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

fb_pay.go 2.8 KiB

1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package fb_pay
  2. import (
  3. zhios_pay_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/utils"
  4. "errors"
  5. "fmt"
  6. "strings"
  7. )
  8. func GetUnificationByVendorSn(vendorSn string) *RequestParameters {
  9. var rp RequestParameters
  10. rp.VendorSn = vendorSn
  11. rp.Method = Unification
  12. return &rp
  13. }
  14. func GetOrderQrcodeByVendorSn(vendorSn string) *RequestParameters {
  15. var rp RequestParameters
  16. rp.VendorSn = vendorSn
  17. rp.Method = OrderQrcode
  18. return &rp
  19. }
  20. func GetRefundByVendorSn(vendorSn string) *RequestParameters {
  21. var rp RequestParameters
  22. rp.VendorSn = vendorSn
  23. rp.Method = Refund
  24. return &rp
  25. }
  26. func GetRefundQueryByVendorSn(vendorSn string) *RequestParameters {
  27. var rp RequestParameters
  28. rp.VendorSn = vendorSn
  29. rp.Method = RefundQuery
  30. return &rp
  31. }
  32. func GetAggregateCodeByVendorSn(vendorSn string) *RequestParameters {
  33. var rp RequestParameters
  34. rp.VendorSn = vendorSn
  35. rp.Method = AggregateCode
  36. return &rp
  37. }
  38. func GetRequestParametersByVendorSn(vendorSn string) *RequestParameters {
  39. var rp RequestParameters
  40. rp.VendorSn = vendorSn
  41. return &rp
  42. }
  43. func GetUnificationByAppId(appId string) *RequestParameters {
  44. var rp RequestParameters
  45. rp.AppId = appId
  46. rp.Method = Unification
  47. return &rp
  48. }
  49. func GetOrderQrcodeByAppId(appId string) *RequestParameters {
  50. var rp RequestParameters
  51. rp.AppId = appId
  52. rp.Method = OrderQrcode
  53. return &rp
  54. }
  55. func GetAggregateCodeByAppId(appId string) *RequestParameters {
  56. var rp RequestParameters
  57. rp.AppId = appId
  58. rp.Method = AggregateCode
  59. return &rp
  60. }
  61. func GetRequestParametersByAppId(appId string) *RequestParameters {
  62. var rp RequestParameters
  63. rp.AppId = appId
  64. return &rp
  65. }
  66. func (bp *BaseParameters) SetBizContent(param interface{}) {
  67. fmt.Println("参数:", zhios_pay_utils.SerializeStr(param))
  68. bp.BizContent = zhios_pay_utils.SerializeStr(param)
  69. }
  70. func (bp *BaseParameters) GetSign(appSecret string) string {
  71. struct2Map := make(map[string]string)
  72. zhios_pay_utils.Unserialize(zhios_pay_utils.Serialize(bp), &struct2Map)
  73. needSignStr := zhios_pay_utils.JoinStringsInASCII(struct2Map, "&", "=", false, false)
  74. needSignStr = needSignStr + appSecret
  75. return strings.ToUpper(zhios_pay_utils.Md5(needSignStr))
  76. }
  77. func (rp *RequestParameters) SetSign(appSecret string) {
  78. rp.Sign = rp.BaseParameters.GetSign(appSecret)
  79. }
  80. func (rp *RequestParameters) Send(prd bool) (string, error) {
  81. if rp.Sign == "" {
  82. return "", errors.New("请进行签名")
  83. }
  84. param := zhios_pay_utils.Struct2Map(rp)
  85. for key, value := range param {
  86. if value == "" {
  87. delete(param, key)
  88. }
  89. }
  90. url := TestUrl
  91. if prd {
  92. url = PrdUrl
  93. }
  94. headers := map[string]string{
  95. "Content-Type": ReqHeader,
  96. }
  97. zhios_pay_utils.CurlDebug = true
  98. res, err := zhios_pay_utils.CurlPost(url, zhios_pay_utils.SerializeStr(param), headers)
  99. if err != nil {
  100. return "", err
  101. }
  102. fmt.Println(string(res))
  103. return string(res), nil
  104. }