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

新增微信公众号支付JSSDK签名处理 #241

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/Gateways/Wechat/PubCharge.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use Payment\Contracts\IGatewayRequest;
use Payment\Exceptions\GatewayException;
use Payment\Helpers\ArrayUtil;
use Payment\Helpers\StrUtil;
use Payment\Payment;

/**
Expand All @@ -36,10 +38,41 @@ class PubCharge extends WechatBaseObject implements IGatewayRequest
public function request(array $requestParams)
{
try {
return $this->requestWXApi(self::METHOD, $requestParams);
$ret = $this->requestWXApi(self::METHOD, $requestParams);
} catch (GatewayException $e) {
throw $e;
}

// 生成app端需要的数据
if (is_array($ret) && $ret['return_code'] === 'SUCCESS' && $ret['result_code'] === 'SUCCESS') {
$payData = [
'appId' => $ret['appid'],
'package' => 'prepay_id='.$ret['prepay_id'],
'nonceStr' => StrUtil::getNonceStr(self::NONCE_LEN),
'timeStamp' => time(),
'signType' => $this->signType
];

// 添加签名
$payData = ArrayUtil::paraFilter($payData);
$payData = ArrayUtil::arraySort($payData);

try {
$signStr = ArrayUtil::createLinkstring($payData);
$payData['paySign'] = $this->makeSign($signStr);
} catch (\Exception $e) {
throw new GatewayException($e->getMessage(), Payment::PARAMS_ERR);
}

// 这三个字段是为了让前端的判断保持一致
$payData['return_code'] = 'SUCCESS';
$payData['return_msg'] = $ret['return_msg'];
$payData['result_code'] = 'SUCCESS';

$ret = $payData;
}

return $ret;
}

/**
Expand Down