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

添加微信扫描用户码支付及扫描返回支付状态未知处理 #61

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ var_dump($result);
| miniProgram | 小程序支付 | Request | Response |
| transfer | 单笔转账 | Request | Response |
| sendRedPack | 现金红包 | Request | Response |
| micro | 付款码支付 | Request | Response |

#### 微信参数配置

Expand Down Expand Up @@ -552,6 +553,19 @@ $data = $pay->weChat($this->wechatConfig)->scan($bean);
$url2 = $data->getCodeUrl();
```

## 付款码支付
```php
$micro = new \EasySwoole\Pay\WeChat\RequestBean\Micro();
$micro->setOpenid('xxxxxxxxx');
$micro->setOutTradeNo('CN' . date('YmdHis') . rand(1000, 9999));
$micro->setBody('xxxx-测试' . $outTradeNo);
$micro->setTotalFee(1);
$micro->setAuthCode('10xxxxxxx');//18位纯数字,以10、11、12、13、14、15开头
$micro->setSpbillCreateIp($this->request()->getHeader('x-real-ip')[0]);
$pay = new \EasySwoole\Pay\Pay();
$params = $pay->weChat($this->wechatConfig)->miniProgram($micro);
```

## 订单查询

```php
Expand Down
17 changes: 17 additions & 0 deletions src/AliPay/RequestBean/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Base extends SplBean
protected $body;
protected $notify_url;
protected $return_url;
protected $goods_detail;

/**
* @return mixed
*/
Expand Down Expand Up @@ -137,4 +139,19 @@ public function setReturnUrl($returnUrl): void
{
$this->return_url = $returnUrl;
}

/**
* @return mixed
*/
public function getGoodsDetail() {
return $this->goods_detail;
}

/**
* @param $goods_detail
*/
public function setGoodsDetail($goods_detail)
{
$this->goods_detail = $goods_detail;
}
}
183 changes: 183 additions & 0 deletions src/WeChat/RequestBean/Micro.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
<?php
/**
*
* Copyright EasySwoole
* User: hanwenbo
* Date: 2019-02-17
* Time: 13:24
*
*/

namespace EasySwoole\Pay\WeChat\RequestBean;

/**
* 付款码支付
* Class Micro
* @package EasySwoole\Pay\WeChat\RequestBean
*/
class Micro extends PayBase
{
protected $sub_appid; // 微信分配的公众账号ID
protected $sub_mch_id; // 微信支付分配的商户号
protected $device_info; // 终端设备号(商户自定义,如门店编号) 选填
protected $nonce_str; // 随机字符串 不长于32位
protected $sign; // 签名
protected $sign_type; // 签名类型,目前支持HMAC-SHA256和MD5,默认为MD5 选填
protected $body; // 商品简单描述
protected $detail; // 商品详情 选填
protected $attach; // 附加数据 选填
protected $out_trade_no; // 商户订单号
protected $total_fee; // 支付金额单位为分
protected $fee_type; // 货币类型 默认人民币 选填
protected $spbill_create_ip; // 支持IPV4和IPV6两种格式的IP地址。调用微信支付API的机器IP
protected $goods_tag; // 订单优惠标记 选填
protected $limit_pay; // 指定支付方式no_credit--指定不能使用信用卡支付 选填
protected $time_start; // 交易起始时间 选填
protected $time_expire; // 交易结束时间 选填
protected $receipt; // 电子发票入口开放标识 Y,传入Y时,支付成功消息和支付详情页将出现开票入口 选填
protected $auth_code; // 付款码 扫码支付付款码,设备读取用户微信中的条码或者二维码信息
protected $profit_sharing; // 是否需要分账 Y-是,需要分账 N-否,不分账 字母要求大写,不传默认不分账 选填


/**
* @return mixed
*/
public function getSubAppid()
{
return $this->sub_appid;
}

/**
* @param mixed $sub_appid
*/
public function setSubAppId($sub_appid): void
{
$this->sub_appid = $sub_appid;
}

/**
* @return mixed
*/
public function getSubMchId()
{
return $this->sub_mch_id;
}

/**
* @param mixed $sub_mch_id
*/
public function setSubMchId($sub_mch_id): void
{
$this->sub_mch_id = $sub_mch_id;
}

/**
* @return mixed
*/
public function getNonceStr()
{
return $this->nonce_str;
}

/**
* @param mixed $nonce_str
*/
public function setNonceStr($nonce_str): void
{
$this->nonce_str = $nonce_str;
}

/**
* @return mixed
*/
public function getBody()
{
return $this->body;
}

/**
* @param mixed $body
*/
public function setBody($body): void
{
$this->body = $body;
}

/**
* @return mixed
*/
public function getDetail()
{
return $this->detail;
}

/**
* @param mixed $detail
*/
public function setDetail($detail): void
{
$this->detail = $detail;
}

/**
* @return mixed
*/
public function getOutTradeNo()
{
return $this->out_trade_no;
}

/**
* @param mixed $out_trade_no
*/
public function setOutTradeNo($out_trade_no): void
{
$this->out_trade_no = $out_trade_no;
}

/**
* @return mixed
*/
public function getTotalFee()
{
return $this->total_fee;
}

/**
* @param mixed $total_fee
*/
public function setTotalFee($total_fee): void
{
$this->total_fee = $total_fee;
}

/**
* @return mixed
*/
public function getSpbillCreateIp()
{
return $this->spbill_create_ip;
}

/**
* @param mixed $spbill_create_ip
*/
public function setSpbillCreateIp($spbill_create_ip): void
{
$this->spbill_create_ip = $spbill_create_ip;
}

/**
* @return mixed
*/
public function getAuthCode() {
return $this->auth_code;
}

/**
* @param $auth_code
*/
public function setAuthCode($auth_code) {
$this->auth_code = $auth_code;
}
}
54 changes: 54 additions & 0 deletions src/WeChat/ResponseBean/Micro.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
*
* Copyright EasySwoole
* User: hanwenbo
* Date: 2019-02-17
* Time: 13:24
*
*/

