修复:优化二维码风控登录与批量发布兼容性
- 优化二维码登录风控提示,支持人脸验证二维码和验证截图。 - 修复批量发布发货地持久化,并兼容旧任务地址格式。 - 加强二维码登录和通知渠道的敏感数据保护。 - 补充登录风控使用说明。
This commit is contained in:
1 parent
c1282dfa4e
commit
c3020bde09
33 files changed
+855
-99
No files matched your search
@@ -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();
|
||||
|
||||
@@ -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,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 表示用于筛选和新增测试的文本类型卡密组。
|
||||
|
||||
@@ -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 表示卡密页面中的文本类型卡密组。
|
||||
|
||||
@@ -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 };
|
||||
};
|
||||
|
||||
/** 获取全部通知渠道并转换为编辑器模型。 */
|
||||
|
||||
Reference in new issue
Block a user