支付模块
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

147 rindas
4.7 KiB

  1. package pay
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/md"
  4. zhios_pay_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/utils"
  5. "crypto/tls"
  6. "io/ioutil"
  7. "net/http"
  8. "net/url"
  9. "strings"
  10. )
  11. func UniPayByJoin(payParams *md.JoinPayReq, paySecretKey string, isPrd bool) (*md.JoinPayResponse, error) {
  12. payParams.P0Version = "2.1"
  13. payParams.P4Cur = "1"
  14. //可注释行:
  15. //payParams.P1MerchantNo = md.PayTestAccount
  16. //payParams.P2OrderNo = "95271"
  17. //payParams.P3Amount = "0.1"
  18. //payParams.P5ProductName = "测试商品"
  19. //payParams.P9NotifyUrl = "AB|https://www.baidu.com"
  20. //--交易类型
  21. //payParams.Q1FrpCode = md.Q1FrpCodeWEIXINPAYAPP
  22. //payParams.Q1FrpCode = md.Q1FrpCodeALIPAY
  23. //原始微信AppId
  24. //payParams.Q7AppId = "gh_5a236de9850a"
  25. //微信AppId
  26. //payParams.Q7AppId = "wx5bb10bb79cb5da1c"
  27. //商家报备编号(分微信和支付宝的);支付宝的:
  28. //payParams.QATradeMerchantNo = md.PayTestAliAccount
  29. //商家报备编号(分微信和支付宝的);微信的:
  30. //payParams.QATradeMerchantNo = md.PayTestWeChatAccount
  31. //不可注释行:
  32. postData := url.Values{}
  33. creatHmac(payParams, paySecretKey, &postData)
  34. zhios_pay_utils.FilePutContents("UniPayByJoin", zhios_pay_utils.SerializeStr(map[string]interface{}{
  35. "data": payParams,
  36. }))
  37. tr := &http.Transport{
  38. TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
  39. }
  40. client := &http.Client{Transport: tr}
  41. response, err := client.Post(md.JoinPayUrl, "application/x-www-form-urlencoded", strings.NewReader(postData.Encode()))
  42. if err != nil {
  43. return nil, err
  44. }
  45. defer response.Body.Close()
  46. body, err := ioutil.ReadAll(response.Body)
  47. resp := md.JoinPayResponse{}
  48. zhios_pay_utils.Unserialize(body, &resp)
  49. return &resp, err
  50. }
  51. func creatHmac(payParams *md.JoinPayReq, paySecretKey string, postData *url.Values) {
  52. hmac := ""
  53. if payParams.P0Version != "" {
  54. postData.Add("p0_Version", payParams.P0Version)
  55. hmac = hmac + payParams.P0Version
  56. }
  57. if payParams.P1MerchantNo != "" {
  58. postData.Add("p1_MerchantNo", payParams.P1MerchantNo)
  59. hmac = hmac + payParams.P1MerchantNo
  60. }
  61. if payParams.P2OrderNo != "" {
  62. postData.Add("p2_OrderNo", payParams.P2OrderNo)
  63. hmac = hmac + payParams.P2OrderNo
  64. }
  65. if payParams.P3Amount != "" {
  66. postData.Add("p3_Amount", payParams.P3Amount)
  67. hmac = hmac + payParams.P3Amount
  68. }
  69. if payParams.P4Cur != "" {
  70. postData.Add("p4_Cur", payParams.P4Cur)
  71. hmac = hmac + payParams.P4Cur
  72. }
  73. if payParams.P5ProductName != "" {
  74. postData.Add("p5_ProductName", payParams.P5ProductName)
  75. hmac = hmac + payParams.P5ProductName
  76. }
  77. if payParams.P6ProductDesc != "" {
  78. postData.Add("p6_ProductDesc", payParams.P6ProductDesc)
  79. hmac = hmac + payParams.P6ProductDesc
  80. }
  81. if payParams.P7Mp != "" {
  82. postData.Add("p7_Mp", payParams.P7Mp)
  83. hmac = hmac + payParams.P7Mp
  84. }
  85. if payParams.P9NotifyUrl != "" {
  86. postData.Add("p9_NotifyUrl", payParams.P9NotifyUrl)
  87. hmac = hmac + payParams.P9NotifyUrl
  88. }
  89. if payParams.Q1FrpCode != "" {
  90. postData.Add("q1_FrpCode", payParams.Q1FrpCode)
  91. hmac = hmac + payParams.Q1FrpCode
  92. }
  93. if payParams.Q2MerchantBankCode != "" {
  94. postData.Add("q2_MerchantBankCode", payParams.Q2MerchantBankCode)
  95. hmac = hmac + payParams.Q2MerchantBankCode
  96. }
  97. if payParams.Q4IsShowPic != "" {
  98. postData.Add("q4_IsShowPic", payParams.Q4IsShowPic)
  99. hmac = hmac + payParams.Q4IsShowPic
  100. }
  101. if payParams.Q5OpenId != "" {
  102. postData.Add("q5_OpenId", payParams.Q5OpenId)
  103. hmac = hmac + payParams.Q5OpenId
  104. }
  105. if payParams.Q6AuthCode != "" {
  106. postData.Add("q6_AuthCode", payParams.Q6AuthCode)
  107. hmac = hmac + payParams.Q6AuthCode
  108. }
  109. if payParams.Q7AppId != "" {
  110. postData.Add("q7_AppId", payParams.Q7AppId)
  111. hmac = hmac + payParams.Q7AppId
  112. }
  113. if payParams.Q8TerminalNo != "" {
  114. postData.Add("q8_TerminalNo", payParams.Q8TerminalNo)
  115. hmac = hmac + payParams.Q8TerminalNo
  116. }
  117. if payParams.Q9TransactionModel != "" {
  118. postData.Add("q9_TransactionModel", payParams.Q9TransactionModel)
  119. hmac = hmac + payParams.Q9TransactionModel
  120. }
  121. if payParams.QATradeMerchantNo != "" {
  122. postData.Add("qa_TradeMerchantNo", payParams.QATradeMerchantNo)
  123. hmac = hmac + payParams.QATradeMerchantNo
  124. }
  125. if payParams.QBbuyerId != "" {
  126. postData.Add("qb_buyerId", payParams.QBbuyerId)
  127. hmac = hmac + payParams.QBbuyerId
  128. }
  129. if payParams.QJDJPlan != "" {
  130. postData.Add("qj_DJPlan", payParams.QJDJPlan)
  131. hmac = hmac + payParams.QJDJPlan
  132. }
  133. if payParams.QKDisablePayModel != "" {
  134. postData.Add("qk_DisablePayModel", payParams.QKDisablePayModel)
  135. hmac = hmac + payParams.QKDisablePayModel
  136. }
  137. if payParams.QLTerminalIp != "" {
  138. postData.Add("ql_TerminalIp", payParams.QLTerminalIp)
  139. hmac = hmac + payParams.QLTerminalIp
  140. }
  141. payParams.Hmac = zhios_pay_utils.Md5(hmac + paySecretKey)
  142. postData.Add("hmac", payParams.Hmac)
  143. }