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

pay_by_own.go 7.7 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. v3 "github.com/iGoogle-ink/gopay/wechat/v3"
  10. "github.com/iGoogle-ink/gotil/xlog"
  11. "github.com/pkg/errors"
  12. )
  13. //自有支付 支付宝
  14. func Alipay(args map[string]string) (string, error) {
  15. var paySet = &md.PayData{
  16. PayAppCertSn: args["pay_app_cert_sn"],
  17. PayAlipayRootCertSn: args["pay_alipay_root_cert_sn"],
  18. PayAlipayrsaPublicKey: args["pay_alipayrsa_public_key"],
  19. PayAliUseType: args["pay_ali_use_type"],
  20. WxAppletFilepathUrl: args["wx_applet_filepath_url"],
  21. }
  22. if args["private_key"] == "" || args["app_id"] == "" {
  23. return "", errors.New("请在后台正确配置支付宝")
  24. }
  25. var param interface{}
  26. var err error
  27. switch args["platform"] {
  28. case md.PLATFORM_ALIPAY_APPLET:
  29. 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)
  30. case md.PLATFORM_WAP:
  31. 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)
  32. case md.PLATFORM_ANDROID, md.PLATFORM_IOS:
  33. 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)
  34. default:
  35. return "", errors.New("支付平台不存在")
  36. }
  37. if err != nil {
  38. fmt.Println("支付宝错误日志")
  39. fmt.Println(param)
  40. fmt.Println(err)
  41. return "", errors.New("支付宝订单创建失败")
  42. }
  43. return zhios_pay_utils.AnyToString(param), nil
  44. }
  45. func AlipayApp(args map[string]string) (string, error) {
  46. var paySet = &md.PayData{
  47. PayAppCertSn: args["pay_app_cert_sn"],
  48. PayAlipayRootCertSn: args["pay_alipay_root_cert_sn"],
  49. PayAlipayrsaPublicKey: args["pay_alipayrsa_public_key"],
  50. PayAliUseType: args["pay_ali_use_type"],
  51. WxAppletFilepathUrl: args["wx_applet_filepath_url"],
  52. }
  53. if args["private_key"] == "" || args["app_id"] == "" {
  54. return "", errors.New("请在后台正确配置支付宝")
  55. }
  56. 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)
  57. if err != nil {
  58. fmt.Println("支付宝错误日志")
  59. fmt.Println(param)
  60. fmt.Println(err)
  61. return "", errors.New("支付宝订单创建失败")
  62. }
  63. return zhios_pay_utils.AnyToString(param), nil
  64. }
  65. func AlipayWap(args map[string]string) (string, error) {
  66. var paySet = &md.PayData{
  67. PayAppCertSn: args["pay_app_cert_sn"],
  68. PayAlipayRootCertSn: args["pay_alipay_root_cert_sn"],
  69. PayAlipayrsaPublicKey: args["pay_alipayrsa_public_key"],
  70. PayAliUseType: args["pay_ali_use_type"],
  71. WxAppletFilepathUrl: args["wx_applet_filepath_url"],
  72. }
  73. if args["private_key"] == "" || args["app_id"] == "" {
  74. return "", errors.New("请在后台正确配置支付宝")
  75. }
  76. 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)
  77. if err != nil {
  78. fmt.Println("支付宝错误日志")
  79. fmt.Println(param)
  80. fmt.Println(err)
  81. return "", errors.New("支付宝订单创建失败")
  82. }
  83. return zhios_pay_utils.AnyToString(param), nil
  84. }
  85. func AlipayApplet(args map[string]string) (string, error) {
  86. var paySet = &md.PayData{
  87. PayAppCertSn: args["pay_app_cert_sn"],
  88. PayAlipayRootCertSn: args["pay_alipay_root_cert_sn"],
  89. PayAlipayrsaPublicKey: args["pay_alipayrsa_public_key"],
  90. PayAliUseType: args["pay_ali_use_type"],
  91. WxAppletFilepathUrl: args["wx_applet_filepath_url"],
  92. }
  93. if args["private_key"] == "" || args["app_id"] == "" {
  94. return "", errors.New("请在后台正确配置支付宝")
  95. }
  96. 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)
  97. if err != nil {
  98. fmt.Println("支付宝错误日志")
  99. fmt.Println(param)
  100. fmt.Println(err)
  101. return "", errors.New("支付宝订单创建失败")
  102. }
  103. return zhios_pay_utils.AnyToString(param), nil
  104. }
  105. //自有支付 微信支付
  106. // app支付v2
  107. func WxAppPay(params *md.WxPayParams) (map[string]string, error) {
  108. appId := params.PayWxAppid
  109. mchId := params.PayWxMchId
  110. apiKey := params.PayWxApiKey
  111. notifyUrl := params.NotifyUrl
  112. client := local_wxpay.NewClient(appId, mchId, apiKey, true)
  113. r, err := local_wxpay.TradeAppPay(client, params.Subject, params.OrdId, params.Amount, notifyUrl)
  114. return r, err
  115. }
  116. // H5支付v2
  117. func WxH5Pay(params *md.WxPayParams) (map[string]string, error) {
  118. appId := params.PayWxAppid
  119. mchId := params.PayWxMchId
  120. apiKey := params.PayWxApiKey
  121. notifyUrl := params.NotifyUrl
  122. client := local_wxpay.NewClient(appId, mchId, apiKey, true)
  123. r, err := local_wxpay.TradeH5Pay(client, params.Subject, params.OrdId, params.Amount, notifyUrl)
  124. return r, err
  125. }
  126. // 小程序v2
  127. func WxMiniProgPay(params *md.WxPayParams) (map[string]string, error) {
  128. appId := params.PayWxAppid
  129. mchId := params.PayWxMchId
  130. apiKey := params.PayWxApiKey
  131. notifyUrl := params.NotifyUrl
  132. client := local_wxpay.NewClient(appId, mchId, apiKey, true)
  133. if params.ThirdPartyWechatOpenid == "" {
  134. return nil, errors.New("请先授权微信")
  135. }
  136. r, err := local_wxpay.TradeMiniProgPay(client, params.Subject, params.OrdId, params.Amount, notifyUrl, params.ThirdPartyWechatOpenid)
  137. return r, err
  138. }
  139. // app支付V3
  140. func WxAppPayV3(params *md.WxPayParams) (map[string]string, error) {
  141. appId := params.PayWxAppid
  142. mchId := params.PayWxMchId
  143. notifyUrl := params.NotifyUrl
  144. SerialNo := params.PayWxApiKey
  145. ApiV3Key := params.PayWxApiKey
  146. PKContent := params.PayWxApiKey
  147. client, err := v3.NewClientV3(appId, mchId, SerialNo, ApiV3Key, PKContent)
  148. if err != nil {
  149. xlog.Error(err)
  150. return nil, err
  151. }
  152. client.DebugSwitch = gopay.DebugOff
  153. r, err := local_wxpay.TradeAppPayV3(client, params.Subject, params.OrdId, params.Amount, notifyUrl)
  154. return r, err
  155. }
  156. // 微信JSAPI支付
  157. func WxAppJSAPIPay(params *md.WxPayParams) (map[string]string, error) {
  158. appId := params.PayWxAppid
  159. mchId := params.PayWxMchId
  160. apiKey := params.PayWxApiKey
  161. notifyUrl := params.NotifyUrl
  162. client := local_wxpay.NewClient(appId, mchId, apiKey, true)
  163. if params.ThirdPartyWechatOpenid == "" {
  164. return nil, errors.New("请先授权微信")
  165. }
  166. r, err := local_wxpay.TradeJSAPIPay(client, params.Subject, params.OrdId, params.Amount, notifyUrl, params.ThirdPartyWechatOpenid)
  167. return r, err
  168. }
  169. // H5支付V3
  170. func WxH5PayV3(params *md.WxPayParams) (string, error) {
  171. appId := params.PayWxAppid
  172. mchId := params.PayWxMchId
  173. apiKey := params.PayWxApiKey
  174. notifyUrl := params.NotifyUrl
  175. client := local_wxpay.NewClient(appId, mchId, apiKey, false)
  176. _, err := local_wxpay.TradeH5Pay(client, params.Subject, params.OrdId, params.Amount, notifyUrl)
  177. return "", err
  178. }
  179. // 小程序V3
  180. func WxMiniProgPayV3(params *md.WxPayParams) (string, error) {
  181. appId := params.PayWxAppid
  182. mchId := params.PayWxMchId
  183. notifyUrl := params.NotifyUrl
  184. SerialNo := params.PayWxApiKey
  185. ApiV3Key := params.PayWxApiKey
  186. PKContent := params.PayWxApiKey
  187. client, err := v3.NewClientV3(appId, mchId, SerialNo, ApiV3Key, PKContent)
  188. if err != nil {
  189. xlog.Error(err)
  190. return "", err
  191. }
  192. client.DebugSwitch = gopay.DebugOff
  193. r, err := local_wxpay.TradeMiniProgPayV3(client, params.Subject, params.OrdId, params.Amount, notifyUrl)
  194. return r, err
  195. }