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

118 lines
4.8 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/pkg/errors"
  9. )
  10. /**
  11. 自有支付 支付宝
  12. req 传参
  13. ord_id //订单号
  14. amount //总金额
  15. subject //描述
  16. order_type //订单类型
  17. notify_url //自有支付回调地址
  18. platform //平台 由前端header传来的
  19. pay_app_cert_sn //应用公钥证书 值
  20. pay_alipayrsa_public_key //支付宝公钥证书 值
  21. pay_ali_use_type //支付宝选择版本 0旧版 1新版
  22. private_key //支付宝商户私钥 数据库字段 旧版 pay_ali_private_key 新版 pay_ali_new_private_key
  23. app_id //支付宝appId 数据库字段 旧版 pay_ali_app_id 新版 pay_ali_new_app_id
  24. rsa //支付宝密钥长度 旧版使用 数据库字段 pay_ali_key_len_type
  25. pkcs //支付宝密钥格式 旧版使用 数据库字段 pay_ali_key_format_type
  26. page_url //支付宝wap支付成功跳转链接
  27. */
  28. func AlipayCofing(args map[string]string) *md.PayData {
  29. var paySet = &md.PayData{
  30. PayAppCertSn: args["pay_app_cert_sn"],
  31. PayAlipayrsaPublicKey: args["pay_alipayrsa_public_key"],
  32. PayAliUseType: args["pay_ali_use_type"],
  33. }
  34. return paySet
  35. }
  36. func AlipayApp(args map[string]string) (string, error) {
  37. paySet := AlipayCofing(args)
  38. if args["private_key"] == "" || args["app_id"] == "" {
  39. return "", errors.New("请在后台正确配置支付宝")
  40. }
  41. 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)
  42. if err != nil {
  43. fmt.Println("支付宝错误日志")
  44. fmt.Println(param)
  45. fmt.Println(err)
  46. return "", errors.New("支付宝订单创建失败")
  47. }
  48. return zhios_pay_utils.AnyToString(param), nil
  49. }
  50. func AlipayWap(args map[string]string) (string, error) {
  51. paySet := AlipayCofing(args)
  52. if args["private_key"] == "" || args["app_id"] == "" {
  53. return "", errors.New("请在后台正确配置支付宝")
  54. }
  55. 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)
  56. if err != nil {
  57. fmt.Println("支付宝错误日志")
  58. fmt.Println(param)
  59. fmt.Println(err)
  60. return "", errors.New("支付宝订单创建失败")
  61. }
  62. return zhios_pay_utils.AnyToString(param), nil
  63. }
  64. func AlipayApplet(args map[string]string) (string, error) {
  65. paySet := AlipayCofing(args)
  66. if args["private_key"] == "" || args["app_id"] == "" {
  67. return "", errors.New("请在后台正确配置支付宝")
  68. }
  69. 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)
  70. if err != nil {
  71. fmt.Println("支付宝错误日志")
  72. fmt.Println(param)
  73. fmt.Println(err)
  74. return "", errors.New("支付宝订单创建失败")
  75. }
  76. return zhios_pay_utils.AnyToString(param), nil
  77. }
  78. // 微信app支付v2
  79. func WxAppPay(params map[string]string) (map[string]string, error) {
  80. client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true)
  81. r, err := local_wxpay.TradeAppPay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"])
  82. return r, err
  83. }
  84. // 微信H5支付v2
  85. func WxH5Pay(params map[string]string) (map[string]string, error) {
  86. client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true)
  87. r, err := local_wxpay.TradeH5Pay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"])
  88. return r, err
  89. }
  90. // 微信小程序v2
  91. func WxMiniProgPay(params map[string]string) (map[string]string, error) {
  92. client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true)
  93. if params["third_party_wechat_openid"] == "" {
  94. return nil, errors.New("请先授权微信")
  95. }
  96. r, err := local_wxpay.TradeMiniProgPay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"], params["third_party_wechat_openid"])
  97. return r, err
  98. }
  99. // 微信JSAPI支付
  100. func WxAppJSAPIPay(params map[string]string) (map[string]string, error) {
  101. client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true)
  102. if params["third_party_wechat_openid"] == "" {
  103. return nil, errors.New("请先授权微信")
  104. }
  105. r, err := local_wxpay.TradeJSAPIPay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"], params["third_party_wechat_openid"])
  106. return r, err
  107. }