diff --git a/lib/local_alipay/api.go b/lib/local_alipay/api.go index ad353bd..2723e41 100644 --- a/lib/local_alipay/api.go +++ b/lib/local_alipay/api.go @@ -43,34 +43,10 @@ func TradeAppPay(appID, priKey, subject, orderID, amount, notiURL, RSA, PKCS str } //新支付宝支付 if paySet.PayAliUseType == "1" { - appCertSN, err := alipay.GetCertSN(paySet.WxAppletFilepathUrl + "/" + paySet.PayAppCertSn) - fmt.Println("-应用-") - fmt.Println(appCertSN) - if err != nil { - fmt.Println(err) - return "", err - } - if appCertSN == "" { - fmt.Println(err) - return "", err - } - client.SetAppCertSN(appCertSN) - //aliPayRootCertSN, err := local_alipay.GetCertSN(cfg.WxappletFilepath.URL + "/" + paySet.PayAlipayRootCertSn) + client.SetAppCertSN(paySet.PayAppCertSn) aliPayRootCertSN := "687b59193f3f462dd5336e5abf83c5d8_02941eef3187dddf3d3b83462e1dfcf6" client.SetAliPayRootCertSN(aliPayRootCertSN) - aliPayPublicCertSN, err := alipay.GetCertSN(paySet.WxAppletFilepathUrl + "/" + paySet.PayAlipayrsaPublicKey) - fmt.Println("-公钥-") - fmt.Println(aliPayPublicCertSN) - - if err != nil { - fmt.Println(err) - return "", err - } - if aliPayPublicCertSN == "" { - fmt.Println(err) - return "", err - } - client.SetAliPayPublicCertSN(aliPayPublicCertSN) + client.SetAliPayPublicCertSN(paySet.PayAlipayrsaPublicKey) } fmt.Println(client) //请求参数 @@ -120,37 +96,10 @@ func TradeWapPay(appID, priKey, subject, orderID, amount, notiURL, RSA, PKCS, pa SetNotifyUrl(notiURL) //新支付宝支付 if paySet.PayAliUseType == "1" { - appCertSN, err := alipay.GetCertSN(paySet.WxAppletFilepathUrl + "/" + paySet.PayAppCertSn) - if err != nil { - fmt.Println(err) - return "", err - } - if appCertSN == "" { - fmt.Println(err) - return "", err - } - client.SetAppCertSN(appCertSN) - //aliPayRootCertSN, err := local_alipay.GetCertSN(paySet.WxAppletFilepathUrl + "/" + paySet.PayAlipayRootCertSn) - //if err != nil { - // fmt.Println(err) - // return "", err - //} - //if aliPayRootCertSN == "" { - // fmt.Println(err) - // return "", err - //} + client.SetAppCertSN(paySet.PayAppCertSn) aliPayRootCertSN := "687b59193f3f462dd5336e5abf83c5d8_02941eef3187dddf3d3b83462e1dfcf6" client.SetAliPayRootCertSN(aliPayRootCertSN) - aliPayPublicCertSN, err := alipay.GetCertSN(paySet.WxAppletFilepathUrl + "/" + paySet.PayAlipayrsaPublicKey) - if err != nil { - fmt.Println(err) - return "", err - } - if aliPayPublicCertSN == "" { - fmt.Println(err) - return "", err - } - client.SetAliPayPublicCertSN(aliPayPublicCertSN) + client.SetAliPayPublicCertSN(paySet.PayAlipayrsaPublicKey) } //请求参数 body := make(gopay.BodyMap) @@ -197,37 +146,10 @@ func TradeCreate(appID, priKey, subject, orderID, amount, notiURL, RSA, PKCS str SetPrivateKeyType(pkcs_type). SetNotifyUrl(notiURL) if paySet.PayAliUseType == "1" { - appCertSN, err := alipay.GetCertSN(paySet.WxAppletFilepathUrl + "/" + paySet.PayAppCertSn) - if err != nil { - fmt.Println(err) - return nil, err - } - if appCertSN == "" { - fmt.Println(err) - return nil, err - } - client.SetAppCertSN(appCertSN) - //aliPayRootCertSN, err := local_alipay.GetCertSN(paySet.WxAppletFilepathUrl + "/" + paySet.PayAlipayRootCertSn) - //if err != nil { - // fmt.Println(err) - // return nil, err - //} - //if aliPayRootCertSN == "" { - // fmt.Println(err) - // return nil, err - //} + client.SetAppCertSN(paySet.PayAppCertSn) aliPayRootCertSN := "687b59193f3f462dd5336e5abf83c5d8_02941eef3187dddf3d3b83462e1dfcf6" client.SetAliPayRootCertSN(aliPayRootCertSN) - aliPayPublicCertSN, err := alipay.GetCertSN(paySet.WxAppletFilepathUrl + "/" + paySet.PayAlipayrsaPublicKey) - if err != nil { - fmt.Println(err) - return nil, err - } - if aliPayPublicCertSN == "" { - fmt.Println(err) - return nil, err - } - client.SetAliPayPublicCertSN(aliPayPublicCertSN) + client.SetAliPayPublicCertSN(paySet.PayAlipayrsaPublicKey) } //请求参数 body := make(gopay.BodyMap) diff --git a/pay/pay_by_own.go b/pay/pay_by_own.go index 39cf97b..7f6b174 100644 --- a/pay/pay_by_own.go +++ b/pay/pay_by_own.go @@ -19,28 +19,26 @@ subject //描述 order_type //订单类型 notify_url //自有支付回调地址 platform //平台 由前端header传来的 -pay_app_cert_sn //应用公钥证书存放路径 -pay_alipay_root_cert_sn //支付宝根证书存放路径 -pay_alipayrsa_public_key //支付宝公钥证书存放路径 +pay_app_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) { +func AlipayCofing(args map[string]string) *md.PayData { 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"], } + return paySet +} +func AlipayApp(args map[string]string) (string, error) { + paySet := AlipayCofing(args) if args["private_key"] == "" || args["app_id"] == "" { return "", errors.New("请在后台正确配置支付宝") } @@ -55,14 +53,7 @@ func AlipayApp(args map[string]string) (string, error) { } 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"], - } + paySet := AlipayCofing(args) if args["private_key"] == "" || args["app_id"] == "" { return "", errors.New("请在后台正确配置支付宝") } @@ -77,13 +68,7 @@ func AlipayWap(args map[string]string) (string, error) { } 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"], - } + paySet := AlipayCofing(args) if args["private_key"] == "" || args["app_id"] == "" { return "", errors.New("请在后台正确配置支付宝") } @@ -99,51 +84,34 @@ func AlipayApplet(args map[string]string) (string, error) { // 微信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) + client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true) + r, err := local_wxpay.TradeAppPay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"]) 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) + client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true) + r, err := local_wxpay.TradeH5Pay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"]) 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) + client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], 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"]) + r, err := local_wxpay.TradeMiniProgPay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"], 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) + client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], 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"]) + r, err := local_wxpay.TradeJSAPIPay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"], params["third_party_wechat_openid"]) return r, err }