namespace EasySwoole\Pay\WeChat\ResponseBean;

class Micro extends Base
{

protected $appId;
protected $nonce_str;
protected $sign;
protected $transaction_id;
protected $time_end;
protected $out_trade_no;
protected $return_code;
protected $return_msg;
protected $appid;
protected $mch_id;
protected $sub_mch_id;
protected $result_code;
protected $openid;
protected $is_subscribe;
protected $trade_type;
protected $total_fee;、
protected $err_code_des;
protected $err_code;

public function getTransactionId(): string
{
return $this->transaction_id;
}

public function getTimeEnd(): string
{
return $this->time_end;
}

public function getNonceStr(): string
{
return $this->nonce_str;
}

public function setPaySign($sign): string
{
$this->sign = $sign;
}
}
7 changes: 7 additions & 0 deletions src/WeChat/Utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ public function requestApi(string $endpoint, Base $bean, bool $useCert = false):

$result = is_array($result) ? $result : $this->fromXML($result);

//处理扫描用户码返回支付状态未知code
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', 'AUTH_CODE_ERROR'])) {
return new SplArray($result);
}
}

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']);
}
Expand Down
5 changes: 5 additions & 0 deletions src/WeChat/WeChat.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use EasySwoole\Pay\WeChat\RequestBean\Scan as ScanRequest;
use EasySwoole\Pay\WeChat\RequestBean\Wap as WapRequest;
use EasySwoole\Pay\WeChat\RequestBean\App as AppRequest;
use EasySwoole\Pay\WeChat\RequestBean\Micro as MicroRequest;


use EasySwoole\Pay\WeChat\RequestBean\OrderFind as OrderFindRequest;
Expand All @@ -33,19 +34,23 @@
use EasySwoole\Pay\WeChat\RequestBean\AuthCodeToOpenId as AuthCodeToOpenIdRequest;




use EasySwoole\Pay\WeChat\ResponseBean\OfficialAccount as OfficialAccountResponse;
use EasySwoole\Pay\WeChat\ResponseBean\Wap as WapResponse;
use EasySwoole\Pay\WeChat\ResponseBean\Scan as ScanResponse;
use EasySwoole\Pay\WeChat\ResponseBean\MiniProgram as MiniProgramResponse;
use EasySwoole\Pay\WeChat\ResponseBean\App as AppResponse;
use EasySwoole\Pay\WeChat\ResponseBean\BarCode as BarCodeResponse;
use EasySwoole\Pay\WeChat\ResponseBean\Micro as MicroResponse;

use EasySwoole\Pay\WeChat\WeChatPay\BarCode;
use EasySwoole\Pay\WeChat\WeChatPay\MiniProgram;
use EasySwoole\Pay\WeChat\WeChatPay\OfficialAccount;
use EasySwoole\Pay\WeChat\WeChatPay\Scan;
use EasySwoole\Pay\WeChat\WeChatPay\Wap;
use EasySwoole\Pay\WeChat\WeChatPay\App;
use EasySwoole\Pay\WeChat\WeChatPay\Micro;
use EasySwoole\Spl\SplArray;

/**
Expand Down
Loading