Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #403

Merged
merged 13 commits into from
Apr 22, 2016
1 change: 1 addition & 0 deletions src/Payment/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ protected function request($api, array $params, $method = 'post', array $options
$params['mch_id'] = $this->merchant->merchant_id;
$params['device_info'] = $this->merchant->device_info;
$params['nonce_str'] = uniqid();
$params = array_filter($params);
$params['sign'] = generate_sign($params, $this->merchant->key, 'md5');

$options = array_merge([
Expand Down
1 change: 1 addition & 0 deletions src/Payment/LuckyMoney/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public function getMerchant()
*/
protected function request($api, array $params, $method = 'post')
{
$params = array_filter($params);
$params['mch_id'] = $this->merchant->merchant_id;
$params['nonce_str'] = uniqid();
$params['sign'] = \EasyWeChat\Payment\generate_sign($params, $this->merchant->key, 'md5');
Expand Down
1 change: 1 addition & 0 deletions src/Payment/MerchantPay/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public function getMerchant()
*/
protected function request($api, array $params, $method = 'post')
{
$params = array_filter($params);
$params['nonce_str'] = uniqid();
$params['sign'] = \EasyWeChat\Payment\generate_sign($params, $this->merchant->key, 'md5');

Expand Down
9 changes: 9 additions & 0 deletions src/Payment/Notify.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

/**
* Notify.php.
*
Expand Down
34 changes: 29 additions & 5 deletions src/Payment/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@ public function handleNotify(callable $callback)
}

/**
* Generate js config for payment.
* [WeixinJSBridge] Generate js config for payment.
*
* <pre>
* WeixinJSBridge.invoke(
* 'getBrandWCPayRequest',
* ...
* );
* </pre>
*
* @param string $prepayId
* @param bool $json
Expand All @@ -135,13 +142,30 @@ public function configForPayment($prepayId, $json = true)

$params['paySign'] = generate_sign($params, $this->merchant->key, 'md5');

// 简直了,这帮人真的是快玩出花儿来了!
$params['timestamp'] = $params['timeStamp'];
unset($params['timeStamp']);

return $json ? json_encode($params) : $params;
}

/**
* [JSSDK] Generate js config for payment.
*
* <pre>
* wx.chooseWXPay({...});
* </pre>
*
* @param string $prepayId
*
* @return array|string
*/
public function configForJSSDKPayment($prepayId)
{
$config = $this->configForPayment($prepayId, false);

$config['timestamp'] = $config['timeStamp'];
unset($config['timeStamp']);

return $config;
}

/**
* Generate app payment parameters.
*
Expand Down
4 changes: 2 additions & 2 deletions src/Support/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class File
*
* @var array
*/
protected static $extensionMap = array(
protected static $extensionMap = [
'audio/wav' => '.wav',
'audio/x-ms-wma' => '.wma',
'video/x-ms-wmv' => '.wmv',
Expand All @@ -46,7 +46,7 @@ class File
'image/png' => '.png',
'image/tiff' => '.tiff',
'image/jpeg' => '.jpg',
);
];

/**
* File header signatures.
Expand Down
19 changes: 18 additions & 1 deletion tests/Payment/PaymentPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,28 @@ public function testConfigForPayment()
$this->assertEquals('wxTestAppId', $array['appId']);
$this->assertEquals('prepay_id=prepayId', $array['package']);
$this->assertEquals('MD5', $array['signType']);
$this->assertArrayHasKey('timestamp', $array);
$this->assertArrayHasKey('timeStamp', $array);
$this->assertArrayHasKey('nonceStr', $array);
$this->assertArrayHasKey('paySign', $array);
}

/**
* test configForPayment.
*/
public function testConfigForJSSDKPayment()
{
$payment = $this->getPayment();

$config = $payment->configForJSSDKPayment('prepayId');

$this->assertEquals('wxTestAppId', $config['appId']);
$this->assertEquals('prepay_id=prepayId', $config['package']);
$this->assertEquals('MD5', $config['signType']);
$this->assertArrayHasKey('timestamp', $config);
$this->assertArrayHasKey('nonceStr', $config);
$this->assertArrayHasKey('paySign', $config);
}

/**
* test configForAppPayment.
*/
Expand Down