refactor: 清理 YAML 支付配置遗留代码,重命名 Card* 常量为 Asset*,新增支付配置相关错误码
- 删除 PaymentConfig 结构体和 WechatConfig.Payment 字段(YAML 方案已废弃) - 删除 wechat.payment 配置节和 NewPaymentApp() 函数 - 删除 validateWechatConfig 中所有 wechatCfg.Payment.* 校验代码 - pkg/constants/wallet.go: Card* 前缀统一重命名为 Asset*,旧名保留废弃别名 - pkg/constants/redis.go: 新增 RedisWechatConfigActiveKey() - pkg/errors/codes.go: 新增错误码 1170-1175 - go.mod: 新增 golang.org/x/text 依赖(富友支付 GBK 编解码) Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -359,60 +359,16 @@ func initGateway(cfg *config.Config, appLogger *zap.Logger) *gateway.Client {
|
||||
func validateWechatConfig(cfg *config.Config, appLogger *zap.Logger) {
|
||||
wechatCfg := cfg.Wechat
|
||||
|
||||
if wechatCfg.OfficialAccount.AppID == "" && wechatCfg.Payment.AppID == "" {
|
||||
appLogger.Warn("微信配置未设置,微信相关功能将不可用")
|
||||
if wechatCfg.OfficialAccount.AppID == "" {
|
||||
appLogger.Warn("微信公众号配置未设置,OAuth 相关功能将不可用")
|
||||
return
|
||||
}
|
||||
|
||||
if wechatCfg.OfficialAccount.AppID != "" {
|
||||
if wechatCfg.OfficialAccount.AppSecret == "" {
|
||||
appLogger.Fatal("微信公众号配置不完整",
|
||||
zap.String("missing", "app_secret"),
|
||||
zap.String("env", "JUNHONG_WECHAT_OFFICIAL_ACCOUNT_APP_SECRET"))
|
||||
}
|
||||
appLogger.Info("微信公众号配置已验证",
|
||||
zap.String("app_id", wechatCfg.OfficialAccount.AppID))
|
||||
}
|
||||
|
||||
if wechatCfg.Payment.AppID != "" {
|
||||
missingFields := []string{}
|
||||
|
||||
if wechatCfg.Payment.MchID == "" {
|
||||
missingFields = append(missingFields, "mch_id (JUNHONG_WECHAT_PAYMENT_MCH_ID)")
|
||||
}
|
||||
if wechatCfg.Payment.APIV3Key == "" {
|
||||
missingFields = append(missingFields, "api_v3_key (JUNHONG_WECHAT_PAYMENT_API_V3_KEY)")
|
||||
}
|
||||
if wechatCfg.Payment.CertPath == "" {
|
||||
missingFields = append(missingFields, "cert_path (JUNHONG_WECHAT_PAYMENT_CERT_PATH)")
|
||||
}
|
||||
if wechatCfg.Payment.KeyPath == "" {
|
||||
missingFields = append(missingFields, "key_path (JUNHONG_WECHAT_PAYMENT_KEY_PATH)")
|
||||
}
|
||||
if wechatCfg.Payment.SerialNo == "" {
|
||||
missingFields = append(missingFields, "serial_no (JUNHONG_WECHAT_PAYMENT_SERIAL_NO)")
|
||||
}
|
||||
if wechatCfg.Payment.NotifyURL == "" {
|
||||
missingFields = append(missingFields, "notify_url (JUNHONG_WECHAT_PAYMENT_NOTIFY_URL)")
|
||||
}
|
||||
|
||||
if len(missingFields) > 0 {
|
||||
appLogger.Fatal("微信支付配置不完整",
|
||||
zap.Strings("missing_fields", missingFields))
|
||||
}
|
||||
|
||||
if _, err := os.Stat(wechatCfg.Payment.CertPath); os.IsNotExist(err) {
|
||||
appLogger.Fatal("微信支付证书文件不存在",
|
||||
zap.String("cert_path", wechatCfg.Payment.CertPath))
|
||||
}
|
||||
|
||||
if _, err := os.Stat(wechatCfg.Payment.KeyPath); os.IsNotExist(err) {
|
||||
appLogger.Fatal("微信支付私钥文件不存在",
|
||||
zap.String("key_path", wechatCfg.Payment.KeyPath))
|
||||
}
|
||||
|
||||
appLogger.Info("微信支付配置已验证",
|
||||
zap.String("app_id", wechatCfg.Payment.AppID),
|
||||
zap.String("mch_id", wechatCfg.Payment.MchID))
|
||||
if wechatCfg.OfficialAccount.AppSecret == "" {
|
||||
appLogger.Fatal("微信公众号配置不完整",
|
||||
zap.String("missing", "app_secret"),
|
||||
zap.String("env", "JUNHONG_WECHAT_OFFICIAL_ACCOUNT_APP_SECRET"))
|
||||
}
|
||||
appLogger.Info("微信公众号配置已验证",
|
||||
zap.String("app_id", wechatCfg.OfficialAccount.AppID))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user