♻️ refactor(simyo): 统一客户端版本与 User-Agent 配置

抽取 client-identity 作为版本、设备型号与 User-Agent 的单一事实来源;
本地与 Netlify 代理强制使用配置的 User-Agent,不再透传浏览器 UA。
This commit is contained in:
Abner
2026-07-22 18:18:58 +08:00
parent 5a65dd3d01
commit 2bbe2f9bc4
8 changed files with 121 additions and 24 deletions

View File

@@ -1,7 +1,7 @@
'use strict';
/**
* Simyo api-config请求头与设备 ID(对齐官方 App 抓包)
* Simyo api-config / client-identity:请求头与设备身份(对齐官方 App 抓包)
*/
import {
@@ -9,8 +9,31 @@ import {
getOrCreateDeviceId,
simyoConfig
} from '../../src/simyo/js/modules/api-config.js';
import {
SIMYO_CLIENT_PLATFORM,
SIMYO_CLIENT_VERSION,
SIMYO_DEVICE_MODEL,
SIMYO_IOS_VERSION,
SIMYO_USER_AGENT,
simyoClientIdentity
} from '../../src/simyo/js/modules/client-identity.js';
const UUID_RE = /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/;
/** 官方抓包 UA版本号后恰好两个空格 */
const OFFICIAL_UA = 'MijnSimyoFT/4.28.0 (iOS 27.0; iPhone16,1)';
describe('Simyo client-identity', () => {
it('版本 / 设备 / UA 应与 4.28.0 抓包完全一致', () => {
expect(SIMYO_CLIENT_VERSION).toBe('4.28.0');
expect(SIMYO_CLIENT_PLATFORM).toBe('ios');
expect(SIMYO_IOS_VERSION).toBe('27.0');
expect(SIMYO_DEVICE_MODEL).toBe('iPhone16,1');
expect(SIMYO_USER_AGENT).toBe(OFFICIAL_UA);
// 版本号与括号之间必须是两个空格(不是一个)
expect(SIMYO_USER_AGENT).toMatch(/^MijnSimyoFT\/4\.28\.0 {2}\(iOS 27\.0; iPhone16,1\)$/);
expect(simyoClientIdentity.userAgent).toBe(OFFICIAL_UA);
});
});
describe('Simyo api-config headers', () => {
beforeEach(() => {
@@ -29,9 +52,10 @@ describe('Simyo api-config headers', () => {
it('createHeaders 必须包含官方抓包中的核心头', () => {
const headers = createHeaders(false);
expect(headers['X-Client-Token']).toBe(simyoConfig.clientToken);
expect(headers['X-Client-Platform']).toBe('ios');
expect(headers['X-Client-Version']).toBe('4.28.0');
expect(headers['X-Client-Platform']).toBe(SIMYO_CLIENT_PLATFORM);
expect(headers['X-Client-Version']).toBe(SIMYO_CLIENT_VERSION);
expect(headers['X-Device-ID']).toMatch(UUID_RE);
expect(headers['User-Agent']).toBe(OFFICIAL_UA);
expect(headers['User-Agent']).toBe(simyoConfig.userAgent);
expect(headers['Content-Type']).toBe('application/json');
expect(headers.Accept).toBe('application/json');
@@ -42,5 +66,6 @@ describe('Simyo api-config headers', () => {
const headers = createHeaders(true, 'sess-token-1');
expect(headers['X-Session-Token']).toBe('sess-token-1');
expect(headers['X-Device-ID']).toMatch(UUID_RE);
expect(headers['User-Agent']).toBe(OFFICIAL_UA);
});
});

View File

@@ -540,6 +540,7 @@
'X-Client-Platform': 'ios',
'X-Client-Version': '4.28.0',
'X-Device-ID': 'E766D17B-BDF5-43B8-8807-35E43BA129E2',
// 官方抓包:版本号后两个空格 + iOS 27.0 + iPhone16,1
'User-Agent': 'MijnSimyoFT/4.28.0 (iOS 27.0; iPhone16,1)',
'Content-Type': 'application/json',
'Accept': 'application/json',