修复:优化二维码风控登录与批量发布兼容性

- 优化二维码登录风控提示,支持人脸验证二维码和验证截图。

- 修复批量发布发货地持久化,并兼容旧任务地址格式。

- 加强二维码登录和通知渠道的敏感数据保护。

- 补充登录风控使用说明。
This commit is contained in:
Christ committed 2026-08-19 22:50:03 +08:00
1 parent c1282dfa4e
commit c3020bde09
33 files changed
+855 -99

No files matched your search

+9 -9
View File
@@ -17,6 +17,13 @@ QRLoginGenerateResponse,QRLoginStatusResponse,QRLoginVerificationResponse
import { del,get,post,put,type RequestControlOptions } from '../../../shared/http/client';
import { collectionFrom,objectFrom } from '../../../shared/http/contract';
export type * from '../../../shared/api-contract/accounts';
// QRLoginStatusResult 描述账号 feature 消费的非敏感二维码状态字段。
export type QRLoginStatusResult = Pick<
QRLoginStatusResponse,
'status' | 'message' | 'session_id' | 'account_id' | 'is_new_account' | 'verification_screenshot' | 'face_qr_url'
>;
// Accounts
// addAccount 新增账号。
export const addAccount = async (id: string, value: string, loginMethod?: string): Promise<OperationResponse> => {
@@ -294,13 +301,8 @@ export const getNotificationChannels = async (options?: RequestControlOptions):
const result = await get<unknown>('/api/v1/notifications/channels', undefined, options);
// channels 通知渠道列表,用于当前 API 处理流程。
const channels = collectionFrom<NotificationChannelResponse>(result, ['data', 'channels', 'items']).map(/* 当前回调用于处理集合元素或接口响应。 */ (item: NotificationChannelResponse) => {
// parsedConfig 解析后的通知配置,用于当前 API 处理流程。
let parsedConfig;
try {
parsedConfig = typeof item.config === 'string' ? JSON.parse(item.config) : item.config;
} catch {
parsedConfig = {};
}
// parsedConfig 是列表摘要刻意不返回渠道秘密时使用的空编辑初始值。
const parsedConfig: Record<string, unknown> = {};
// normalizedType 是兼容旧渠道别名后的前端渠道类型。
const normalizedType = (item.type === 'ding_talk' ? 'dingtalk' : (item.type === 'lark' ? 'feishu' : item.type)) as NotificationChannel['type'];
return {
@@ -310,8 +312,6 @@ export const getNotificationChannels = async (options?: RequestControlOptions):
config: parsedConfig,
event_types: parseNotificationEventTypes(item.event_types),
enabled: item.enabled,
created_at: item.created_at,
updated_at: item.updated_at,
};
});
return { success: true, data: channels };
@@ -59,7 +59,7 @@ describe('useAccountQRCodeLogin 二维码登录协调器', /* 当前回调验证
expect(hook.result.current.qrStatus).toBe('waiting');
expect(hook.result.current.qrCodeUrl).toBe('qr-url');
qrLoginMocks.checkQRLoginStatus.mockResolvedValueOnce({ status: 'success', cookies: 'a=b', unb: 'user-1' });
qrLoginMocks.checkQRLoginStatus.mockResolvedValueOnce({ status: 'success' });
await act(/* pollAction 触发二维码状态轮询。 */ async () => {
await vi.advanceTimersByTimeAsync(2000);
await flushMicrotasks();
+1 -1
View File
@@ -111,7 +111,7 @@ export const useAccountQRCodeLogin = ({ onLoginSuccess }: AccountQRCodeLoginOpti
// response 保存风控验证完成接口返回值。
const response = await completeQRVerification(sessionId, target?.id);
if (!response.success || !response.account_id) {
throw new Error(response.message || '保存扫码授权失败');
throw new Error('保存扫码授权失败');
}
return response.account_id;
};
@@ -36,7 +36,7 @@ test('QR poller stops on success and terminal errors', /* 当前回调处理用
vi.useFakeTimers();
// checkStatus check状态,负责当前功能中的对应处理。
const checkStatus = vi.fn()
.mockResolvedValueOnce({ status: 'success', cookies: 'a=b', unb: 'acc1' })
.mockResolvedValueOnce({ status: 'success' })
.mockResolvedValueOnce({ status: 'expired' });
// onSuccess 响应当前用户操作(Success)。
const onSuccess = vi.fn();
@@ -53,7 +53,7 @@ test('QR poller stops on success and terminal errors', /* 当前回调处理用
await vi.advanceTimersByTimeAsync(2000);
await flushMicrotasks();
expect(onSuccess).toHaveBeenCalledWith({ status: 'success', cookies: 'a=b', unb: 'acc1' });
expect(onSuccess).toHaveBeenCalledWith({ status: 'success' });
expect(poller.isActive()).toBe(false);
await vi.advanceTimersByTimeAsync(4000);
expect(checkStatus).toHaveBeenCalledTimes(1);
@@ -76,7 +76,6 @@ test('QR poller keeps polling during verification and stops on thrown errors', /
const checkStatus = vi.fn()
.mockResolvedValueOnce({
status: 'verification_required',
verification_url: 'https://verify.example',
face_qr_url: 'https://face.example',
})
.mockRejectedValueOnce(new Error('network down'));
+1 -15
View File
@@ -1,18 +1,4 @@
// QRLoginStatusResult 描述二维码登录状态接口返回的可选字段。
export interface QRLoginStatusResult {
// status 表示当前二维码登录状态。
status?: string;
// cookies 表示登录成功后返回的凭证字符串。
cookies?: string;
// unb 表示闲鱼账号的用户标识。
unb?: string;
// verification_url 表示风控验证地址。
verification_url?: string;
// verification_screenshot 表示风控验证截图地址。
verification_screenshot?: string;
// face_qr_url 表示人脸验证二维码地址。
face_qr_url?: string;
}
import type { QRLoginStatusResult } from './api';
// QRLoginPollerTimers 描述轮询器使用的定时器依赖,便于测试替换时间源。
interface QRLoginPollerTimers {
@@ -26,8 +26,6 @@ const cardFixture: Card = {
description: '测试库存',
enabled: true,
delay_seconds: 0,
created_at: '2026-08-15T00:00:00Z',
updated_at: '2026-08-15T00:00:00Z',
};
// textCardFixture 表示用于筛选和新增测试的文本类型卡密组。
+1 -1
View File
@@ -19,7 +19,7 @@ const batchCreateMock = vi.mocked(batchCreateCards);
const getCardsMock = vi.mocked(getCards);
// cardFixture 是 data 类型卡密组的完整测试对象。
const cardFixture: Card = { id: 1, name: '库存一', type: 'data', enabled: true, data_content: 'old', created_at: '2026-01-01', updated_at: '2026-01-01' };
const cardFixture: Card = { id: 1, name: '库存一', type: 'data', enabled: true, data_content: 'old' };
// loadCardsFixture 是批量操作完成后的库存刷新替身。
const loadCardsFixture = vi.fn().mockResolvedValue(undefined);
@@ -66,8 +66,6 @@ const cardFixture: Card = {
description: '测试库存',
enabled: true,
delay_seconds: 0,
created_at: '2026-08-15T00:00:00Z',
updated_at: '2026-08-15T00:00:00Z',
};
// textCardFixture 表示卡密页面中的文本类型卡密组。
+3 -10
View File
@@ -39,18 +39,11 @@ const stringifyNotificationEventTypes = (eventTypes?: NotificationEventType[]):
/** 把后端渠道 DTO 转换为通知编辑器使用的 UI 模型。 */
const toNotificationChannel = (channel: NotificationChannelResponse): NotificationChannel => {
// config 是解析失败时降级为空对象的渠道配置。
let config: Record<string, unknown> = {};
try {
// parsed 是配置文本解析后的未知 JSON 值。
const parsed: unknown = typeof channel.config === 'string' ? JSON.parse(channel.config) : channel.config;
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) config = parsed as Record<string, unknown>;
} catch {
// 历史损坏配置不阻止用户继续编辑渠道。
}
// config 是列表摘要不返回 SMTP 等秘密时使用的空编辑初始值。
const config: Record<string, unknown> = {};
// type 是处理 ding_talk/lark 历史别名后的渠道类型。
const type = (channel.type === 'ding_talk' ? 'dingtalk' : channel.type === 'lark' ? 'feishu' : channel.type) as NotificationChannel['type'];
return { id: String(channel.id), name: channel.name, type, config, event_types: parseNotificationEventTypes(channel.event_types), enabled: channel.enabled, created_at: channel.created_at, updated_at: channel.updated_at };
return { id: String(channel.id), name: channel.name, type, config, event_types: parseNotificationEventTypes(channel.event_types), enabled: channel.enabled };
};
/** 获取全部通知渠道并转换为编辑器模型。 */
+7 -27
View File
@@ -296,10 +296,6 @@ export interface Card {
spec_name?: string;
/** 规格值。 */
spec_value?: string;
/** 卡券组创建时间。 */
created_at: string;
/** 卡券组更新时间。 */
updated_at: string;
}
// Items
@@ -328,8 +324,6 @@ export interface Item {
multi_quantity_delivery?: number | boolean;
/** 是否启用多数量发货兼容字段。 */
is_multi_qty_ship?: number | boolean;
/** 商品创建时间。 */
created_at?: string;
}
export type AutomationTriggerType = 'order_paid' | 'buyer_reviewed' | 'review_missing_timeout';
@@ -536,12 +530,6 @@ export interface SystemSettings {
export interface AIReplySettings {
/** 是否启用账号 AI 回复。 */
ai_enabled: boolean;
/** 账号使用的模型名称。 */
model_name?: string;
/** 账号 AI API 密钥。 */
api_key?: string;
/** 账号 AI 基础地址。 */
base_url?: string;
/** 最大折扣比例。 */
max_discount_percent: number;
/** 最大折扣金额。 */
@@ -1211,18 +1199,12 @@ export interface NotificationChannelResponse {
name: string;
/** 通知渠道类型。 */
type: string;
/** 通知渠道配置 JSON。 */
config: string;
/** 订阅事件类型 JSON 或兼容文本。 */
event_types?: string;
/** 订阅事件类型 JSON 或兼容文本。 */
event_types?: string;
/** 通知渠道是否启用。 */
enabled: boolean;
/** 所属用户主键。 */
user_id?: number;
/** 创建时间;旧接口可能省略。 */
created_at?: string;
/** 更新时间;旧接口可能省略。 */
updated_at?: string;
}
/** 卡券列表接口的兼容包装响应。 */
@@ -1507,11 +1489,13 @@ export interface QRLoginGenerateResponse {
export interface QRLoginStatusResponse {
/** 当前二维码会话状态。 */
status: string;
/** 风控验证页面截图地址,在人脸二维码不可用时作为展示兜底。 */
verification_screenshot?: string;
/** 闲鱼人脸风控验证二维码地址,验证页面优先展示。 */
face_qr_url?: string;
/** 扫码登录会话标识。 */
session_id?: string;
/** 平台账号标识。 */
unb?: string;
/** 持久化后的本地账号标识。 */
/** 持久化后的本地账号标识。 */
account_id?: string;
/** 是否新建了本地账号。 */
is_new_account?: boolean;
@@ -1531,10 +1515,6 @@ export interface QRLoginVerificationResponse {
account_id?: string;
/** 是否新建了本地账号。 */
is_new_account?: boolean;
/** 扫码账号与目标账号不一致时的提示标识。 */
scanned_account_id?: string;
/** 验证结果提示文本。 */
message?: string;
}
/** 订单列表刷新逐项结果。 */