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

149 rivejä
6.6 KiB

  1. package pay
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/lib/local_alipay"
  4. local_wxpay "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/lib/local_wechat"
  5. "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/md"
  6. zhios_pay_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/utils"
  7. "fmt"
  8. "github.com/iGoogle-ink/gopay"
  9. "github.com/iGoogle-ink/gopay/wechat"
  10. "github.com/pkg/errors"
  11. )
  12. /**
  13. 自有支付 支付宝
  14. req 传参
  15. ord_id //订单号
  16. amount //总金额
  17. subject //描述
  18. order_type //订单类型
  19. notify_url //自有支付回调地址
  20. platform //平台 由前端header传来的
  21. pay_app_cert_sn //应用公钥证书 值
  22. pay_alipayrsa_public_key //支付宝公钥证书 值
  23. pay_ali_use_type //支付宝选择版本 0旧版 1新版
  24. private_key //支付宝商户私钥 数据库字段 旧版 pay_ali_private_key 新版 pay_ali_new_private_key
  25. app_id //支付宝appId 数据库字段 旧版 pay_ali_app_id 新版 pay_ali_new_app_id
  26. rsa //支付宝密钥长度 旧版使用 数据库字段 pay_ali_key_len_type
  27. pkcs //支付宝密钥格式 旧版使用 数据库字段 pay_ali_key_format_type
  28. page_url //支付宝wap支付成功跳转链接
  29. */
  30. func AlipayCofing(args map[string]string) *md.PayData {
  31. var paySet = &md.PayData{
  32. PayAppCertSn: args["pay_app_cert_sn"],
  33. PayAlipayrsaPublicKey: args["pay_alipayrsa_public_key"],
  34. PayAliUseType: args["pay_ali_use_type"],
  35. }
  36. return paySet
  37. }
  38. func AlipayApp(args map[string]string) (string, error) {
  39. paySet := AlipayCofing(args)
  40. if args["private_key"] == "" || args["app_id"] == "" {
  41. return "", errors.New("请在后台正确配置支付宝")
  42. }
  43. param, err := local_alipay.TradeAppPay(args["app_id"], args["private_key"], args["subject"], args["ord_id"], args["amount"], args["notify_url"], args["rsa"], args["pkcs"], paySet)
  44. if err != nil {
  45. fmt.Println("支付宝错误日志")
  46. fmt.Println(param)
  47. fmt.Println(err)
  48. return "", errors.New("支付宝订单创建失败")
  49. }
  50. return zhios_pay_utils.AnyToString(param), nil
  51. }
  52. func AlipayPc(args map[string]string) (string, error) {
  53. paySet := AlipayCofing(args)
  54. if args["private_key"] == "" || args["app_id"] == "" {
  55. return "", errors.New("请在后台正确配置支付宝")
  56. }
  57. param, err := local_alipay.TradeAppPc(args["app_id"], args["private_key"], args["subject"], args["ord_id"], args["amount"], args["notify_url"], args["rsa"], args["pkcs"], args["page_url"], paySet)
  58. if err != nil {
  59. fmt.Println("支付宝错误日志")
  60. fmt.Println(param)
  61. fmt.Println(err)
  62. return "", errors.New("支付宝订单创建失败")
  63. }
  64. return zhios_pay_utils.AnyToString(param), nil
  65. }
  66. func AlipayWap(args map[string]string) (string, error) {
  67. paySet := AlipayCofing(args)
  68. if args["private_key"] == "" || args["app_id"] == "" {
  69. return "", errors.New("请在后台正确配置支付宝")
  70. }
  71. param, err := local_alipay.TradeWapPay(args["app_id"], args["private_key"], args["subject"], args["ord_id"], args["amount"], args["notify_url"], args["rsa"], args["pkcs"], args["page_url"], paySet)
  72. if err != nil {
  73. fmt.Println("支付宝错误日志")
  74. fmt.Println(param)
  75. fmt.Println(err)
  76. return "", errors.New("支付宝订单创建失败")
  77. }
  78. return zhios_pay_utils.AnyToString(param), nil
  79. }
  80. func AlipayApplet(args map[string]string) (string, error) {
  81. paySet := AlipayCofing(args)
  82. if args["private_key"] == "" || args["app_id"] == "" {
  83. return "", errors.New("请在后台正确配置支付宝")
  84. }
  85. param, err := local_alipay.TradeCreate(args["app_id"], args["private_key"], args["subject"], args["ord_id"], args["amount"], args["notify_url"], args["rsa"], args["pkcs"], paySet)
  86. if err != nil {
  87. fmt.Println("支付宝错误日志")
  88. fmt.Println(param)
  89. fmt.Println(err)
  90. return "", errors.New("支付宝订单创建失败")
  91. }
  92. return zhios_pay_utils.AnyToString(param), nil
  93. }
  94. // 微信app支付v2
  95. func WxAppPay(params map[string]string) (map[string]string, error) {
  96. client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true)
  97. r, err := local_wxpay.TradeAppPay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"])
  98. return r, err
  99. }
  100. // 微信H5支付v2
  101. func WxH5Pay(params map[string]string) (map[string]string, error) {
  102. client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true)
  103. r, err := local_wxpay.TradeH5Pay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"])
  104. return r, err
  105. }
  106. func WxPcPay(params map[string]string) (map[string]string, error) {
  107. client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true)
  108. r, err := local_wxpay.TradePcPay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"], params["product_id"])
  109. return r, err
  110. }
  111. // 微信小程序v2
  112. func WxMiniProgPay(params map[string]string) (map[string]string, error) {
  113. client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true)
  114. if params["third_party_wechat_openid"] == "" {
  115. return nil, errors.New("请先授权微信")
  116. }
  117. r, err := local_wxpay.TradeMiniProgPay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"], params["third_party_wechat_openid"])
  118. return r, err
  119. }
  120. // 微信JSAPI支付
  121. func WxAppJSAPIPay(params map[string]string) (map[string]string, error) {
  122. client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true)
  123. if params["third_party_wechat_openid"] == "" {
  124. return nil, errors.New("请先授权微信")
  125. }
  126. r, err := local_wxpay.TradeJSAPIPay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"], params["third_party_wechat_openid"])
  127. return r, err
  128. }
  129. func WxAppRefund(params map[string]string) (*wechat.RefundResponse, gopay.BodyMap, error) {
  130. client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true)
  131. r, r1, err := local_wxpay.TradeAppRefund(client, params["subject"], params["transaction_id"], params["out_refund_no"], params["total_fee"], params["amount"], params["p12_str"], params["notify_url"])
  132. return r, r1, err
  133. }
  134. func WxAppRefundQuery(params map[string]string) (*wechat.QueryRefundResponse, gopay.BodyMap, error) {
  135. client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true)
  136. r, r1, err := local_wxpay.TradeAppRefundQuery(client, params["transaction_id"])
  137. return r, r1, err
  138. }