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

123 lines
4.0 KiB

  1. package pay
  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. "encoding/json"
  6. "fmt"
  7. "github.com/gin-gonic/gin"
  8. "github.com/pkg/errors"
  9. )
  10. //酷点 - 支付宝APP支付
  11. func AliAppPayByKuDian(payParams *md.KuDianAliAppPayParams, isPrd bool) (string, error) {
  12. var url string
  13. if isPrd == true {
  14. url = md.ZHIOS_PAY_URL_PRD + "/kuDianPay/Pay/aliAppPay"
  15. } else {
  16. url = md.ZHIOS_PAY_URL_DEV + "/kuDianPay/Pay/aliAppPay"
  17. }
  18. zhios_pay_utils.FilePutContents("AliAppPayByKuDian", zhios_pay_utils.SerializeStr(map[string]interface{}{
  19. "data": payParams,
  20. }))
  21. bytes, err := zhios_pay_utils.CurlPost(url, zhios_pay_utils.Serialize(payParams), nil)
  22. if err != nil {
  23. return "", err
  24. }
  25. var result struct {
  26. Code int `json:"code"`
  27. Msg string `json:"msg"`
  28. Data map[string]string `json:"data"`
  29. }
  30. zhios_pay_utils.FilePutContents("AliAppPayByKuDian", zhios_pay_utils.SerializeStr(result))
  31. err = json.Unmarshal(bytes, &result)
  32. if err != nil {
  33. return "", err
  34. }
  35. if result.Code != 0 {
  36. return "", errors.New(result.Msg)
  37. }
  38. zhios_pay_utils.FilePutContents("AliAppPayByKuDian", zhios_pay_utils.SerializeStr(result.Data["data"]))
  39. return result.Data["url"], nil
  40. }
  41. // 酷点 - 支付宝JsAPi支付
  42. func AliJsApiPayByKuDian(payParams *md.KuDianAliAppPayParams, isPrd bool) (string, error) {
  43. var url string
  44. if isPrd == true {
  45. url = md.ZHIOS_PAY_URL_PRD + "/kuDianPay/Pay/aliJsApiPay"
  46. } else {
  47. url = md.ZHIOS_PAY_URL_DEV + "/kuDianPay/Pay/aliJsApiPay"
  48. }
  49. zhios_pay_utils.FilePutContents("AliAppPayByKuDian", zhios_pay_utils.SerializeStr(map[string]interface{}{
  50. "data": payParams,
  51. }))
  52. bytes, err := zhios_pay_utils.CurlPost(url, zhios_pay_utils.Serialize(payParams), nil)
  53. if err != nil {
  54. return "", err
  55. }
  56. var result struct {
  57. Code int `json:"code"`
  58. Msg string `json:"msg"`
  59. Data map[string]string `json:"data"`
  60. }
  61. zhios_pay_utils.FilePutContents("AliAppPayByKuDian", zhios_pay_utils.SerializeStr(result))
  62. err = json.Unmarshal(bytes, &result)
  63. if err != nil {
  64. return "", err
  65. }
  66. if result.Code != 0 {
  67. return "", errors.New(result.Msg)
  68. }
  69. zhios_pay_utils.FilePutContents("AliAppPayByKuDian", zhios_pay_utils.SerializeStr(result.Data["data"]))
  70. return result.Data["trade_no"], nil
  71. }
  72. // 酷点 - 微信小程序支付
  73. func WxAppletPayByKuDian(payParams *md.KuDianWxPayParams, isPrd bool) (interface{}, error) {
  74. var url string
  75. if isPrd == true {
  76. url = md.ZHIOS_PAY_URL_PRD + "/kuDianPay/Pay/wxJsAPi"
  77. } else {
  78. url = md.ZHIOS_PAY_URL_DEV + "/kuDianPay/Pay/wxJsAPi"
  79. }
  80. zhios_pay_utils.FilePutContents("WxAppletPayByKuDian", zhios_pay_utils.SerializeStr(map[string]interface{}{
  81. "data": payParams,
  82. }))
  83. bytes, err := zhios_pay_utils.CurlPost(url, zhios_pay_utils.Serialize(payParams), nil)
  84. if err != nil {
  85. return nil, err
  86. }
  87. var result struct {
  88. Code int `json:"code"`
  89. Msg string `json:"msg"`
  90. Data map[string]interface{} `json:"data"`
  91. }
  92. zhios_pay_utils.FilePutContents("WxAppletPayByKuDian", zhios_pay_utils.SerializeStr(result))
  93. err = json.Unmarshal(bytes, &result)
  94. if err != nil {
  95. return nil, err
  96. }
  97. if result.Code != 0 {
  98. return nil, errors.New(result.Msg)
  99. }
  100. zhios_pay_utils.FilePutContents("WxAppletPayByKuDian", zhios_pay_utils.SerializeStr(result.Data["data"]))
  101. return result.Data["data"], nil
  102. }
  103. // 酷点 - 检查返回参数
  104. func CheckAllCallbackParamsByKuDian(c *gin.Context) (interface{}, error) {
  105. var dataWx md.KuDianPayCallback
  106. if err := c.ShouldBindJSON(&dataWx); err != nil {
  107. fmt.Println(">>>>>>>>>CheckAllCallbackParamsByKuDian>>>>>>>>>>>>>>", err)
  108. return nil, err
  109. }
  110. var dataPay md.KuDianPayCallbackResp
  111. if err := json.Unmarshal([]byte(dataWx.Result), &dataPay); err != nil {
  112. fmt.Println(">>>>>>>>>CheckAllCallbackParamsByKuDian>>>>>>>>>>>>>>", err)
  113. return nil, err
  114. }
  115. zhios_pay_utils.FilePutContents("CheckAllCallbackParamsByKuDian", zhios_pay_utils.SerializeStr(dataPay))
  116. return dataPay, nil
  117. }