feat: 对齐闲鱼续期流程并完善业务管理

对齐官方 WebSocket 批量握手、注册、心跳、ACK、同步恢复及运行时设备标识生命周期。

保留 Cookie 完整属性,接入静默续期和保存登录信息设置,并在凭证更新后重建账号连接。

完善订单与商品同步、卡券和通知渠道交互,更新前端品牌、时间展示及嵌入资源。

补充 Go 与前端回归测试,确保完整检查和生产构建通过。
This commit is contained in:
Christ committed 2026-07-22 12:51:52 +08:00
1 parent 3cc1d4094d
commit d77c317452
69 files changed
+3169 -819

No files matched your search

+30 -9
View File
@@ -597,15 +597,15 @@ func (n *Notifier) sendTelegram(cfg map[string]any, message string) error {
func (n *Notifier) sendEmail(cfg map[string]any, message string) error {
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
server := n.configOrSetting(ctx, cfg, "smtp_server", "")
port := n.configOrSetting(ctx, cfg, "smtp_port", "587")
user := n.configOrSetting(ctx, cfg, "smtp_user", "")
pass := n.configOrSetting(ctx, cfg, "smtp_password", "")
useTLS := parseConfigBool(n.configOrSetting(ctx, cfg, "smtp_use_tls", "true"), true)
useSSL := parseConfigBool(n.configOrSetting(ctx, cfg, "smtp_use_ssl", "false"), false)
fromAddress := n.configOrSetting(ctx, cfg, "smtp_from_address", "")
fromName := n.configOrSetting(ctx, cfg, "smtp_from_name", "")
legacyFrom := n.configOrSetting(ctx, cfg, "smtp_from", "")
server := n.smtpConfigValue(ctx, cfg, "smtp_server", "")
port := n.smtpConfigValue(ctx, cfg, "smtp_port", "587")
user := n.smtpConfigValue(ctx, cfg, "smtp_user", "")
pass := n.smtpConfigValue(ctx, cfg, "smtp_password", "")
useTLS := parseConfigBool(n.smtpConfigValue(ctx, cfg, "smtp_use_tls", "true"), true)
useSSL := parseConfigBool(n.smtpConfigValue(ctx, cfg, "smtp_use_ssl", "false"), false)
fromAddress := n.smtpConfigValue(ctx, cfg, "smtp_from_address", "")
fromName := n.smtpConfigValue(ctx, cfg, "smtp_from_name", "")
legacyFrom := n.smtpConfigValue(ctx, cfg, "smtp_from", "")
to := strOr(cfg, "to_email", strOr(cfg, "email", ""))
if server == "" || user == "" || to == "" {
return fmt.Errorf("邮件配置不完整:请配置系统 SMTP 或在邮件渠道中覆盖 SMTP,并填写收件邮箱")
@@ -751,6 +751,27 @@ func (n *Notifier) configOrSetting(ctx context.Context, cfg map[string]any, key,
return fallbackValue
}
// smtpConfigValue keeps legacy per-field fallback behavior for existing rows,
// while new rows use an explicit all-system or all-channel SMTP mode.
func (n *Notifier) smtpConfigValue(ctx context.Context, cfg map[string]any, key, fallbackValue string) string {
modeValue, hasExplicitMode := cfg["use_custom_smtp"]
if !hasExplicitMode {
return n.configOrSetting(ctx, cfg, key, fallbackValue)
}
if parseConfigBool(fmt.Sprintf("%v", modeValue), false) {
if value := strings.TrimSpace(strOr(cfg, key, "")); value != "" {
return value
}
return fallbackValue
}
if n.store != nil && n.store.Settings != nil {
if value, err := n.store.Settings.Get(ctx, key); err == nil && strings.TrimSpace(value) != "" {
return strings.TrimSpace(value)
}
}
return fallbackValue
}
// postJSON 通用 JSON POST。
func (n *Notifier) postJSON(url string, payload any) error {
body, err := json.Marshal(payload)
+27
View File
@@ -568,6 +568,33 @@ func TestSendEmail_UsesSystemSMTPFallback(t *testing.T) {
}
}
func TestSMTPConfigValueUsesExclusiveExplicitModes(t *testing.T) {
store, cleanup := newNotifyStoreBare(t)
defer cleanup()
ctx := context.Background()
if err := store.Settings.Set(ctx, "smtp_server", "system.example.com"); err != nil {
t.Fatal(err)
}
n := New("cid", store, nil)
if got := n.smtpConfigValue(ctx, map[string]any{
"use_custom_smtp": false,
"smtp_server": "stale-channel.example.com",
}, "smtp_server", ""); got != "system.example.com" {
t.Fatalf("system mode mixed in channel override: %q", got)
}
if got := n.smtpConfigValue(ctx, map[string]any{
"use_custom_smtp": true,
}, "smtp_server", ""); got != "" {
t.Fatalf("custom mode inherited system value: %q", got)
}
if got := n.smtpConfigValue(ctx, map[string]any{
"smtp_server": "legacy-channel.example.com",
}, "smtp_server", ""); got != "legacy-channel.example.com" {
t.Fatalf("legacy channel override compatibility lost: %q", got)
}
}
// TestSendEmail_IncompleteConfig 配置不完整应报错。
func TestSendEmail_IncompleteConfig(t *testing.T) {
n := New("cid", nil, nil)