From c19b7db8c0bc9dfb4c40cf5ec8c99b37fb9738f5 Mon Sep 17 00:00:00 2001 From: GeekMaster Date: Fri, 25 Jul 2025 19:15:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=94=AF=E4=BB=98=E5=AE=9D?= =?UTF-8?q?=E5=92=8C=E5=BE=AE=E4=BF=A1=E6=94=AF=E4=BB=98=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=8F=82=E6=95=B0=EF=BC=9A=201.=20=E5=88=A0=E5=87=8F=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E5=AE=9D=E5=8F=82=E6=95=B0=EF=BC=8C=E5=8F=AA=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E4=BC=A0=E5=85=A5=E5=BA=94=E7=94=A8=E7=A7=81=E9=92=A5?= =?UTF-8?q?=E5=92=8C=E6=94=AF=E4=BB=98=E5=AE=9D=E5=85=AC=E9=92=A5=E3=80=82?= =?UTF-8?q?=202.=20=E6=89=80=E6=9C=89=E7=9A=84=E7=A7=98=E9=92=A5=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E5=86=99=E5=85=A5=E9=85=8D=E7=BD=AE=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E4=BC=A0=E5=85=A5=EF=BC=8C=E8=80=8C=E4=B8=8D=E6=98=AF=E4=BC=A0?= =?UTF-8?q?=E5=85=A5=E7=A7=98=E9=92=A5=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=EF=BC=8C=E7=AE=80=E5=8C=96=E5=8F=82=E6=95=B0=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/core/types/config.go | 9 +++------ api/service/payment/alipay_service.go | 20 ++++---------------- api/service/payment/wepay_service.go | 11 ++++------- 3 files changed, 11 insertions(+), 29 deletions(-) diff --git a/api/core/types/config.go b/api/core/types/config.go index 9fbcc73d..ccff3678 100644 --- a/api/core/types/config.go +++ b/api/core/types/config.go @@ -53,11 +53,8 @@ type AlipayConfig struct { Enabled bool // 是否启用该支付通道 SandBox bool // 是否沙盒环境 AppId string // 应用 ID - UserId string // 支付宝用户 ID - PrivateKey string // 用户私钥文件路径 - PublicKey string // 用户公钥文件路径 - AlipayPublicKey string // 支付宝公钥文件路径 - RootCert string // Root 秘钥路径 + PrivateKey string // 商户私钥 + AlipayPublicKey string // 支付宝公钥 NotifyURL string // 异步通知地址 ReturnURL string // 同步通知地址 } @@ -67,7 +64,7 @@ type WechatPayConfig struct { AppId string // 公众号的APPID,如:wxd678efh567hg6787 MchId string // 直连商户的商户号,由微信支付生成并下发 SerialNo string // 商户证书的证书序列号 - PrivateKey string // 用户私钥文件路径 + PrivateKey string // 商户私钥 ApiV3Key string // API V3 秘钥 NotifyURL string // 异步通知地址 } diff --git a/api/service/payment/alipay_service.go b/api/service/payment/alipay_service.go index 09290df8..b2c10e8c 100644 --- a/api/service/payment/alipay_service.go +++ b/api/service/payment/alipay_service.go @@ -12,10 +12,11 @@ import ( "fmt" "geekai/core/types" logger2 "geekai/logger" - "github.com/go-pay/gopay" - "github.com/go-pay/gopay/alipay" "net/http" "os" + + "github.com/go-pay/gopay" + "github.com/go-pay/gopay/alipay" ) type AlipayService struct { @@ -31,25 +32,12 @@ func NewAlipayService(appConfig *types.AppConfig) (*AlipayService, error) { logger.Info("Disabled Alipay service") return nil, nil } - priKey, err := readKey(config.PrivateKey) - if err != nil { - return nil, fmt.Errorf("error with read App Private key: %v", err) - } - client, err := alipay.NewClient(config.AppId, priKey, !config.SandBox) + client, err := alipay.NewClient(config.AppId, config.PrivateKey, !config.SandBox) if err != nil { return nil, fmt.Errorf("error with initialize alipay service: %v", err) } - //client.DebugSwitch = gopay.DebugOn // 开启调试模式 - client.SetLocation(alipay.LocationShanghai). // 设置时区,不设置或出错均为默认服务器时间 - SetCharset(alipay.UTF8). // 设置字符编码,不设置默认 utf-8 - SetSignType(alipay.RSA2) // 设置签名类型,不设置默认 RSA2 - - if err = client.SetCertSnByPath(config.PublicKey, config.RootCert, config.AlipayPublicKey); err != nil { - return nil, fmt.Errorf("error with load payment public key: %v", err) - } - return &AlipayService{config: &config, client: client}, nil } diff --git a/api/service/payment/wepay_service.go b/api/service/payment/wepay_service.go index 2e2ddb44..7137718a 100644 --- a/api/service/payment/wepay_service.go +++ b/api/service/payment/wepay_service.go @@ -11,10 +11,11 @@ import ( "context" "fmt" "geekai/core/types" - "github.com/go-pay/gopay" - "github.com/go-pay/gopay/wechat/v3" "net/http" "time" + + "github.com/go-pay/gopay" + "github.com/go-pay/gopay/wechat/v3" ) type WechatPayService struct { @@ -28,12 +29,8 @@ func NewWechatService(appConfig *types.AppConfig) (*WechatPayService, error) { logger.Info("Disabled WechatPay service") return nil, nil } - priKey, err := readKey(config.PrivateKey) - if err != nil { - return nil, fmt.Errorf("error with read App Private key: %v", err) - } - client, err := wechat.NewClientV3(config.MchId, config.SerialNo, config.ApiV3Key, priKey) + client, err := wechat.NewClientV3(config.MchId, config.SerialNo, config.ApiV3Key, config.PrivateKey) if err != nil { return nil, fmt.Errorf("error with initialize WechatPay service: %v", err) }