Laravel 支付寶支付和微信支付


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重定向錯誤


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM