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

完善付款码支付的返回值信息 #62

Merged
merged 2 commits into from
Nov 10, 2021
Merged
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
24 changes: 22 additions & 2 deletions src/WeChat/WeChatPay/BarCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
namespace EasySwoole\Pay\WeChat\WeChatPay;


use EasySwoole\Pay\Exceptions\GatewayException;
use EasySwoole\Pay\Exceptions\InvalidSignException;
use EasySwoole\Pay\WeChat\RequestBean\Base;
use EasySwoole\Pay\WeChat\ResponseBean\BarCode as MicroPayResponse;
use EasySwoole\Pay\WeChat\Utility;
Expand All @@ -20,7 +22,25 @@ function pay(Base $bean)
$bean->setNotifyUrl( $this->config->getNotifyUrl() );
}
$utility = new Utility( $this->config );
$result = $utility->requestApi( $this->requestPath(), $bean );
return new MicroPayResponse($result->getArrayCopy());

$result = $utility->request( $this->requestPath(), $bean );
$result = is_array($result) ? $result : $utility->fromXML($result);
if ((isset($result['return_code']) && $result['return_code'] == 'SUCCESS') && isset($result['err_code']) && $result['result_code'] == 'FAIL') {
// 以下情况 可能已经支付成功了,所以需要返回给调用者
if (in_array($result['err_code'], ['BANKERROR', 'SYSTEMERROR', 'USERPAYING'])) {
// 这里为了兼容微信的一个BUG,用请求的sign_type代替响应值里的sign_type
if (!isset($result['sign_type']) && $bean->getSignType() != null) {
$result['sign_type'] = $bean->getSignType();
}
if ($utility->generateSign($result) === $result['sign']) {
$resultArray = new SplArray($result);
return new MicroPayResponse($resultArray->getArrayCopy());
}
throw new InvalidSignException('sign is error');
}
}
if (!isset($result['return_code']) || $result['return_code'] != 'SUCCESS' || $result['result_code'] != 'SUCCESS') {
throw new GatewayException('Get Wechat API Error:' . ($result['return_msg'] ?? $result['retmsg']) . ($result['err_code_des'] ?? ''),$result,$result['return_code']);
}
}
}