优化回调推送:参考微信/支付宝机制,限制每商户单一回调地址

- 回调重试改为微信式固定退避序列(15s/15s/30s/3m/10m/20m/30m/30m/30m/1h/3h/3h/3h/6h/6h),共 16 次尝试
- 重试次数/推送超时/退避序列可通过环境变量配置(CALLBACK_MAX_ATTEMPTS/CALLBACK_PUSH_TIMEOUT_SECONDS/CALLBACK_RETRY_SCHEDULE)
- 每个商户仅允许 1 个 active 回调订阅,创建前校验,先停用后新建
- 前端回调页提示推送策略与单地址限制
- docker-compose 透传回调相关配置
This commit is contained in:
yml2213
2026-08-03 10:57:21 +08:00
parent 7fe4a05ed7
commit cf2ee96baa
5 changed files with 131 additions and 15 deletions
+17 -1
View File
@@ -20,6 +20,18 @@ import (
"gorm.io/gorm"
)
// secondsToDurations 把秒数列表转成 time.Duration 列表(回调重试序列)。
func secondsToDurations(seconds []int) []time.Duration {
if len(seconds) == 0 {
return nil
}
out := make([]time.Duration, 0, len(seconds))
for _, s := range seconds {
out = append(out, time.Duration(s)*time.Second)
}
return out
}
func main() {
cfg := config.Load()
time.Local = timeutil.Location()
@@ -54,7 +66,11 @@ func main() {
tenantSvc := service.NewTenantService(db)
authSvc := service.NewAuthService(db, jm, tenantSvc)
userSvc := service.NewUserService(db, tenantSvc)
callbackSvc := service.NewCallbackService(db, codec)
callbackSvc := service.NewCallbackService(db, codec, service.WithCallbackConfig(service.CallbackConfig{
MaxAttempts: cfg.CallbackMaxAttempts,
PushTimeout: time.Duration(cfg.CallbackPushTimeoutSeconds) * time.Second,
RetrySchedule: secondsToDurations(cfg.CallbackRetryScheduleSeconds),
}))
fulfillmentSvc := service.NewFulfillmentService(db, callbackSvc)
merchantSvc := service.NewMerchantService(db, codec, tenantSvc)
deliverySvc := service.NewDeliveryService(