记住用户名密码
在easyswoole中,已经开发好了相关的支付组件,只需要引入即可:
1
|
composer require easyswoole /pay |
pay组件支持协程
支付宝支付目前支持 7 种支付方法,对应的支付 method 如下:
method | 说明 | 参数 | 返回值 |
---|---|---|---|
web | 电脑支付 | Request | Response |
wap | 手机网站支付 | Request | Response |
app | APP 支付 | Request | Response |
pos | 刷卡支付 | Request | Response |
scan | 扫码支付 | Request | Response |
transfer | 账户转账 | Request | Response |
mini | 小程序支付 | Request | Response |
统一收单下单并支付页面接口
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
$aliConfig = new \EasySwoole\Pay\AliPay\Config(); $aliConfig ->setGateWay(\EasySwoole\Pay\AliPay\GateWay::NORMAL); $aliConfig ->setAppId( '2017082000295641' ); $aliConfig ->setPublicKey( '阿里公钥' ); $aliConfig ->setPrivateKey( '阿里私钥' ); $pay = new \EasySwoole\Pay\Pay(); ## 对象风格 $order = new \EasySwoole\Pay\AliPay\RequestBean\Web(); $order ->setSubject( '测试' ); $order ->setOutTradeNo(time(). '123456' ); $order ->setTotalAmount( '0.01' ); // 本库只预置了常用的请求参数,没预置的参数使用:$order->addProperty('其他字段','其他字段值'); ## 数组风格 $order = new \EasySwoole\Pay\AliPay\RequestBean\App([ 'subject' => '测试' , 'out_trade_no' => '123456' , 'total_amount' => '0.01' , '额外的字段键值' => '额外字段值' ],true); $res = $pay ->aliPay( $aliConfig )->web( $order ); var_dump( $res ->toArray()); $html = buildPayHtml(\EasySwoole\Pay\AliPay\GateWay::NORMAL, $res ->toArray()); file_put_contents ( 'test.html' , $html ); |
所有订单配置中,客观参数均不用配置,扩展包已经为大家自动处理了,比如,product_code
等参数。
所有订单配置参数和官方无任何差别,兼容所有功能,所有参数请参考这里,查看「请求参数」一栏。
参数查询:https://docs.open.alipay.com/api_1/alipay.trade.page.pay
生成支付的跳转html示例
1
2
3
4
5
6
7
8
9
10
11
|
function buildPayHtml( $endpoint , $payload ) { $sHtml = "<form id='alipaysubmit' name='alipaysubmit' action='" . $endpoint . "' method='POST'>" ; foreach ( $payload as $key => $val ) { $val = str_replace ( "'" , ''', $val ); $sHtml .= "<input type='hidden' name='" . $key . "' value='" . $val . "'/>" ; } $sHtml .= "<input type='submit' value='ok' style='display:none;'></form>" ; $sHtml .= "<script>document.forms['alipaysubmit'].submit();</script>" ; return $sHtml ; } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
$aliConfig = new \EasySwoole\Pay\AliPay\Config(); $aliConfig ->setGateWay(\EasySwoole\Pay\AliPay\GateWay::NORMAL); $aliConfig ->setAppId( '2017082000295641' ); $aliConfig ->setPublicKey( '阿里公钥' ); $aliConfig ->setPrivateKey( '阿里私钥' ); $pay = new \EasySwoole\Pay\Pay(); $order = new \EasySwoole\Pay\AliPay\RequestBean\Wap(); $order ->setSubject( '测试' ); $order ->setOutTradeNo(time(). '123456' ); $order ->setTotalAmount( '0.01' ); $res = $pay ->aliPay( $aliConfig )->wap( $order ); var_dump( $res ->toArray()); $html = buildPayHtml(\EasySwoole\Pay\AliPay\GateWay::NORMAL, $res ->toArray()); file_put_contents ( 'test.html' , $html ); |
所有订单配置中,客观参数均不用配置,扩展包已经为大家自动处理了,比如,product_code
等参数。
所有订单配置参数和官方无任何差别,兼容所有功能,所有参数请参考这里,查看「请求参数」一栏。
参数查询:https://docs.open.alipay.com/api_1/alipay.trade.wap.pay
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
$aliConfig = new \EasySwoole\Pay\AliPay\Config(); $aliConfig ->setGateWay(\EasySwoole\Pay\AliPay\GateWay::SANDBOX); $aliConfig ->setAppId( '2016091800538339' ); $aliConfig ->setPublicKey( '阿里公钥' ); $aliConfig ->setPrivateKey( '阿里私钥' ); $pay = new \EasySwoole\Pay\Pay(); $order = new \EasySwoole\Pay\AliPay\RequestBean\App(); $order ->setSubject( '测试' ); $order ->setOutTradeNo(time(). '123456' ); $order ->setTotalAmount( '0.01' ); $aliPay = $pay ->aliPay( $aliConfig ); var_dump( $aliPay ->app( $order )->toArray()); |
所有订单配置中,客观参数均不用配置,扩展包已经为大家自动处理了,比如, product_code
等参数。
所有订单配置参数和官方无任何差别,兼容所有功能,所有参数请参考这里,查看「请求参数」一栏。
参数查询:https://docs.open.alipay.com/api_1/alipay.trade.app.pay
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
$aliConfig = new \EasySwoole\Pay\AliPay\Config(); $aliConfig ->setGateWay(\EasySwoole\Pay\AliPay\GateWay::SANDBOX); $aliConfig ->setAppId( '2016091800538339' ); $aliConfig ->setPublicKey( '阿里公钥' ); $aliConfig ->setPrivateKey( '阿里私钥' ); $pay = new \EasySwoole\Pay\Pay(); $order = new \EasySwoole\Pay\AliPay\RequestBean\Pos(); $order ->setSubject( '测试' ); $order ->setTotalAmount( '0.01' ); $order ->setOutTradeNo(time()); $order ->setAuthCode( '289756915257123456' ); $aliPay = $pay ->aliPay( $aliConfig ); $data = $aliPay ->pos( $order )->toArray(); var_dump( $data ); |
所有订单配置中,客观参数均不用配置,扩展包已经为大家自动处理了,比如,product_code
等参数。
所有订单配置参数和官方无任何差别,兼容所有功能,所有参数请参考这里,查看「请求参数」一栏。
参数查询:https://docs.open.alipay.com/api_1/alipay.trade.page.pay
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
$aliConfig = new \EasySwoole\Pay\AliPay\Config(); $aliConfig ->setGateWay(\EasySwoole\Pay\AliPay\GateWay::SANDBOX); $aliConfig ->setAppId( '2016091800538339' ); $aliConfig ->setPublicKey( '阿里公钥' ); $aliConfig ->setPrivateKey( '阿里私钥' ); $pay = new \EasySwoole\Pay\Pay(); $pay = new \EasySwoole\Pay\Pay(); $order = new \EasySwoole\Pay\AliPay\RequestBean\Scan(); $order ->setSubject( '测试' ); $order ->setTotalAmount( '0.01' ); $order ->setOutTradeNo(time()); $aliPay = $pay ->aliPay( $aliConfig ); $data = $aliPay ->scan( $order )->toArray(); $response = $aliPay ->preQuest( $data ); var_dump( $response ); // qr_code 当前预下单请求生成的二维码码串,可以用二维码生成工具根据该码串值生成对应的二维码 https://qr.alipay.com/bavh4wjlxf12tper3a |
所有订单配置中,客观参数均不用配置,扩展包已经为大家自动处理了,比如,product_code
等参数。
所有订单配置参数和官方无任何差别,兼容所有功能,所有参数请参考这里,查看「请求参数」一栏。
参考参数:https://docs.open.alipay.com/api_1/alipay.trade.precreate
1
|
<br> |
$aliConfig = new \EasySwoole\Pay\AliPay\Config();
$aliConfig->setGateWay(\EasySwoole\Pay\AliPay\GateWay::SANDBOX);
$aliConfig->setAppId('2016091800538339');
$aliConfig->setPublicKey('阿里公钥');
$aliConfig->setPrivateKey('阿里私钥');
$pay = new \EasySwoole\Pay\Pay();
$order = new \EasySwoole\Pay\AliPay\RequestBean\Transfer();
$order->setSubject('测试');
$order->setTotalAmount('0.01');
$order->setPayeeType('ALIPAY_LOGONID');
$order->setPayeeAccount('hcihsn8174@sandbox.com');
$aliPay = $pay->aliPay($aliConfig);
$data = $aliPay->transfer($order)->toArray();
$aliPay->preQuest($data);
var_dump($data);
所有订单配置中,客观参数均不用配置,扩展包已经为大家自动处理了,比如,product_code
等参数。
所有订单配置参数和官方无任何差别,兼容所有功能,所有参数请参考这里,查看「请求参数」一栏。
参数查询:https://docs.open.alipay.com/api_28/alipay.fund.trans.toaccount.transfer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
$aliConfig = new \EasySwoole\Pay\AliPay\Config(); $aliConfig ->setGateWay(\EasySwoole\Pay\AliPay\GateWay::SANDBOX); $aliConfig ->setAppId( '2016091800538339' ); $aliConfig ->setPublicKey( '阿里公钥' ); $aliConfig ->setPrivateKey( '阿里私钥' ); $pay = new \EasySwoole\Pay\Pay(); $order = new \EasySwoole\Pay\AliPay\RequestBean\MiniProgram(); $order ->setSubject( '测试' ); $order ->setOutTradeNo(time(). '123456' ); $order ->setTotalAmount( '0.01' ); $order ->setBuyerId( 'hcihsn8174@sandbox.com' ); $aliPay = $pay ->aliPay( $aliConfig ); $data = $aliPay ->miniProgram( $order )->toArray(); var_dump( $data ); |
所有订单配置中,客观参数均不用配置,扩展包已经为大家自动处理了,比如,product_code
等参数。
所有订单配置参数和官方无任何差别,兼容所有功能,所有参数请参考这里,查看「请求参数」一栏。
小程序支付接入文档:https://docs.alipay.com/mini/introduce/pay。
参数查询:
1
2
3
4
5
6
7
8
9
10
|
$aliConfig = new \EasySwoole\Pay\AliPay\Config(); $aliConfig ->setGateWay(\EasySwoole\Pay\AliPay\GateWay::SANDBOX); $aliConfig ->setAppId( '2016091800538339' ); $aliConfig ->setPublicKey( '阿里公钥' ); $aliConfig ->setPrivateKey( '阿里私钥' ); $pay = new \EasySwoole\Pay\Pay(); $order = new \EasySwoole\Pay\AliPay\RequestBean\OrderFind(); $order ->setOutTradeNo(time(). '123456' ); $aliPay = $pay ->aliPay( $aliConfig ); var_dump( $aliPay ->orderFind( $order )->toArray()); |
官方参数查询:https://docs.open.alipay.com/api_1/alipay.trade.fastpay.refund.query
1
2
3
4
5
6
7
8
9
10
11
12
|
$aliConfig = new \EasySwoole\Pay\AliPay\Config(); $aliConfig ->setGateWay(\EasySwoole\Pay\AliPay\GateWay::SANDBOX); $aliConfig ->setAppId( '2016091800538339' ); $aliConfig ->setPublicKey( '阿里公钥' ); $aliConfig ->setPrivateKey( '阿里私钥' ); $pay = new \EasySwoole\Pay\Pay(); $order = new \EasySwoole\Pay\AliPay\RequestBean\RefundFind(); $order ->setOutTradeNo( '20150320010101001' ); $order ->setOutRequestNo(time(). '2014112611001004680073956707' ); $aliPay = $pay ->aliPay( $aliConfig ); $data = $aliPay ->refundFind( $order )->toArray(); var_dump( $aliPay ->preQuest( $data )); |
官方参数查询:https://docs.open.alipay.com/api_1/alipay.trade.refund
1
2
3
4
5
6
7
8
9
10
11
12
13
|
$aliConfig = new \EasySwoole\Pay\AliPay\Config(); $aliConfig ->setGateWay(\EasySwoole\Pay\AliPay\GateWay::SANDBOX); $aliConfig ->setAppId( '2016091800538339' ); $aliConfig ->setPublicKey( '阿里公钥' ); $aliConfig ->setPrivateKey( '阿里私钥' ); $pay = new \EasySwoole\Pay\Pay(); $order = new \EasySwoole\Pay\AliPay\RequestBean\TransferFind(); $order ->setOutBizNo( '3142321423432' ); // 二选一 // $order->setOrderId('20160627110070001502260006780837'); $aliPay = $pay ->aliPay( $aliConfig ); $data = $aliPay ->transferFind( $order )->toArray(); var_dump( $aliPay ->preQuest( $data )); |
官方参数查询:https://docs.open.alipay.com/api_28/alipay.fund.trans.order.query
1
2
3
4
5
6
7
8
9
10
11
|
$aliConfig = new \EasySwoole\Pay\AliPay\Config(); $aliConfig ->setGateWay(\EasySwoole\Pay\AliPay\GateWay::SANDBOX); $aliConfig ->setAppId( '2016091800538339' ); $aliConfig ->setPublicKey( '阿里公钥' ); $aliConfig ->setPrivateKey( '阿里私钥' ); $pay = new \EasySwoole\Pay\Pay(); $order = new \EasySwoole\Pay\AliPay\RequestBean\Cancel(); $order ->setOutTradeNo( '20150320010101001' ); $aliPay = $pay ->aliPay( $aliConfig ); $data = $aliPay ->cancel( $order )->toArray(); var_dump( $aliPay ->preQuest( $data )); |
官方参数查询:https://docs.open.alipay.com/api_1/alipay.trade.cancel
1
2
3
4
5
6
7
8
9
10
11
|
$aliConfig = new \EasySwoole\Pay\AliPay\Config(); $aliConfig ->setGateWay(\EasySwoole\Pay\AliPay\GateWay::SANDBOX); $aliConfig ->setAppId( '2016091800538339' ); $aliConfig ->setPublicKey( '阿里公钥' ); $aliConfig ->setPrivateKey( '阿里私钥' ); $pay = new \EasySwoole\Pay\Pay(); $order = new \EasySwoole\Pay\AliPay\RequestBean\Close(); $order ->setOutTradeNo(time(). '123456' ); $aliPay = $pay ->aliPay( $aliConfig ); $data = $aliPay ->close( $order )->toArray(); var_dump( $aliPay ->preQuest( $data )); |
官方参数查询:https://docs.open.alipay.com/api_1/alipay.trade.close
1
2
3
4
5
6
7
8
9
10
11
12
|
$aliConfig = new \EasySwoole\Pay\AliPay\Config(); $aliConfig ->setGateWay(\EasySwoole\Pay\AliPay\GateWay::SANDBOX); $aliConfig ->setAppId( '2016091800538339' ); $aliConfig ->setPublicKey( '阿里公钥' ); $aliConfig ->setPrivateKey( '阿里私钥' ); $pay = new \EasySwoole\Pay\Pay(); $order = new \EasySwoole\Pay\AliPay\RequestBean\Download(); $order ->setBillType( 'trade' ); $order ->setBillDate( '2016-04-05' ); $aliPay = $pay ->aliPay( $aliConfig ); $data = $aliPay ->download( $order )->toArray(); var_dump( $aliPay ->preQuest( $data )); |
官方参数查询:https://docs.open.alipay.com/api_15/alipay.data.dataservice.bill.downloadurl.query
1
2
3
4
5
6
7
8
9
10
11
12
|
$aliConfig = new \EasySwoole\Pay\AliPay\Config(); $aliConfig ->setGateWay(\EasySwoole\Pay\AliPay\GateWay::SANDBOX); $aliConfig ->setAppId( '2016091800538339' ); $aliConfig ->setPublicKey( '阿里公钥' ); $aliConfig ->setPrivateKey( '阿里私钥' ); $pay = new \EasySwoole\Pay\Pay(); $param = []; //伪代码,post数据 unset( $param [ 'sign_type' ]); //需要忽略sign_type组装 $order = new \EasySwoole\Pay\AliPay\RequestBean\NotifyRequest( $param ,true); $aliPay = $pay ->aliPay( $aliConfig ); $result = $aliPay ->verify( $order ); var_dump( $result ); |
1
2
|
\EasySwoole\Pay\AliPay::success(); //成功响应 \EasySwoole\Pay\AliPay::fail(); //失败响应 |
微信支付目前支持 3 种支付方法,对应的支付 method 如下:
method | 说明 | 参数 | 返回值 |
---|---|---|---|
wap | 手机网站支付 | Request | Response |
officialAccount | 公众号支付 | Request | Response |
scan | 扫码支付 | Request | Response |
miniProgram | 小程序支付 | Request | Response |
1
2
3
4
5
6
7
8
|
$wechatConfig = new Config(); $wechatConfig ->setAppId( 'xxxxxx' ); // 除了小程序以外使用该APPID $wechatConfig ->setMiniAppId( 'xxxxxx' ); // 小程序使用该APPID $wechatConfig ->setMchId( 'xxxxxx' ); $wechatConfig ->setKey( 'xxxxxx' ); $wechatConfig ->setNotifyUrl( 'xxxxx' ); $wechatConfig ->setApiClientCert( 'xxxxxxx' ); //客户端证书 $wechatConfig ->setApiClientKey( 'xxxxxxx' ); //客户端证书秘钥 |
由于小程序拥有独立的APPID,只需要在配置里同时配置上AppId和MiniAppId两个配置项,在支付的时候会自动选择对应的APPID来发起支付
1
2
3
4
5
6
7
8
|
$officialAccount = new OfficialAccount(); $officialAccount ->setOpenid( 'xxxxxxx' ); $officialAccount ->setOutTradeNo( 'CN' . date ( 'YmdHis' ) . rand(1000, 9999)); $officialAccount ->setBody( 'xxxxx-测试' . $outTradeNo ); $officialAccount ->setTotalFee(1); $officialAccount ->setSpbillCreateIp( 'xxxxx' ); $pay = new \EasySwoole\Pay\Pay(); $params = $pay ->weChat( $wechatConfig )->officialAccount( $officialAccount ); |
可以参考demo/wechat/index.php
1
2
3
4
5
6
7
|
$wap = new \EasySwoole\Pay\WeChat\RequestBean\Wap(); $wap ->setOutTradeNo( 'CN' . date ( 'YmdHis' ) . rand(1000, 9999)); $wap ->setBody( 'xxxxx-WAP测试' . $outTradeNo ); $wap ->setTotalFee(1); $wap ->setSpbillCreateIp( 'xxxxx' ); $pay = new \EasySwoole\Pay\Pay(); $params = $pay ->weChat( $wechatConfig )->wap( $wap ); |
1
2
3
4
5
6
7
8
|
$bean = new \EasySwoole\Pay\WeChat\RequestBean\MiniProgram(); $bean ->setOpenid( 'xxxxxxxxx' ); $bean ->setOutTradeNo( 'CN' . date ( 'YmdHis' ) . rand(1000, 9999)); $bean ->setBody( 'xxxx-测试' . $outTradeNo ); $bean ->setTotalFee(1); $bean ->setSpbillCreateIp( $this ->request()->getHeader( 'x-real-ip' )[0]); $pay = new \EasySwoole\Pay\Pay(); $params = $pay ->weChat( $this ->wechatConfig)->miniProgram( $bean ); |
生成扫码链接 然后生成二维码 具体请查看demo/wechat/index.php
1
2
3
4
5
6
7
8
9
10
|
$biz = new Biz(); $biz
|