From cae439d4da55b9c4574d58382e912b47d8d3956d Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Wed, 17 May 2023 15:08:21 +0800 Subject: [PATCH] test --- lib/local_alipay/api.go | 54 +++++++++++++++++++++++++++++++++++++++++ pay/pay_by_own.go | 15 +++++++++++- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/lib/local_alipay/api.go b/lib/local_alipay/api.go index 2723e41..c2d56c0 100644 --- a/lib/local_alipay/api.go +++ b/lib/local_alipay/api.go @@ -65,6 +65,60 @@ func TradeAppPay(appID, priKey, subject, orderID, amount, notiURL, RSA, PKCS str } return payParam, nil } +func TradeAppPc(appID, priKey, subject, orderID, amount, notiURL, RSA, PKCS string, paySet *md.PayData) (string, error) { + //初始化支付宝客户端 + // appID 是在支付宝申请的APPID + // priKey 是支付宝私钥 + // subject 是支付订单的主题 + // orderID 是智莺这边生成的订单id + // amount 是付费金额 + // notiURL 通知地址url + // passback_params 回调通知参数 + + client := alipay.NewClient(appID, priKey, true) + client.DebugSwitch = gopay.DebugOn + //判断密钥的类型 + rsa_type := alipay.RSA2 + pkcs_type := alipay.PKCS1 + if RSA == "1" { + rsa_type = alipay.RSA + } + if PKCS == "1" { + pkcs_type = alipay.PKCS8 + } + if paySet.PayAliUseType == "1" { + rsa_type = alipay.RSA2 + pkcs_type = alipay.PKCS8 + } + //配置公共参数 + client.SetCharset("utf-8"). + SetSignType(rsa_type). + SetPrivateKeyType(pkcs_type) + if notiURL != "" { + client.SetNotifyUrl(notiURL) + } + //新支付宝支付 + if paySet.PayAliUseType == "1" { + client.SetAppCertSN(paySet.PayAppCertSn) + aliPayRootCertSN := "687b59193f3f462dd5336e5abf83c5d8_02941eef3187dddf3d3b83462e1dfcf6" + client.SetAliPayRootCertSN(aliPayRootCertSN) + client.SetAliPayPublicCertSN(paySet.PayAlipayrsaPublicKey) + } + fmt.Println(client) + //请求参数 + body := make(gopay.BodyMap) + body.Set("subject", subject) + body.Set("out_trade_no", orderID) + body.Set("total_amount", amount) + body.Set("timeout_express", "30m") + body.Set("product_code", "FAST_INSTANT_TRADE_PAY") + // body.Set("passback_params", orderID) + payParam, err := client.TradePagePay(body) + if err != nil { + return "", err + } + return payParam, nil +} // TradeAppPay is 支付宝H5支付 func TradeWapPay(appID, priKey, subject, orderID, amount, notiURL, RSA, PKCS, page_url string, paySet *md.PayData) (string, error) { diff --git a/pay/pay_by_own.go b/pay/pay_by_own.go index 7f6b174..7e9af1b 100644 --- a/pay/pay_by_own.go +++ b/pay/pay_by_own.go @@ -51,7 +51,20 @@ func AlipayApp(args map[string]string) (string, error) { } return zhios_pay_utils.AnyToString(param), nil } - +func AlipayPc(args map[string]string) (string, error) { + paySet := AlipayCofing(args) + if args["private_key"] == "" || args["app_id"] == "" { + return "", errors.New("请在后台正确配置支付宝") + } + param, err := local_alipay.TradeAppPc(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) { paySet := AlipayCofing(args) if args["private_key"] == "" || args["app_id"] == "" {