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

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 GetAggregateCodeByVendorSn(vendorSn string) *RequestParameters {
  21. var rp RequestParameters
  22. rp.VendorSn = vendorSn
  23. rp.Method = AggregateCode
  24. return &rp
  25. }
  26. func GetRequestParametersByVendorSn(vendorSn string) *RequestParameters {
  27. var rp RequestParameters
  28. rp.VendorSn = vendorSn
  29. return &rp
  30. }
  31. func GetUnificationByAppId(appId string) *RequestParameters {
  32. var rp RequestParameters
  33. rp.AppId = appId
  34. rp.Method = Unification
  35. return &rp
  36. }
  37. func GetOrderQrcodeByAppId(appId string) *RequestParameters {
  38. var rp RequestParameters
  39. rp.AppId = appId
  40. rp.Method = OrderQrcode
  41. return &rp
  42. }
  43. func GetAggregateCodeByAppId(appId string) *RequestParameters {
  44. var rp RequestParameters
  45. rp.AppId = appId
  46. rp.Method = AggregateCode
  47. return &rp
  48. }
  49. func GetRequestParametersByAppId(appId string) *RequestParameters {
  50. var rp RequestParameters
  51. rp.AppId = appId
  52. return &rp
  53. }
  54. func (bp *BaseParameters) SetBizContent(param interface{}) {
  55. fmt.Println("参数:", zhios_pay_utils.SerializeStr(param))
  56. bp.BizContent = zhios_pay_utils.SerializeStr(param)
  57. }
  58. func (bp *BaseParameters) GetSign(appSecret string) string {
  59. struct2Map := make(map[string]string)
  60. zhios_pay_utils.Unserialize(zhios_pay_utils.Serialize(bp), &struct2Map)
  61. needSignStr := zhios_pay_utils.JoinStringsInASCII(struct2Map, "&", "=", false, false)
  62. needSignStr = needSignStr + appSecret
  63. return strings.ToUpper(zhios_pay_utils.Md5(needSignStr))
  64. }
  65. func (rp *RequestParameters) SetSign(appSecret string) {
  66. rp.Sign = rp.BaseParameters.GetSign(appSecret)
  67. }
  68. func (rp *RequestParameters) Send(prd bool) (string, error) {
  69. if rp.Sign == "" {
  70. return "", errors.New("请进行签名")
  71. }
  72. param := zhios_pay_utils.Struct2Map(rp)
  73. for key, value := range param {
  74. if value == "" {
  75. delete(param, key)
  76. }
  77. }
  78. url := TestUrl
  79. if prd {
  80. url = PrdUrl
  81. }
  82. headers := map[string]string{
  83. "Content-Type": ReqHeader,
  84. }
  85. zhios_pay_utils.CurlDebug = true
  86. res, err := zhios_pay_utils.CurlPost(url, zhios_pay_utils.SerializeStr(param), headers)
  87. if err != nil {
  88. return "", err
  89. }
  90. fmt.Println(string(res))
  91. return string(res), nil
  92. }