Laravel框架版本
Laravel Framework 7.6.2
安装扩展
composer require yansongda/pay -vvv
支付宝
支付宝电脑网站支付
同步请求
支付成功之后会跳转到配置文件中的 return_url 的路由中。返回值截图如下:
异步回调请求
这个请求只有在 trade_status=TRADE_SUCCESS
才会触发。也就是说用户支付成功后才会触发。
在用户支付完成之后,支付宝会根据 API 中商户传入的 notify_url,这个请求是支付宝通过 POST 请求的形式将支付结果作为参数返回商户系统的。格式如下:
{
"gmt_create":"2020-04-29 15:08:22",
"charset":"utf-8",
"gmt_payment":"2020-04-29 15:08:32",
"notify_time":"2020-04-29 15:08:33",
"subject":"测试订单",
"sign":"K9MsNOE3+hG0zb+Lx6yyoQ652DPWKJ08lEYasdfyx7Mg==",
"buyer_id":"2088xxxxxx",
"invoice_amount":"1.00",
"version":"1.0",
"notify_id":"20200429002280512305246",
"fund_bill_list":"[{"amount":"1.00","fundChannel":"ALIPAYACCOUNT"}]",
"notify_type":"trade_status_sync",
"out_trade_no":"1588144092",
"total_amount":"1.00",
"trade_status":"TRADE_SUCCESS",
"trade_no":"202004292200xxxx",
"auth_app_id":"201609xxxx",
"receipt_amount":"1.00",
"point_amount":"0.00",
"app_id":"20160xxxx",
"buyer_pay_amount":"1.00",
"sign_type":"RSA2",
"seller_id":"20881xxxxx"
}
怎么接收返回过来的参数呢。
可以通过 $_POST['trade_status']
这样接收。
手机网站支付
异步请求
返回参数格式如下:
{
"gmt_create":"2020-04-29 15:32:40",
"charset":"utf-8",
"seller_email":"xxxx@xxx.com",
"subject":"测试订单",
"sign":"P7axVFvMyN6w76A54xHemCYqtNtuSiHxo/nR6gBr/lQlH8RKxxxxz7NRFr7v0xASp/RGpjFw0GMavMO88EPehL7p3vvBklIAch1stiQYMehXooPNaD4QHznoEA==",
"buyer_id":"2088xxxx",
"invoice_amount":"0.01",
"notify_id":"20200429xxxxxx",
"fund_bill_list":"[{"amount":"0.01","fundChannel":"ALIPAYACCOUNT"}]",
"notify_type":"trade_status_sync",
"trade_status":"TRADE_SUCCESS",
"receipt_amount":"0.01",
"buyer_pay_amount":"0.01",
"app_id":"20160xxxx",
"sign_type":"RSA2",
"seller_id":"20881xxxx",
"gmt_payment":"2020-04-29 15:32:43",
"notify_time":"2020-04-29 15:32:44",
"version":"1.0",
"out_trade_no":"1588145531",
"total_amount":"0.01",
"trade_no":"2020042922001406880502885050",
"auth_app_id":"2016xxxxx",
"buyer_logon_id":"xxx***@xx.com",
"point_amount":"0.00"
}
扫码支付
异步请求
返回参数格式如下:
{
"gmt_create":"2020-04-29 16:03:39",
"charset":"utf-8",
"seller_email":"xxx@xxx.com",
"subject":"扫码测试支付",
"sign":"U00QOgF34jdcDjVZVHvy000steEtLFFkfP9hRCvoI19KoSpuBTviLjxUSEOb2dFA==",
"buyer_id":"2088xxxxx",
"invoice_amount":"0.01",
"notify_id":"2020042xxxxx",
"fund_bill_list":"[{"amount":"0.01","fundChannel":"ALIPAYACCOUNT"}]",
"notify_type":"trade_status_sync",
"trade_status":"TRADE_SUCCESS",
"receipt_amount":"0.01",
"buyer_pay_amount":"0.01",
"app_id":"2016xxx",
"sign_type":"RSA2",
"seller_id":"20881xxx",
"gmt_payment":"2020-04-29 16:03:50",
"notify_time":"2020-04-29 16:03:51",
"version":"1.0",
"out_trade_no":"1588147398",
"total_amount":"0.01",
"trade_no":"2020042922xxxx",
"auth_app_id":"2016xxx",
"buyer_logon_id":"xx***@xxx.com",
"point_amount":"0.00"
}
参考文档:
https://pay.yanda.net.cn/docs/2.x/overview
https://xueyuanjun.com/post/1501.html
Laravel 支付宝支付异步通知
支付宝支付通知有前端通知(GET)和服务器异步通知(POST)
在配置支付宝支付时,需要注意的问题就是支付宝的回调操作:
-
在laravel中应该将支付宝通知路径组织csrf验证,否则会导致419错误
-
支付宝两种通知返回的参数不相同,需要谨慎填写,否则会导致数据库更改数据失败错误
-
支付宝两种通知返回的路径路由不要放在登陆中间件中,否则会导致302重定向错误