|
@@ -4,163 +4,146 @@ import ( |
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/lib/local_alipay" |
|
|
"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" |
|
|
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" |
|
|
"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/pkg/errors" |
|
|
"github.com/pkg/errors" |
|
|
"github.com/syyongx/php2go" |
|
|
|
|
|
"strings" |
|
|
|
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
//自有支付 支付宝 |
|
|
|
|
|
func Alipay(req map[string]string) (interface{}, error) { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
自有支付 支付宝 |
|
|
|
|
|
req 传参 |
|
|
|
|
|
|
|
|
|
|
|
ord_id //订单号 |
|
|
|
|
|
amount //总金额 |
|
|
|
|
|
subject //描述 |
|
|
|
|
|
order_type //订单类型 |
|
|
|
|
|
notify_url //自有支付回调地址 |
|
|
|
|
|
platform //平台 由前端header传来的 |
|
|
|
|
|
pay_app_cert_sn //应用公钥证书存放路径 |
|
|
|
|
|
pay_alipay_root_cert_sn //支付宝根证书存放路径 |
|
|
|
|
|
pay_alipayrsa_public_key //支付宝公钥证书存放路径 |
|
|
|
|
|
pay_ali_use_type //支付宝选择版本 0旧版 1新版 |
|
|
|
|
|
private_key //支付宝商户私钥 数据库字段 旧版 pay_ali_private_key 新版 pay_ali_new_private_key |
|
|
|
|
|
app_id //支付宝appId 数据库字段 旧版 pay_ali_app_id 新版 pay_ali_new_app_id |
|
|
|
|
|
rsa //支付宝密钥长度 旧版使用 数据库字段 pay_ali_key_len_type |
|
|
|
|
|
pkcs //支付宝密钥格式 旧版使用 数据库字段 pay_ali_key_format_type |
|
|
|
|
|
|
|
|
|
|
|
page_url //支付宝wap支付成功跳转链接 |
|
|
|
|
|
|
|
|
|
|
|
wx_applet_filepath_url //这是服务器的路径 cfg.WxappletFilepath.URL |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
func AlipayApp(args map[string]string) (string, error) { |
|
|
var paySet = &md.PayData{ |
|
|
var paySet = &md.PayData{ |
|
|
PayAppCertSn: req["pay_app_cert_sn"], |
|
|
|
|
|
PayAlipayRootCertSn: req["pay_alipay_root_cert_sn"], |
|
|
|
|
|
PayAlipayrsaPublicKey: req["pay_alipayrsa_public_key"], |
|
|
|
|
|
PayAliUseType: req["pay_ali_use_type"], |
|
|
|
|
|
WxAppletFilepathUrl: req["wx_applet_filepath_url"], |
|
|
|
|
|
|
|
|
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 req["private_key"] == "" || req["app_id"] == "" { |
|
|
|
|
|
|
|
|
if args["private_key"] == "" || args["app_id"] == "" { |
|
|
return "", errors.New("请在后台正确配置支付宝") |
|
|
return "", errors.New("请在后台正确配置支付宝") |
|
|
} |
|
|
} |
|
|
prd := false |
|
|
|
|
|
if req["cfg_prd"] == "1" { |
|
|
|
|
|
prd = true |
|
|
|
|
|
|
|
|
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("支付宝订单创建失败") |
|
|
} |
|
|
} |
|
|
var param interface{} |
|
|
|
|
|
var err error |
|
|
|
|
|
switch req["platform"] { |
|
|
|
|
|
case md.PLATFORM_ALIPAY_APPLET: |
|
|
|
|
|
param, err = local_alipay.TradeCreate(req["app_id"], req["private_key"], req["subject"], req["ord_id"], req["amount"], req["notify_url"], req["rsa"], req["pkcs"], paySet) |
|
|
|
|
|
case md.PLATFORM_WAP: |
|
|
|
|
|
if req["pay_type"] == "self" { |
|
|
|
|
|
param, err = local_alipay.TradeCreate(req["app_id"], req["private_key"], req["subject"], req["ord_id"], req["amount"], req["notify_url"], req["rsa"], req["pkcs"], paySet) |
|
|
|
|
|
} else if req["pay_type"] == "thirdParty" { |
|
|
|
|
|
var actualPayMethod string |
|
|
|
|
|
payConfigs := map[string]string{ |
|
|
|
|
|
"ord_id": req["ord_id"], |
|
|
|
|
|
"notify_url": req["kudian_notify_url"], |
|
|
|
|
|
"subject": req["subject"], |
|
|
|
|
|
"amount": req["amount"], |
|
|
|
|
|
"pay_third_party_id": req["pay_third_party_id"], |
|
|
|
|
|
"user_id": req["user_id"], |
|
|
|
|
|
} |
|
|
|
|
|
if strings.Contains(req["browser"], "ali_pay_browser") && req["user_id"] != "" { //判断是否在支付宝内浏览器打开 |
|
|
|
|
|
actualPayMethod = "JSPAI" |
|
|
|
|
|
payConfigs["trade_type"] = actualPayMethod |
|
|
|
|
|
} else { |
|
|
|
|
|
actualPayMethod = "H5" |
|
|
|
|
|
payConfigs["trade_type"] = actualPayMethod |
|
|
|
|
|
payConfigs["wap_mame"] = "支付" |
|
|
|
|
|
payConfigs["return_url"] = "" |
|
|
|
|
|
payConfigs["wap_url"] = req["wap_url"] |
|
|
|
|
|
} |
|
|
|
|
|
payParams := &md.KuDianAliAppPayParams{} |
|
|
|
|
|
payParams, err = KuDianAlipayConfig(req, payConfigs) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
var r string |
|
|
|
|
|
|
|
|
return zhios_pay_utils.AnyToString(param), nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
r, err = AliJsApiPayByKuDian(payParams, prd) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
if actualPayMethod == "H5" { |
|
|
|
|
|
r = php2go.URLEncode(r) |
|
|
|
|
|
} |
|
|
|
|
|
usePayMethod := "third_party" |
|
|
|
|
|
return map[string]string{ |
|
|
|
|
|
"params": r, |
|
|
|
|
|
|
|
|
func AlipayWap(args map[string]string) (string, error) { |
|
|
|
|
|
|
|
|
"actual_pay_method": actualPayMethod, |
|
|
|
|
|
"use_pay_method": usePayMethod, |
|
|
|
|
|
"orderId": req["ord_id"], |
|
|
|
|
|
}, nil |
|
|
|
|
|
} |
|
|
|
|
|
case md.PLATFORM_ANDROID, md.PLATFORM_IOS: |
|
|
|
|
|
if req["pay_type"] == "self" { |
|
|
|
|
|
param, err = local_alipay.TradeAppPay(req["app_id"], req["private_key"], req["subject"], req["ord_id"], req["amount"], req["notify_url"], req["rsa"], req["pkcs"], paySet) |
|
|
|
|
|
} else if req["pay_type"] == "thirdParty" { |
|
|
|
|
|
payConfigs := map[string]string{ |
|
|
|
|
|
"ord_id": req["ord_id"], |
|
|
|
|
|
"notify_url": req["kudian_notify_url"], |
|
|
|
|
|
"subject": req["subject"], |
|
|
|
|
|
"amount": req["amount"], |
|
|
|
|
|
"pay_third_party_id": req["pay_third_party_id"], |
|
|
|
|
|
} |
|
|
|
|
|
payParams := &md.KuDianAliAppPayParams{} |
|
|
|
|
|
payParams, err = KuDianAlipayConfig(req, payConfigs) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
var r string |
|
|
|
|
|
r, err = AliAppPayByKuDian(payParams, prd) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
r = php2go.URLEncode(r) |
|
|
|
|
|
usePayMethod := "third_party" |
|
|
|
|
|
return map[string]string{ |
|
|
|
|
|
"params": r, |
|
|
|
|
|
"use_pay_method": usePayMethod, |
|
|
|
|
|
"orderId": req["ord_id"], |
|
|
|
|
|
}, nil |
|
|
|
|
|
} |
|
|
|
|
|
default: |
|
|
|
|
|
return "", errors.New("渠道不存在") |
|
|
|
|
|
|
|
|
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 { |
|
|
if err != nil { |
|
|
return "", err |
|
|
|
|
|
|
|
|
fmt.Println("支付宝错误日志") |
|
|
|
|
|
fmt.Println(param) |
|
|
|
|
|
fmt.Println(err) |
|
|
|
|
|
return "", errors.New("支付宝订单创建失败") |
|
|
} |
|
|
} |
|
|
return param, nil |
|
|
|
|
|
|
|
|
return zhios_pay_utils.AnyToString(param), nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//自有支付 微信支付 |
|
|
|
|
|
func WxPay(params map[string]string) (interface{}, error) { |
|
|
|
|
|
var r interface{} |
|
|
|
|
|
var err error |
|
|
|
|
|
prd := false |
|
|
|
|
|
if params["cfg_prd"] == "1" { |
|
|
|
|
|
prd = true |
|
|
|
|
|
|
|
|
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"], |
|
|
} |
|
|
} |
|
|
client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true) |
|
|
|
|
|
switch params["platform"] { |
|
|
|
|
|
case md.PLATFORM_WX_APPLET: |
|
|
|
|
|
if params["pay_type"] == "self" { //自有支付 |
|
|
|
|
|
r, err = local_wxpay.TradeMiniProgPay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"], params["third_party_wechat_openid"]) |
|
|
|
|
|
} else if params["pay_type"] == "thirdParty" { |
|
|
|
|
|
payConfigs := map[string]string{ |
|
|
|
|
|
"ord_id": params["ord_id"], |
|
|
|
|
|
"notify_url": params["ku_dian_notify_url"], |
|
|
|
|
|
"subject": params["subject"], |
|
|
|
|
|
"amount": params["amount"], |
|
|
|
|
|
"pay_third_party_id": params["pay_third_party_id"], |
|
|
|
|
|
} |
|
|
|
|
|
payParams := &md.KuDianWxPayParams{} |
|
|
|
|
|
payParams, err = KuDianWxConfig(params, payConfigs) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
r, err = WxAppletPayByKuDian(payParams, prd) |
|
|
|
|
|
r = map[string]interface{}{ |
|
|
|
|
|
"params": r, |
|
|
|
|
|
"orderId": params["ord_id"], |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
case md.PLATFORM_WAP: |
|
|
|
|
|
if strings.Contains(params["browser"], "wx_pay_browser") { |
|
|
|
|
|
r, err = local_wxpay.TradeJSAPIPay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"], params["third_party_wechat_openid"]) |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
r, err = local_wxpay.TradeH5Pay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"]) |
|
|
|
|
|
} |
|
|
|
|
|
case md.PLATFORM_ANDROID, md.PLATFORM_IOS, md.PLATFORM_JSAPI: |
|
|
|
|
|
r, err = local_wxpay.TradeAppPay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"]) |
|
|
|
|
|
default: |
|
|
|
|
|
return nil, errors.New("渠道不存在") |
|
|
|
|
|
|
|
|
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 { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
|
|
|
|
|
|
fmt.Println("支付宝错误日志") |
|
|
|
|
|
fmt.Println(param) |
|
|
|
|
|
fmt.Println(err) |
|
|
|
|
|
return "", errors.New("支付宝订单创建失败") |
|
|
} |
|
|
} |
|
|
return r, nil |
|
|
|
|
|
|
|
|
return zhios_pay_utils.AnyToString(param), nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 微信app支付v2 |
|
|
|
|
|
func WxAppPay(params map[string]string) (map[string]string, error) { |
|
|
|
|
|
appId := params["pay_wx_appid"] |
|
|
|
|
|
mchId := params["pay_wx_mch_id"] |
|
|
|
|
|
apiKey := params["pay_wx_api_key"] |
|
|
|
|
|
notifyUrl := params["notify_url"] |
|
|
|
|
|
client := local_wxpay.NewClient(appId, mchId, apiKey, true) |
|
|
|
|
|
r, err := local_wxpay.TradeAppPay(client, params["subject"], params["ord_id"], params["amount"], notifyUrl) |
|
|
|
|
|
return r, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 微信H5支付v2 |
|
|
|
|
|
func WxH5Pay(params map[string]string) (map[string]string, error) { |
|
|
|
|
|
appId := params["pay_wx_appid"] |
|
|
|
|
|
mchId := params["pay_wx_mch_id"] |
|
|
|
|
|
apiKey := params["pay_wx_api_key"] |
|
|
|
|
|
notifyUrl := params["notify_url"] |
|
|
|
|
|
client := local_wxpay.NewClient(appId, mchId, apiKey, true) |
|
|
|
|
|
r, err := local_wxpay.TradeH5Pay(client, params["subject"], params["ord_id"], params["amount"], notifyUrl) |
|
|
|
|
|
return r, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 微信小程序v2 |
|
|
|
|
|
func WxMiniProgPay(params map[string]string) (map[string]string, error) { |
|
|
|
|
|
appId := params["pay_wx_appid"] |
|
|
|
|
|
mchId := params["pay_wx_mch_id"] |
|
|
|
|
|
apiKey := params["pay_wx_api_key"] |
|
|
|
|
|
notifyUrl := params["notify_url"] |
|
|
|
|
|
client := local_wxpay.NewClient(appId, mchId, apiKey, true) |
|
|
|
|
|
if params["third_party_wechat_openid"] == "" { |
|
|
|
|
|
return nil, errors.New("请先授权微信") |
|
|
|
|
|
} |
|
|
|
|
|
r, err := local_wxpay.TradeMiniProgPay(client, params["subject"], params["ord_id"], params["amount"], notifyUrl, params["third_party_wechat_openid"]) |
|
|
|
|
|
return r, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 微信JSAPI支付 |
|
|
|
|
|
func WxAppJSAPIPay(params map[string]string) (map[string]string, error) { |
|
|
|
|
|
appId := params["pay_wx_appid"] |
|
|
|
|
|
mchId := params["pay_wx_mch_id"] |
|
|
|
|
|
apiKey := params["pay_wx_api_key"] |
|
|
|
|
|
notifyUrl := params["notify_url"] |
|
|
|
|
|
|
|
|
|
|
|
client := local_wxpay.NewClient(appId, mchId, apiKey, true) |
|
|
|
|
|
if params["third_party_wechat_openid"] == "" { |
|
|
|
|
|
return nil, errors.New("请先授权微信") |
|
|
|
|
|
} |
|
|
|
|
|
r, err := local_wxpay.TradeJSAPIPay(client, params["subject"], params["ord_id"], params["amount"], notifyUrl, params["third_party_wechat_openid"]) |
|
|
|
|
|
return r, err |
|
|
} |
|
|
} |