错误提示有问题
This commit is contained in:
@@ -1,35 +1,37 @@
|
||||
package alipay
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/smartwalle/alipay/v3"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
apperrors "github.com/break/junhong_cmp_fiber/pkg/errors"
|
||||
)
|
||||
|
||||
// NewClientFromConfig 从 WechatConfig 构建支付宝 SDK client。
|
||||
// 校验 ali_app_id、ali_private_key、ali_public_key 必须非空。
|
||||
// ali_production=true 时使用生产环境,否则使用沙箱环境。
|
||||
func NewClientFromConfig(cfg *model.WechatConfig) (*alipay.Client, error) {
|
||||
if cfg == nil {
|
||||
return nil, apperrors.New(apperrors.CodeNoPaymentConfig, "支付宝配置缺失:未找到启用的支付配置")
|
||||
}
|
||||
if cfg.AliAppID == "" {
|
||||
return nil, fmt.Errorf("支付宝配置缺失:ali_app_id 不能为空")
|
||||
return nil, apperrors.New(apperrors.CodeNoPaymentConfig, "支付宝配置缺失:ali_app_id 不能为空")
|
||||
}
|
||||
if cfg.AliPrivateKey == "" {
|
||||
return nil, fmt.Errorf("支付宝配置缺失:ali_private_key 不能为空")
|
||||
return nil, apperrors.New(apperrors.CodeNoPaymentConfig, "支付宝配置缺失:ali_private_key 不能为空")
|
||||
}
|
||||
if cfg.AliPublicKey == "" {
|
||||
return nil, fmt.Errorf("支付宝配置缺失:ali_public_key 不能为空")
|
||||
return nil, apperrors.New(apperrors.CodeNoPaymentConfig, "支付宝配置缺失:ali_public_key 不能为空")
|
||||
}
|
||||
|
||||
client, err := alipay.New(cfg.AliAppID, cfg.AliPrivateKey, cfg.AliProduction)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("创建支付宝客户端失败: %w", err)
|
||||
return nil, apperrors.Wrap(apperrors.CodeNoPaymentConfig, err, "支付宝配置不可用:创建客户端失败")
|
||||
}
|
||||
|
||||
// 加载支付宝公钥(公钥模式验签)
|
||||
if err := client.LoadAliPayPublicKey(cfg.AliPublicKey); err != nil {
|
||||
return nil, fmt.Errorf("加载支付宝公钥失败: %w", err)
|
||||
return nil, apperrors.Wrap(apperrors.CodeNoPaymentConfig, err, "支付宝配置不可用:加载公钥失败")
|
||||
}
|
||||
|
||||
return client, nil
|
||||
|
||||
Reference in New Issue
Block a user