feat(billing): 微信支付配置进 DB —— admin 控制面保存即热生效
用户定的形态:配置存数据库、密钥文件放服务器磁盘(库里只存路径)。 env 降级为兜底(DB 优先 → env → 隐藏,与 tokens_per_credit 同一约定)。 - payment 包重构:Config(6 字段)+ Manager(RWMutex 热重载,学 prompt 控制面 改完即生效不重启);未启用原因人话化(未配置/缺哪些字段/初始化失败具体错)。 - APIv3 密钥入库前 AES-GCM 加密(shared/secrets,与模型 API Key 同一把 SUNDYNIX_SECRET_KEY);GET 只回 has_apiv3_key 不回显;PUT 留空=沿用旧密钥 (只写不回显语义,同模型 Key)。 - admin GET/PUT /admin/payment/wechat;业务路径全部改经 Manager.Current() 取快照(BillingPacks/下单/查单/回调)。 - admin 计费页「微信支付配置」卡片:状态徽章(已启用/未启用+原因)+六字段 +保存并热生效。 live:无配置→「未配置」;存假配置→热重载报「私钥加载失败:decode err」; 去掉 appid→「配置不全,缺: appid」;密钥留空沿用(has_apiv3_key 保持 true); psql 复核库内密文 enc:1: 前缀、不含明文子串。go/tsc/41 vitest 全绿。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -24,21 +24,15 @@ import (
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
db *store.Postgres
|
||||
cache *store.Redis
|
||||
bus *nats.Bus
|
||||
blob *blob.Store
|
||||
wechat *payment.Wechat // 微信支付渠道;nil=未配置(渠道隐藏)
|
||||
db *store.Postgres
|
||||
cache *store.Redis
|
||||
bus *nats.Bus
|
||||
blob *blob.Store
|
||||
pay *payment.Manager // 微信支付渠道管理器(DB 配置热重载;Current()==nil 即渠道隐藏)
|
||||
}
|
||||
|
||||
func New(db *store.Postgres, cache *store.Redis, bus *nats.Bus, blob *blob.Store) *Handler {
|
||||
return &Handler{db: db, cache: cache, bus: bus, blob: blob}
|
||||
}
|
||||
|
||||
// WithWechat 注入微信支付渠道(nil 安全:保持隐藏)。
|
||||
func (h *Handler) WithWechat(w *payment.Wechat) *Handler {
|
||||
h.wechat = w
|
||||
return h
|
||||
return &Handler{db: db, cache: cache, bus: bus, blob: blob, pay: payment.NewManager()}
|
||||
}
|
||||
|
||||
// preflight 是「会烧钱的执行」提交前的统一关卡:当日 token 预算 → 计费租户 → 积分硬拦截。
|
||||
|
||||
Reference in New Issue
Block a user