|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- package pay
-
- import (
- "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/lib/local_alipay"
- local_wxpay "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/lib/local_wechat"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/md"
- zhios_pay_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/utils"
- "fmt"
- "github.com/iGoogle-ink/gopay"
- v3 "github.com/iGoogle-ink/gopay/wechat/v3"
- "github.com/iGoogle-ink/gotil/xlog"
- "github.com/pkg/errors"
- )
-
- //自有支付 支付宝
- func Alipay(args map[string]string) (string, error) {
- var paySet = &md.PayData{
- PayAppCertSn: args["pay_app_cert_sn"],
- PayAlipayRootCertSn: args["pay_alipay_root_cert_sn"],
- PayAlipayrsaPublicKey: args["pay_alipayrsa_public_key"],
- PayAliUseType: args["pay_ali_use_type"],
- WxAppletFilepathUrl: args["wx_applet_filepath_url"],
- }
- if args["private_key"] == "" || args["app_id"] == "" {
- return "", errors.New("请在后台正确配置支付宝")
- }
- var param interface{}
- var err error
- switch args["platform"] {
- case md.PLATFORM_ALIPAY_APPLET:
- 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)
- case md.PLATFORM_WAP:
- 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)
- case md.PLATFORM_ANDROID, md.PLATFORM_IOS:
- 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)
- default:
- return "", errors.New("支付平台不存在")
- }
- if err != nil {
- fmt.Println("支付宝错误日志")
- fmt.Println(param)
- fmt.Println(err)
- return "", errors.New("支付宝订单创建失败")
- }
- return zhios_pay_utils.AnyToString(param), nil
- }
- func AlipayApp(args map[string]string) (string, error) {
- var paySet = &md.PayData{
- PayAppCertSn: args["pay_app_cert_sn"],
- PayAlipayRootCertSn: args["pay_alipay_root_cert_sn"],
- PayAlipayrsaPublicKey: args["pay_alipayrsa_public_key"],
- PayAliUseType: args["pay_ali_use_type"],
- WxAppletFilepathUrl: args["wx_applet_filepath_url"],
- }
- if args["private_key"] == "" || args["app_id"] == "" {
- return "", errors.New("请在后台正确配置支付宝")
- }
- 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)
- if err != nil {
- fmt.Println("支付宝错误日志")
- fmt.Println(param)
- fmt.Println(err)
- return "", errors.New("支付宝订单创建失败")
- }
- return zhios_pay_utils.AnyToString(param), nil
- }
-
- func AlipayWap(args map[string]string) (string, error) {
-
- var paySet = &md.PayData{
- PayAppCertSn: args["pay_app_cert_sn"],
- PayAlipayRootCertSn: args["pay_alipay_root_cert_sn"],
- PayAlipayrsaPublicKey: args["pay_alipayrsa_public_key"],
- PayAliUseType: args["pay_ali_use_type"],
- WxAppletFilepathUrl: args["wx_applet_filepath_url"],
- }
- if args["private_key"] == "" || args["app_id"] == "" {
- return "", errors.New("请在后台正确配置支付宝")
- }
- 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)
- if err != nil {
- fmt.Println("支付宝错误日志")
- fmt.Println(param)
- fmt.Println(err)
- return "", errors.New("支付宝订单创建失败")
- }
- return zhios_pay_utils.AnyToString(param), nil
- }
-
- func AlipayApplet(args map[string]string) (string, error) {
- var paySet = &md.PayData{
- PayAppCertSn: args["pay_app_cert_sn"],
- PayAlipayRootCertSn: args["pay_alipay_root_cert_sn"],
- PayAlipayrsaPublicKey: args["pay_alipayrsa_public_key"],
- PayAliUseType: args["pay_ali_use_type"],
- WxAppletFilepathUrl: args["wx_applet_filepath_url"],
- }
- if args["private_key"] == "" || args["app_id"] == "" {
- return "", errors.New("请在后台正确配置支付宝")
- }
- 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)
- if err != nil {
- fmt.Println("支付宝错误日志")
- fmt.Println(param)
- fmt.Println(err)
- return "", errors.New("支付宝订单创建失败")
- }
- return zhios_pay_utils.AnyToString(param), nil
- }
-
- //自有支付 微信支付
-
- // app支付v2
- func WxAppPay(params *md.WxPayParams) (map[string]string, error) {
- appId := params.PayWxAppid
- mchId := params.PayWxMchId
- apiKey := params.PayWxApiKey
- notifyUrl := params.NotifyUrl
- client := local_wxpay.NewClient(appId, mchId, apiKey, true)
- r, err := local_wxpay.TradeAppPay(client, params.Subject, params.OrdId, params.Amount, notifyUrl)
- return r, err
- }
-
- // H5支付v2
- func WxH5Pay(params *md.WxPayParams) (map[string]string, error) {
- appId := params.PayWxAppid
- mchId := params.PayWxMchId
- apiKey := params.PayWxApiKey
- notifyUrl := params.NotifyUrl
- client := local_wxpay.NewClient(appId, mchId, apiKey, true)
- r, err := local_wxpay.TradeH5Pay(client, params.Subject, params.OrdId, params.Amount, notifyUrl)
- return r, err
- }
-
- // 小程序v2
- func WxMiniProgPay(params *md.WxPayParams) (map[string]string, error) {
- appId := params.PayWxAppid
- mchId := params.PayWxMchId
- apiKey := params.PayWxApiKey
- notifyUrl := params.NotifyUrl
- client := local_wxpay.NewClient(appId, mchId, apiKey, true)
- if params.ThirdPartyWechatOpenid == "" {
- return nil, errors.New("请先授权微信")
- }
- r, err := local_wxpay.TradeMiniProgPay(client, params.Subject, params.OrdId, params.Amount, notifyUrl, params.ThirdPartyWechatOpenid)
- return r, err
- }
-
- // app支付V3
- func WxAppPayV3(params *md.WxPayParams) (map[string]string, error) {
- appId := params.PayWxAppid
- mchId := params.PayWxMchId
- notifyUrl := params.NotifyUrl
- SerialNo := params.PayWxApiKey
- ApiV3Key := params.PayWxApiKey
- PKContent := params.PayWxApiKey
- client, err := v3.NewClientV3(appId, mchId, SerialNo, ApiV3Key, PKContent)
- if err != nil {
- xlog.Error(err)
- return nil, err
- }
- client.DebugSwitch = gopay.DebugOff
- r, err := local_wxpay.TradeAppPayV3(client, params.Subject, params.OrdId, params.Amount, notifyUrl)
- return r, err
- }
-
- // 微信JSAPI支付
- func WxAppJSAPIPay(params *md.WxPayParams) (map[string]string, error) {
- appId := params.PayWxAppid
- mchId := params.PayWxMchId
- apiKey := params.PayWxApiKey
- notifyUrl := params.NotifyUrl
-
- client := local_wxpay.NewClient(appId, mchId, apiKey, true)
- if params.ThirdPartyWechatOpenid == "" {
- return nil, errors.New("请先授权微信")
- }
- r, err := local_wxpay.TradeJSAPIPay(client, params.Subject, params.OrdId, params.Amount, notifyUrl, params.ThirdPartyWechatOpenid)
- return r, err
- }
-
- // H5支付V3
- func WxH5PayV3(params *md.WxPayParams) (string, error) {
- appId := params.PayWxAppid
- mchId := params.PayWxMchId
- apiKey := params.PayWxApiKey
- notifyUrl := params.NotifyUrl
- client := local_wxpay.NewClient(appId, mchId, apiKey, false)
- _, err := local_wxpay.TradeH5Pay(client, params.Subject, params.OrdId, params.Amount, notifyUrl)
- return "", err
- }
-
- // 小程序V3
- func WxMiniProgPayV3(params *md.WxPayParams) (string, error) {
- appId := params.PayWxAppid
- mchId := params.PayWxMchId
- notifyUrl := params.NotifyUrl
- SerialNo := params.PayWxApiKey
- ApiV3Key := params.PayWxApiKey
- PKContent := params.PayWxApiKey
- client, err := v3.NewClientV3(appId, mchId, SerialNo, ApiV3Key, PKContent)
- if err != nil {
- xlog.Error(err)
- return "", err
- }
- client.DebugSwitch = gopay.DebugOff
- r, err := local_wxpay.TradeMiniProgPayV3(client, params.Subject, params.OrdId, params.Amount, notifyUrl)
- return r, err
- }
|