附近小店
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

95 wiersze
3.7 KiB

  1. package svc
  2. import (
  3. "applet/app/md"
  4. "applet/app/utils"
  5. "applet/app/utils/logx"
  6. "encoding/json"
  7. "encoding/xml"
  8. "fmt"
  9. "github.com/gin-gonic/gin"
  10. "github.com/iGoogle-ink/gopay"
  11. "io/ioutil"
  12. "net/url"
  13. )
  14. func CheckAllCallbackParams(c *gin.Context) (interface{}, string, string) {
  15. body, _ := ioutil.ReadAll(c.Request.Body)
  16. dataAlipay, _ := GetAlipayCallbackParams(body)
  17. if dataAlipay != nil && dataAlipay.PayMethod == md.ALIPAY {
  18. return dataAlipay, dataAlipay.OrderType, dataAlipay.PayMethod
  19. }
  20. dataWxPay, _ := GetWxPayCallbackParams(body)
  21. if dataWxPay != nil && dataWxPay.PayMethod == md.WX_PAY {
  22. return dataWxPay, dataWxPay.OrderType, dataWxPay.PayMethod
  23. }
  24. return nil, "", ""
  25. }
  26. // 支付宝参数解析
  27. func GetAlipayCallbackParams(body []byte) (*md.AliPayCallback, error) {
  28. //decodeArgs := "order_type=privilege_card&pay_method=alipay&master_id=123456&gmt_create=2021-01-06+15%3A33%3A18&charset=utf-8&seller_email=1666296478%40qq.com&subject=%E6%B5%8B%E8%AF%95&sign=ILbQtP7E51hcdKaroi%2FKlefltw%2BaSOeaqgvBhYIcIuRy5yy440OIOdxPEvhTITA%2BHnA1Lgf3STepzzHVmvvTFIGeKL%2FVvz%2FLSI7vXGpUBxcw2entVZCzhmblGAB8hiK4EOHBIfUAQiyo9ePWl63p%2B%2BvS4CQuZe8SFXrFaj2bTnRyBPemxekudU8TP8tZd630SzHx7kOHYqxTYZ7kHMrLK0fjIdSWBHtSD2cocm%2FxVQ3wYXUyyfZwwTpcXLW9ao97Uj1hZSnknuFRtMfvE57D5f4W3cB%2Bnp%2B39xpuvfbBlbXXllzKUfkWVBqV6zebYMnzaogwVN%2FDXgp74BQOzkJYvA%3D%3D&buyer_id=2088012352245491&invoice_amount=0.01&notify_id=2021010600222153319045491449160553&fund_bill_list=%5B%7B%22amount%22%3A%220.01%22%2C%22fundChannel%22%3A%22PCREDIT%22%7D%5D&notify_type=trade_status_sync&trade_status=TRADE_SUCCESS&receipt_amount=0.01&app_id=2016120103683451&buyer_pay_amount=0.01&sign_type=RSA2&seller_id=2088221294035253&gmt_payment=2021-01-06+15%3A33%3A18&notify_time=2021-01-06+15%3A33%3A19&passback_params=706160991839039994&version=1.0&out_trade_no=791161468268877545&total_amount=0.01&trade_no=2021010622001445491401511921&auth_app_id=2016120103683451&buyer_logon_id=150****0420&point_amount=0.00"
  29. decodeArgs, err := url.QueryUnescape(string(body))
  30. if err != nil {
  31. _ = logx.Warn(err)
  32. return nil, logx.Warn("回调参数解码错误")
  33. }
  34. data, err := url.ParseQuery(decodeArgs)
  35. if err != nil {
  36. return nil, err
  37. }
  38. dataMap := make(map[string]interface{})
  39. for k := range data {
  40. dataMap[k] = data.Get(k)
  41. }
  42. callbackStr := utils.Serialize(dataMap)
  43. fmt.Println("支付宝回调数据", string(callbackStr))
  44. var args md.AliPayCallback
  45. if err := json.Unmarshal(callbackStr, &args); err != nil {
  46. return nil, logx.Warn(err)
  47. }
  48. return &args, nil
  49. }
  50. // 微信回调参数解析
  51. func GetWxPayCallbackParams(body []byte) (*md.WxPayCallback, error) {
  52. dataMap := make(gopay.BodyMap)
  53. if err := xml.Unmarshal(body, &dataMap); err != nil {
  54. return nil, fmt.Errorf("xml.Unmarshal(%s):%w", string(body), err)
  55. }
  56. callbackStr := utils.Serialize(dataMap)
  57. fmt.Println("微信回调数据", string(callbackStr))
  58. var args md.WxPayCallback
  59. err := json.Unmarshal(callbackStr, &args)
  60. if err != nil {
  61. fmt.Println("err3")
  62. return nil, logx.Warn(err)
  63. }
  64. return &args, nil
  65. }
  66. var PayFuncList = map[string]map[string]func(*gin.Context) (interface{}, error){
  67. md.CommunityTeam: {
  68. md.BALANCE_PAY: BalanceCommunityTeam,
  69. md.ALIPAY: AlipayCommunityTeam,
  70. md.WX_PAY: WxPayCommunityTeam,
  71. },
  72. md.CommunityTeamPay: {
  73. md.BALANCE_PAY: BalanceCommunityTeamPay,
  74. md.ALIPAY: AlipayCommunityTeamPay,
  75. md.WX_PAY: WxPayCommunityTeamPay,
  76. },
  77. }
  78. var PayCallbackFuncList = map[string]map[string]func(*gin.Context){
  79. md.CommunityTeam: {
  80. md.BALANCE_PAY: nil,
  81. md.ALIPAY: AlipayCallbackCommunityTeam,
  82. md.WX_PAY: WxPayCallbackCommunityTeam,
  83. },
  84. md.CommunityTeamPay: {
  85. md.BALANCE_PAY: nil,
  86. md.ALIPAY: AlipayCallbackCommunityTeamPay,
  87. md.WX_PAY: WxPayCallbackCommunityTeamPay,
  88. },
  89. }