davidxu / yii2-alipay
支付宝 Composer 包
1.0.7
2020-06-04 03:13 UTC
Requires
- php: >5.5
README
一个支付宝 Composer 包
描述
此包用于支付宝应用支付。
基于 Alipay-SDK-PHP-4.9.0
安装
安装此扩展的首选方式是通过 Composer。
运行以下命令
php composer.phar require davidxu/yii2-alipay "*"
或者
"davidxu/yii2-alipay": "*"
将以下内容添加到您的 composer.json
文件的 require 部分中。
应用支付订单生成请求的用法示例
use davidxu\alipay\Alipay;
use davidxu\alipay\request\AlipayTradeAppPayRequest;
$notifyUrl = 'https://<your_domain>/alipay/notify';
$alipay = new Alipay();
$alipay->gatewayUrl = "https://openapi.alipay.com/gateway.do";
$alipay->appId = "<app_id>";
$alipay->rsaPrivateKey = '<private_key_in_one_line>' ;
$alipay->format = "json";
$alipay->charset = "UTF-8";
$alipay->signType = "RSA2";
$alipay->alipayrsaPublicKey = '<alipay_public_key_NOT_DEVELOPER_PUBLIC_KEY>';
$request = new AlipayTradeAppPayRequest();
$bizcontent = json_encode([
'body' => 'Body of test data',
'subject' => 'App Pay Test',
'out_trade_no' => '2020012511013510000',
'timeout_express' => '30m',
'total_amount' => '0.01',
'product_code' => 'QUICK_MSECURITY_PAY',
]);
$request->setNotifyUrl($notifyUrl);
$request->setBizContent($bizcontent);
$orderString = $alipay->sdkExecute($request);
// Client side can use this string for orderString directly.
echo $orderString;
应用支付异步通知的用法示例
Http Method: POST
Request URL: https://<your_domain>/alipay/notify <notifyUrl>
use davidxu\alipay\Alipay;
$alipay = new Alipay();
$alipay->alipayrsaPublicKey = <alipay_public_key_NOT_DEVELOPER_PUBLIC_KEY>;
$flag = $alipay->rsaCheckV1($request, null, 'RSA2');
// Other code such as deal with business logic and etc
// Response ali post request
echo 'success';
联系
如有任何问题,请联系 david.xu.uts@163.com
祝您玩得开心。