支付模块
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

147 рядки
7.1 KiB

  1. package boc
  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. "fmt"
  6. "github.com/syyongx/php2go"
  7. "time"
  8. )
  9. const (
  10. MerchantId = "888007050019400"
  11. TerminalNo = "98036140"
  12. PrivateKeyStr = "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCSJk259Gd9IuvG\nRxYOma5vjo0+x2CTyP7m3uJ/epf+mwp/4XySbjVharBFmKk0XoSnZz/X/cYOgQXH\nPWPnBd0Y4qTl3xVf+DdZHF035KNG0LJPqvzqOSCuD5w32BHN0o9wFaR75PbWfsUl\nn2XqLVRFdv3IaKJYVWb8fM7VLT0aA+Rk81GXGfAbmXzNqX3lbOkqlTcBdzMHdE94\nqpAxtppVJ8JQqRJsWwzqJHo2koN+/kb3vL9IxeABJGUgU4Fy53MuC7JcvdYUoE7V\n92eD6A9g6ctSHP5y7olx9T7uMAaHk/TDv3+QNk6rI54cif7V7C5ykhtH5ZfHQ27C\nx929l7LZAgMBAAECggEAVZfVQajfyyvehbswMdDTlkYYdsHxz9uRXcj/QcWcquJG\nXerDOEcPQERpg/kKb79DVX9kpqzbh7cMmUlc7vpCKMbj6DSkohYO5EN2XLus3FZx\nd7MeeFaIyygdR59lnfNJSk2CjYTlA24vK/+UgneVuTEdJHgTTESIEitOPw9Fj6v+\n/+vRwuT6PVDm1FDUxFcYmJYzdMwJZoH0wDymofiEdn6beaHkqDXakrdY307cHOlq\ncrVQJKSybLwcBsbk9pgGrh6lCQLtQ8pHNtf6rE5FkEesO/VmdRFDGAK/9cuXEJ7u\nICdSESdfvnKl9BeN3MzSaeDSnh2IPoz13VVxXuJF+QKBgQDfHBVA/e1XFrLDM5IW\nO6nIxZeeZSufITDKHi7qRoS2mlOwjpMoIVAHCxlpnWd89YQ7NPdScEi6Z7l2sEET\n0vKfWsJ3ltowj5QUXS0XuJeAhkmK66lBNrICkatoAGeWxDrraCgkqLPNe40ydQ6h\nT2c3nR8tf++U2TzCpCXxzj6pgwKBgQCnsdTIWKwhRIltTgEzXTh3+JMQ36MH3sVt\nP14bxRN1hlR59yQvx0IEToXOHASSRU0fWxj3H8UewobYmE+2Ro+qNHFY7Do7Ypum\nIM7In00Tx4CKOVOkMZtNtR9hPk2/JUKpPSQBl7dSysBDngAwGhBhpwutWDpEiIfL\n+P4pAFuvcwKBgDrPUT7ncDdjkU1o+5oGshNtGjEzY9M3UYAFgsJYQkVL2sGQY3PR\njCG/KDyxtAS5RtjAdmzxkgooqzeA8DaEhVXB+77AMdVZE2RmxysYij7jpuEKi3vY\nKgYJVdA9QxD3urwwoVxAZ9zDM43YUznsDz4WmZBJx+JJfP2lfScHAXd3AoGAMpRR\noKgWKuaYKM7JT+vDF3RzLzi03K/VjnD5epjDmMQOgMcJNBv+jnv8ocETo+ahL17z\ntb3wX6m+sF+oU0sPFABDW9XMbpL8bWwh0qMxxVB8NbS6xKBtvk9uCo+XNZsQcylM\nzeor0h3zRbHHTrrdzAZtYDhnQrqHcv9D8av4+38CgYEAgyn1h+EompwBF4hKo6Dx\nVL/ZZYcE1E+XMzmHvP8C1sOVBSPZuCAnCx43cZiJZ94/5v8V3+4nKuWbeN1ar9BK\nXXSAVkk21qM8cv2IoDwi/DdBLXD302KMReAOWfJnQ+sbU1v2B2VPJoCwd4lSqauj\nVE4PCFhhrsou1VM1XbP8XsM=\n-----END PRIVATE KEY-----"
  13. )
  14. func Send(prd bool, privateKeyStr string, param map[string]string) (string, error) {
  15. for key, value := range param {
  16. if value == "" {
  17. delete(param, key)
  18. }
  19. }
  20. data := zhios_pay_utils.JoinStringsInASCII(param, "", "", true, false)
  21. sign, err := zhios_pay_utils.GetSign(privateKeyStr, data)
  22. if err != nil {
  23. return "", err
  24. }
  25. url := "https://cuaas.bocmacau.com/w/rsa/mercapi_ol"
  26. if prd {
  27. url = "https://aas.bocmacau.com/w/rsa/mercapi_ol"
  28. }
  29. headers := map[string]string{
  30. "Content-Type": "application/json",
  31. }
  32. param["merchantSign"] = sign
  33. fmt.Println("参数:", zhios_pay_utils.SerializeStr(param))
  34. zhios_pay_utils.CurlDebug = true
  35. res, err := zhios_pay_utils.CurlPost(url, php2go.URLEncode(zhios_pay_utils.SerializeStr(param)), headers)
  36. if err != nil {
  37. return "", err
  38. }
  39. fmt.Println(string(res))
  40. return string(res), nil
  41. }
  42. func CreateBocPayAppTradeReq(prd bool, privateKeyStr, merchantId, terminalNo string, createBocPayAppTradeReq *md.CreateBocPayAppTradeReq) (string, error) {
  43. //基础信息,必填
  44. createBocPayAppTradeReq.Version = Version
  45. createBocPayAppTradeReq.Service = CreateBocPayAppTrade
  46. createBocPayAppTradeReq.SignType = SignType
  47. createBocPayAppTradeReq.MerchantId = merchantId
  48. createBocPayAppTradeReq.TerminalNo = terminalNo
  49. createBocPayAppTradeReq.RequestId = createBocPayAppTradeReq.MercOrderNo + zhios_pay_utils.AnyToString(time.Now().Unix())
  50. //按照接口类型选填信息
  51. //createBocPayAppTradeReq.Amount = "100"
  52. //createBocPayAppTradeReq.OriginalAmount = "100"
  53. //createBocPayAppTradeReq.MercOrderNo = "2022101401"
  54. //createBocPayAppTradeReq.OrderDate = "20221013"
  55. //createBocPayAppTradeReq.OrderTime = "175600"
  56. //createBocPayAppTradeReq.NotifyUrl = "/api/v1/mall/pay/ada/sub_callback"
  57. //createBocPayAppTradeReq.Reserved1 = zhios_pay_utils.SerializeStr(map[string]string{
  58. // "mid":"123456",
  59. //})
  60. param := make(map[string]string)
  61. zhios_pay_utils.Unserialize(zhios_pay_utils.Serialize(createBocPayAppTradeReq), &param)
  62. send, err := Send(prd, privateKeyStr, param)
  63. if err != nil {
  64. return "", err
  65. }
  66. resp, _ := php2go.URLDecode(send)
  67. return resp, nil
  68. }
  69. func CreateWeChatTradeReq(prd bool, privateKeyStr, merchantId, terminalNo string, createWeChatTradeReq *md.CreateWeChatTradeReq) (string, error) {
  70. //基础信息,必填
  71. createWeChatTradeReq.Version = Version
  72. createWeChatTradeReq.Service = CreateWeChatTrade
  73. createWeChatTradeReq.SignType = SignType
  74. createWeChatTradeReq.MerchantId = merchantId
  75. createWeChatTradeReq.TerminalNo = terminalNo
  76. createWeChatTradeReq.RequestId = createWeChatTradeReq.MercOrderNo + zhios_pay_utils.AnyToString(time.Now().Unix())
  77. //按照接口类型选填信息
  78. //createBocPayAppTradeReq.Amount = "100"
  79. //createBocPayAppTradeReq.OriginalAmount = "100"
  80. //createBocPayAppTradeReq.MercOrderNo = "2022101401"
  81. //createBocPayAppTradeReq.OrderDate = "20221013"
  82. //createBocPayAppTradeReq.OrderTime = "175600"
  83. //createBocPayAppTradeReq.NotifyUrl = "/api/v1/mall/pay/ada/sub_callback"
  84. //createBocPayAppTradeReq.Reserved1 = zhios_pay_utils.SerializeStr(map[string]string{
  85. // "mid":"123456",
  86. //})
  87. param := make(map[string]string)
  88. zhios_pay_utils.Unserialize(zhios_pay_utils.Serialize(createWeChatTradeReq), &param)
  89. send, err := Send(prd, privateKeyStr, param)
  90. if err != nil {
  91. return "", err
  92. }
  93. resp, _ := php2go.URLDecode(send)
  94. return resp, nil
  95. }
  96. func CreateQRTradeReq(prd bool, privateKeyStr, merchantId, terminalNo string, createQRTradeReq *md.CreateQRTradeReq) (string, error) {
  97. //基础信息,必填
  98. createQRTradeReq.Version = Version
  99. createQRTradeReq.Service = CreateQRTrade
  100. createQRTradeReq.SignType = SignType
  101. createQRTradeReq.MerchantId = merchantId
  102. createQRTradeReq.TerminalNo = terminalNo
  103. createQRTradeReq.RequestId = createQRTradeReq.MercOrderNo + zhios_pay_utils.AnyToString(time.Now().Unix())
  104. //按照接口类型选填信息
  105. //createBocPayAppTradeReq.Amount = "100"
  106. //createBocPayAppTradeReq.OriginalAmount = "100"
  107. //createBocPayAppTradeReq.MercOrderNo = "2022101401"
  108. //createBocPayAppTradeReq.OrderDate = "20221013"
  109. //createBocPayAppTradeReq.OrderTime = "175600"
  110. //createBocPayAppTradeReq.NotifyUrl = "/api/v1/mall/pay/ada/sub_callback"
  111. //createBocPayAppTradeReq.Reserved1 = zhios_pay_utils.SerializeStr(map[string]string{
  112. // "mid":"123456",
  113. //})
  114. param := make(map[string]string)
  115. zhios_pay_utils.Unserialize(zhios_pay_utils.Serialize(createQRTradeReq), &param)
  116. send, err := Send(prd, privateKeyStr, param)
  117. if err != nil {
  118. return "", err
  119. }
  120. resp, _ := php2go.URLDecode(send)
  121. return resp, nil
  122. }
  123. func OrderQueryReq(prd bool, privateKeyStr, merchantId, terminalNo string, orderQueryReq *md.OrderQueryReq) (string, error) {
  124. //基础信息,必填
  125. orderQueryReq.Version = Version
  126. orderQueryReq.Service = OrderQuery
  127. orderQueryReq.SignType = SignType
  128. orderQueryReq.MerchantId = merchantId
  129. orderQueryReq.TerminalNo = terminalNo
  130. orderQueryReq.RequestId = zhios_pay_utils.AnyToString(time.Now().Unix())
  131. param := make(map[string]string)
  132. zhios_pay_utils.Unserialize(zhios_pay_utils.Serialize(orderQueryReq), &param)
  133. send, err := Send(prd, privateKeyStr, param)
  134. if err != nil {
  135. return "", err
  136. }
  137. resp, _ := php2go.URLDecode(send)
  138. return resp, nil
  139. }