Skip to content

Commit

Permalink
Merge pull request #64 from XueSiLf/master
Browse files Browse the repository at this point in the history
fix:修复命名引入问题
  • Loading branch information
XueSiLf authored Nov 18, 2021
2 parents c6f56bc + 76b9a59 commit 23e0bd7
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/WeChat/WeChatPay/BarCode.php
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
<?php


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;
use EasySwoole\Spl\SplArray;

class BarCode extends AbstractPayBase
{
protected function requestPath(): string
{
return '/pay/micropay';
}

function pay(Base $bean)
{
if ($bean->getNotifyUrl()===null){
$bean->setNotifyUrl( $this->config->getNotifyUrl() );
if ($bean->getNotifyUrl() === null) {
$bean->setNotifyUrl($this->config->getNotifyUrl());
}
$utility = new Utility( $this->config );
$utility = new Utility($this->config);

$result = $utility->request( $this->requestPath(), $bean );
$result = $utility->request($this->requestPath(), $bean);
$result = is_array($result) ? $result : $utility->fromXML($result);

//return_code:通信结果,所以必须是success,否则就是失败的。
if(!isset($result['return_code'])||$result['return_code']!='SUCCESS'){
throw new GatewayException('Get Wechat API Error:' . ($result['return_msg'] ?? $result['retmsg']) . ($result['err_code_des'] ?? ''),$result,$result['return_code']);
// return_code:通信结果,所以必须是success,否则就是失败的。
if (!isset($result['return_code']) || $result['return_code'] != 'SUCCESS') {
throw new GatewayException('Get Wechat API Error:' . ($result['return_msg'] ?? $result['retmsg']) . ($result['err_code_des'] ?? ''), $result, $result['return_code']);
}
//当result_code 为fail时 err_code 为:BANKERROR, SYSTEMERROR, USERPAYING ,可能也是成功的,所以需要返回给调用方
if($result['result_code']=='FAIL')
{
// 当result_code 为fail时 err_code 为:BANKERROR, SYSTEMERROR, USERPAYING ,可能也是成功的,所以需要返回给调用方
if ($result['result_code'] == 'FAIL') {
if (!in_array($result['err_code'], ['BANKERROR', 'SYSTEMERROR', 'USERPAYING'])) {
throw new GatewayException('Get Wechat API Error:' . ($result['return_msg'] ?? $result['retmsg']) . ($result['err_code_des'] ?? ''),$result,$result['return_code']);
throw new GatewayException('Get Wechat API Error:' . ($result['return_msg'] ?? $result['retmsg']) . ($result['err_code_des'] ?? ''), $result, $result['return_code']);
}
}
//这里为了兼容微信的一个BUG,用请求的sign_type代替响应值里的sign_type
// 这里为了兼容微信的一个BUG,用请求的sign_type代替响应值里的sign_type
if (!isset($result['sign_type']) && $bean->getSignType() != null) {
$result['sign_type'] = $bean->getSignType();
}
Expand All @@ -46,7 +45,5 @@ function pay(Base $bean)
return new MicroPayResponse($resultArray->getArrayCopy());
}
throw new InvalidSignException('sign is error');


}
}

0 comments on commit 23e0bd7

Please sign in to comment.