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) }