支付模块
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.

102 rindas
5.0 KiB

  1. package luso_bank
  2. import (
  3. zhios_pay_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/utils"
  4. "crypto"
  5. "encoding/base64"
  6. "fmt"
  7. "github.com/syyongx/php2go"
  8. "math/rand"
  9. "time"
  10. )
  11. const (
  12. MerchantId = "30010"
  13. TerminalNo = "98036140"
  14. PrivateKeyStr = "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDSYivjR7nXUazy\nf+F1i/nvuy/doiHRsiTSwavHIwKF88kzM95Eh5wGiXq6TXwFPhB5yeV8l3tFQxeu\nPycZeKmp0VBge+U+/UhR1rQwEX9U9LeKhVdjbNU0U8kNpO8qX/QqHSS7MCRILL2a\nS4F5U/wvYGkbqJ+qMUNmEMGwEkiVuDaO/Q4I3lMPNtLO+mizgq9jggEkVh+xG50p\nFATWd6CJh0mddBBgGG3/aG1ybV/IYRRP0sS+dbYKmKghbK2d/LztIM8ba7lA16H9\nxLY8oy8SvwGqkq2Gea9K2AIEjociac4i0Q/Ka2U881rJCrDUMg3gDhIundaa971M\nglS5cRe9AgMBAAECggEBALe9P6FHIlqYHZjI8QqtToL+E6bYk/rFP/3FYZYQ0IJW\n0NDkKunlGfJnnYUaaQdXFiKXntJ6phFusD7hLu/C/0Kt6Snq6uNhaAj5n/MfRPrY\no3faTuEpyubhigVdl/eFSASD4XGOcRGL6afY6+If5G8oH4QleBS246s/VTnGLhh6\n7cWv2PvFQOU6WzayYzs+8wIYPlVlhKIfuU7vbQF7sWIFfJg8zqVFe2lNXwGS3D2f\ns8AjjN9lMemWF/t9OIA4l9b/Mr2D1wc71AznTUXgBWqm747tWAYyEQ+r1PimbPMB\nEUi6qllpB0qhoEmSVQxONcR3GIep0IwDj8PHQtP55qECgY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IecBol6uk18BT4QecnlfJd7RUMXrj8nGXip\nqdFQYHvlPv1IUda0MBF/VPS3ioVXY2zVNFPJDaTvKl/0Kh0kuzAkSCy9mkuBeVP8\nL2BpG6ifqjFDZhDBsBJIlbg2jv0OCN5TDzbSzvpos4KvY4IBJFYfsRudKRQE1neg\niYdJnXQQYBht/2htcm1fyGEUT9LEvnW2CpioIWytnfy87SDPG2u5QNeh/cS2PKMv\nEr8BqpKthnmvStgCBI6HImnOItEPymtlPPNayQqw1DIN4A4SLp3Wmve9TIJUuXEX\nvQIDAQAB\n-----END PUBLIC KEY-----"
  17. )
  18. type PayParam struct {
  19. Data string `json:"data"`
  20. Sign string `json:"sign"`
  21. }
  22. type DataParam struct {
  23. Head struct {
  24. MchtNo string `json:"mchtNo" explain:"商户编号"`
  25. ReqTime string `json:"reqTime" explain:"请求时间戳(yyyyMMddHHmmss)"`
  26. MsgId string `json:"msgId" explain:"请求消息唯一编号"`
  27. Attach string `json:"attach" explain:"附加数据(附加数据,用于在同步应答或异步通知时原样返回)"`
  28. CertId string `json:"certId" explain:"数字证书 ID(默认 01)"`
  29. Version string `json:"version" explain:"版本号(默认 1.0.0)"`
  30. } `json:"head"`
  31. ReqBody map[string]string `json:"reqBody"`
  32. }
  33. type signParam struct {
  34. PayParam *PayParam
  35. }
  36. func (payParam *PayParam) SetData(dataParam DataParam) *signParam {
  37. now := time.Now()
  38. rand.Seed(now.UnixNano())
  39. randomInt := rand.Intn(100)
  40. dataParam.Head.MsgId = zhios_pay_utils.AnyToString(randomInt) + dataParam.Head.MchtNo + now.Format("20060102150405")
  41. dataParam.Head.ReqTime = now.Format("20060102150405")
  42. dataParam.Head.CertId = "01"
  43. dataParam.Head.Version = "1.0.0"
  44. if dataParam.ReqBody["mchtOrderId"] != "" {
  45. dataParam.Head.MsgId = dataParam.ReqBody["mchtOrderId"] + now.Format("20060102150405")
  46. }
  47. payParam.Data = zhios_pay_utils.SerializeStr(dataParam)
  48. var signs signParam
  49. signs.PayParam = payParam
  50. return &signs
  51. }
  52. func (s *signParam) SetSign(privateKeyStr string) error {
  53. dataParamBase64Str := base64.StdEncoding.EncodeToString([]byte(s.PayParam.Data))
  54. signStr, err := zhios_pay_utils.GetSignV2(privateKeyStr, dataParamBase64Str, crypto.SHA1)
  55. if err != nil {
  56. return err
  57. }
  58. s.PayParam.Sign = signStr
  59. s.PayParam.Data = dataParamBase64Str
  60. return nil
  61. }
  62. func (payParam *PayParam) Send(prd, isNeedEncode bool, method string) (string, error) {
  63. url := "https://qrpaytest.lusobank.com.mo:443"
  64. if prd {
  65. url = "https://qrpay.lusobank.com.mo:443"
  66. }
  67. switch method {
  68. case "create":
  69. url = url + "/upcp-iap-pps-lqrp/libQrPay/json/create"
  70. case "pay":
  71. url = url + "/upcp-iap-pps-lqrp/libQrPay/json/pay"
  72. case "revoke":
  73. url = url + "/upcp-iap-pps-lqrp/libQrPay/json/revoke"
  74. case "refund":
  75. url = url + "/upcp-iap-pps-lqrp/libQrPay/json/refund"
  76. case "query":
  77. url = url + "/upcp-iap-pps-lqrp/libQrPay/json/query"
  78. }
  79. headers := map[string]string{
  80. "Content-Type": "application/json",
  81. }
  82. zhios_pay_utils.CurlDebug = true
  83. body := zhios_pay_utils.SerializeStr(payParam)
  84. if isNeedEncode {
  85. body = php2go.URLEncode(body)
  86. }
  87. res, err := zhios_pay_utils.CurlPost(url, body, headers)
  88. if err != nil {
  89. return "", err
  90. }
  91. fmt.Println(string(res))
  92. return string(res), nil
  93. }