支付模块
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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