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

83 lines
3.9 KiB

  1. package luso_bank
  2. import (
  3. zhios_pay_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/utils"
  4. "encoding/base64"
  5. "fmt"
  6. "github.com/syyongx/php2go"
  7. "math/rand"
  8. "time"
  9. )
  10. const (
  11. MerchantId = "30010"
  12. TerminalNo = "98036140"
  13. 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\nEUi6qllpB0qhoEmSVQxONcR3GIep0IwDj8PHQtP55qECgYEA7cnP0yNcc1if7Dd/\nBh0xWGafMVkHIPbbBVOgR3FakaTuC5g0OQ7LP5O8OCW1pchyJY0HXLCEiRVSj5O7\n3MY59eIbdqpcBI7a+ZxOyBHEN2IqZ4EVZmkCxd7w7XA12D+mT19rc//F03FT78e5\neYniSWmj0ku1bSJ7oYb1g4mPf6kCgYEA4n8MKlYIf0JALvMgws78M75JMVpSVgDs\nOngZvMF7z7x4gkBxXxxc5ABe6k/RXCuz59n2IQU3NzS0Y3HxCvZyeJzh1X5ENSdD\nsyJVFkb4oC8nhKvztXT8CwH1vSIGMRUJNE3Gn8IrX8QdEWdvADz/+Iw81HtOh7lr\nAGyreWyLc/UCgYBBFaXuspURdUaAj0gTUlY5Tg1wol+TJD4anSMXqu0RREVrowNY\nQrZa9oLkE14+vDiSEqHbOu1r4AwzBEq9SPyAUp0Vw9df4AILpD7kAAjm59WXcvt6\nhm+d3UGwm7ABOpq4yvNMUsvA7hn9XXtkytrHIUUXwGUuM+wG8Duu/y3p0QKBgQC3\nsZKMQ3pgu7qSWV0YogapcIqsHDTqy5TLVtyI2eMweArEmL9aBAbSY/qWzmVd+5PN\nVljoLvK5M2WZwa9c1MPCTnpaTC3FbjLZ9d5MUwMR5yyFzW+6m0ZPJyfGXPHonMb6\nRJnyt+e1o7hvhRPhfZecXSB4tAjcyuSdU4U+1WnEgQKBgAUZFTYeIyC/bnIca5m8\nzh2wIW0KusCLPa9e3VGTARJG5WP6nx8BPVx71Er/wquBLLquoH0XlTmpdj80QF+s\nHlnKE9CfXVu23ci2S0WalbX/8CYGlO5iCct9o0KR0inrXKfqFzuSKkpg6JyXVMk0\nMT1+EUSD25ATIRsNGFWigNHL\n-----END PRIVATE KEY-----"
  14. MchtStoreNm = "世寶商城"
  15. )
  16. type PayParam struct {
  17. Data string `json:"data"`
  18. Sign string `json:"sign"`
  19. }
  20. type DataParam struct {
  21. Head struct {
  22. MchtNo string `json:"mchtNo" explain:"商户编号"`
  23. ReqTime string `json:"reqTime" explain:"请求时间戳(yyyyMMddHHmmss)"`
  24. MsgId string `json:"msgId" explain:"请求消息唯一编号"`
  25. Attach string `json:"attach" explain:"附加数据(附加数据,用于在同步应答或异步通知时原样返回)"`
  26. } `json:"head"`
  27. ReqBody map[string]string `json:"reqBody"`
  28. }
  29. type signParam struct {
  30. PayParam *PayParam
  31. }
  32. func (payParam *PayParam) SetData(dataParam DataParam) *signParam {
  33. now := time.Now()
  34. rand.Seed(now.UnixNano())
  35. randomInt := rand.Intn(100)
  36. dataParam.Head.MsgId = zhios_pay_utils.AnyToString(randomInt) + dataParam.Head.MchtNo + now.Format("20060102150405")
  37. dataParam.Head.ReqTime = now.Format("20060102150405")
  38. payParam.Data = zhios_pay_utils.SerializeStr(dataParam)
  39. var signs signParam
  40. signs.PayParam = payParam
  41. return &signs
  42. }
  43. func (s *signParam) SetSign(privateKeyStr string) error {
  44. dataParamBase64Str := base64.StdEncoding.EncodeToString([]byte(s.PayParam.Data))
  45. signStr, err := zhios_pay_utils.GetSign(privateKeyStr, dataParamBase64Str)
  46. if err != nil {
  47. return err
  48. }
  49. s.PayParam.Sign = signStr
  50. s.PayParam.Data = dataParamBase64Str
  51. return nil
  52. }
  53. func (payParam *PayParam) Send(prd bool, method string) (string, error) {
  54. url := "https://qrpaytest.lusobank.com.mo:443"
  55. if prd {
  56. url = "https://qrpaytest.lusobank.com.mo:8443"
  57. }
  58. switch method {
  59. case "create":
  60. url = url + "/upcp-iap-pps-lqrp/libQrPay/json/create"
  61. case "pay":
  62. url = url + "/upcp-iap-pps-lqrp/libQrPay/json/pay"
  63. }
  64. headers := map[string]string{
  65. "Content-Type": "application/json",
  66. }
  67. zhios_pay_utils.CurlDebug = true
  68. res, err := zhios_pay_utils.CurlPost(url, php2go.URLEncode(zhios_pay_utils.SerializeStr(payParam)), headers)
  69. if err != nil {
  70. return "", err
  71. }
  72. fmt.Println(string(res))
  73. return string(res), nil
  74. }