diff --git a/src/common/utils/QQBasicInfo.ts b/src/common/utils/QQBasicInfo.ts index d76cd162..5f131a1f 100644 --- a/src/common/utils/QQBasicInfo.ts +++ b/src/common/utils/QQBasicInfo.ts @@ -1,61 +1,32 @@ import path from 'node:path'; import fs from 'node:fs'; -import os from 'node:os'; import { systemPlatform } from '@/common/utils/system'; -import { logError } from '@/common/utils/log'; -export const exePath = process.execPath; +import { getDefaultQQVersionConfigInfo, getQQVersionConfigPath } from './helper'; -export const pkgInfoPath = path.join(path.dirname(exePath), 'resources', 'app', 'package.json'); -let configVersionInfoPath; +//基础目录获取 +export let QQMainPath = process.execPath; +export let QQPackageInfoPath: string = path.join(path.dirname(QQMainPath), 'resources', 'app', 'package.json'); +export let QQVersionConfigPath: string | undefined = getQQVersionConfigPath(); -if (os.platform() !== 'linux') { - configVersionInfoPath = path.join(path.dirname(exePath), 'resources', 'app', 'versions', 'config.json'); -} else { - const userPath = os.homedir(); - const appDataPath = path.resolve(userPath, './.config/QQ'); - configVersionInfoPath = path.resolve(appDataPath, './versions/config.json'); +//基础信息获取 无快更则启用默认模板填充 +export let QQVersionAppid: string = systemPlatform === 'linux' ? '537237950' : '537237765'; +export let isQuickUpdate: boolean = !!QQVersionConfigPath; +export let QQVersionConfig: QQVersionConfigType = isQuickUpdate ? JSON.parse(fs.readFileSync(QQVersionConfigPath!).toString()) : getDefaultQQVersionConfigInfo(); +export let QQPackageInfo: QQPackageInfoType = JSON.parse(fs.readFileSync(QQPackageInfoPath).toString()); + +//基础函数 +export function getQQBuildStr() { + return isQuickUpdate ? QQVersionConfig.buildId : QQPackageInfo.buildVersion; } - -if (typeof configVersionInfoPath !== 'string') { - throw new Error('Something went wrong when load QQ info path'); +export function getFullQQVesion() { + return isQuickUpdate ? QQVersionConfig.curVersion : QQPackageInfo.version; } - -export { configVersionInfoPath }; - -type QQPkgInfo = { - version: string; - buildVersion: string; - platform: string; - eleArch: string; +export function requireMinNTQQBuild(buildStr: string) { + return parseInt(getQQBuildStr()) >= parseInt(buildStr); } -type QQVersionConfigInfo = { - baseVersion: string; - curVersion: string; - prevVersion: string; - onErrorVersions: Array; - buildId: string; +export function getQUA() { + return systemPlatform === 'linux' ? `V1_LNX_NQ_${getFullQQVesion()}_${getQQBuildStr()}_GW_B` : `V1_WIN_NQ_${getFullQQVesion()}_${getQQBuildStr()}_GW_B`; } - -let _qqVersionConfigInfo: QQVersionConfigInfo = { - 'baseVersion': '9.9.15-26702', - 'curVersion': '9.9.15-26702', - 'prevVersion': '', - 'onErrorVersions': [], - 'buildId': '26702' -}; - -if (fs.existsSync(configVersionInfoPath)) { - try { - const _ = JSON.parse(fs.readFileSync(configVersionInfoPath).toString()); - _qqVersionConfigInfo = Object.assign(_qqVersionConfigInfo, _); - } catch (e) { - logError('Load QQ version config info failed, Use default version', e); - } -} - -export const qqVersionConfigInfo: QQVersionConfigInfo = _qqVersionConfigInfo; -//V1_WIN_NQ_9.9.12_25765_GW_B -export const qqPkgInfo: QQPkgInfo = JSON.parse(fs.readFileSync(pkgInfoPath).toString()); // platform_type: 3, // app_type: 4, // app_version: '9.9.12-25765', @@ -63,16 +34,6 @@ export const qqPkgInfo: QQPkgInfo = JSON.parse(fs.readFileSync(pkgInfoPath).toSt // appid: '537234702', // platVer: '10.0.26100', // clientVer: '9.9.9-25765', - // Linux // app_version: '3.2.9-25765', // qua: 'V1_LNX_NQ_3.2.10_25765_GW_B', -export function requireMinNTQBuild(buildStr: string) { - return parseInt(qqVersionConfigInfo.buildId) >= parseInt(buildStr); -} -let _appid: string = '537237765'; // 默认为 Windows 平台的 appid -if (systemPlatform === 'linux') { - _appid = '537237950'; -} -// todo: mac 平台的 appid -export const appid = _appid; \ No newline at end of file diff --git a/src/common/utils/helper.ts b/src/common/utils/helper.ts index eb87462f..65ed495f 100644 --- a/src/common/utils/helper.ts +++ b/src/common/utils/helper.ts @@ -1,10 +1,11 @@ import crypto from 'node:crypto'; import path from 'node:path'; -import fs from 'fs/promises'; +import fs from 'fs'; import { log, logDebug } from './log'; import { dirname } from 'node:path'; import { fileURLToPath } from 'node:url'; import * as fsPromise from 'node:fs/promises'; +import os from 'node:os'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); @@ -304,14 +305,14 @@ export function migrateConfig(oldConfig: any) { } // 升级旧的配置到新的 export async function UpdateConfig() { - const configFiles = await fs.readdir(path.join(__dirname, 'config')); + const configFiles = await fsPromise.readdir(path.join(__dirname, 'config')); for (const file of configFiles) { if (file.match(/^onebot11_\d+.json$/)) { - const CurrentConfig = JSON.parse(await fs.readFile(path.join(__dirname, 'config', file), 'utf8')); + const CurrentConfig = JSON.parse(await fsPromise.readFile(path.join(__dirname, 'config', file), 'utf8')); if (isValidOldConfig(CurrentConfig)) { log('正在迁移旧配置到新配置 File:', file); const NewConfig = migrateConfig(CurrentConfig); - await fs.writeFile(path.join(__dirname, 'config', file), JSON.stringify(NewConfig, null, 2)); + await fsPromise.writeFile(path.join(__dirname, 'config', file), JSON.stringify(NewConfig, null, 2)); } } } @@ -331,7 +332,42 @@ export function isEqual(obj1: any, obj2: any) { } return true; } +export function getDefaultQQVersionConfigInfo(): QQVersionConfigType { + if (os.platform() === 'linux') { + return { + baseVersion: '3.2.12-26702', + curVersion: '3.2.12-26702', + prevVersion: '', + onErrorVersions: [], + buildId: '26702' + }; + } + return { + baseVersion: '9.9.15-26702', + curVersion: '9.9.15-26702', + prevVersion: '', + onErrorVersions: [], + buildId: '26702' + }; +} +export function getQQVersionConfigPath(exePath: string = ""): string | undefined { + let configVersionInfoPath; + if (os.platform() !== 'linux') { + configVersionInfoPath = path.join(path.dirname(exePath), 'resources', 'app', 'versions', 'config.json'); + } else { + const userPath = os.homedir(); + const appDataPath = path.resolve(userPath, './.config/QQ'); + configVersionInfoPath = path.resolve(appDataPath, './versions/config.json'); + } + if (typeof configVersionInfoPath !== 'string') { + return undefined; + } + if (!fs.existsSync(configVersionInfoPath)) { + return undefined; + } + return configVersionInfoPath; +} export async function deleteOldFiles(directoryPath: string, daysThreshold: number) { try { const files = await fsPromise.readdir(directoryPath); diff --git a/src/common/utils/type.ts b/src/common/utils/type.ts index 058e7be4..cf95f60d 100644 --- a/src/common/utils/type.ts +++ b/src/common/utils/type.ts @@ -1,31 +1,14 @@ -/** - * 运行时类型转换与检查类 - */ -export class TypeCheck { - static isEmpty(value: any): boolean { - return value === null || value === undefined || value === '' || - (Array.isArray(value) && value.length === 0) || (typeof value === 'object' && Object.keys(value).length === 0); - } +//QQVersionType +type QQPackageInfoType = { + version: string; + buildVersion: string; + platform: string; + eleArch: string; } - -export class TypeConvert { - static toNumber(value: any): number { - const num = Number(value); - if (isNaN(num)) { - throw new Error(`无法将输入转换为数字: ${value}`); - } - return num; - } - - static toString(value: any): string { - return String(value); - } - - static toBoolean(value: any): boolean { - return Boolean(value); - } - - static toArray(value: any): any[] { - return Array.isArray(value) ? value : [value]; - } +type QQVersionConfigType = { + baseVersion: string; + curVersion: string; + prevVersion: string; + onErrorVersions: Array; + buildId: string; } \ No newline at end of file diff --git a/src/core/src/apis/msg.ts b/src/core/src/apis/msg.ts index fbe1d799..71506604 100644 --- a/src/core/src/apis/msg.ts +++ b/src/core/src/apis/msg.ts @@ -7,7 +7,7 @@ import { onGroupFileInfoUpdateParamType } from '@/core/listeners'; import { GeneralCallResult } from '@/core/services/common'; import { MessageUnique } from '../../../common/utils/MessageUnique'; import { NTEventDispatch } from '@/common/utils/EventTask'; -import { requireMinNTQBuild } from '@/common/utils/QQBasicInfo'; +import { requireMinNTQQBuild } from '@/common/utils/QQBasicInfo'; async function LoadMessageIdList(Peer: Peer, msgId: string) { let msgList = await NTQQMsgApi.getMsgHistory(Peer, msgId, 50); @@ -231,7 +231,7 @@ export class NTQQMsgApi { return retMsg; } static async getMsgUnique(chatType: number, time: string) { - if (requireMinNTQBuild('26702')) { + if (requireMinNTQQBuild('26702')) { return napCatCore.session.getMsgService().generateMsgUniqueId(chatType, time); } return napCatCore.session.getMsgService().getMsgUniqueId(time); diff --git a/src/core/src/apis/user.ts b/src/core/src/apis/user.ts index 4c137930..d2b8c153 100644 --- a/src/core/src/apis/user.ts +++ b/src/core/src/apis/user.ts @@ -7,7 +7,7 @@ import { RequestUtil } from '@/common/utils/request'; import { logWarn } from '@/common/utils/log'; import { NTEventDispatch } from '@/common/utils/EventTask'; import { NodeIKernelProfileService, ProfileBizType, UserDetailSource } from '@/core/services'; -import { requireMinNTQBuild } from '@/common/utils/QQBasicInfo'; +import { requireMinNTQQBuild } from '@/common/utils/QQBasicInfo'; export class NTQQUserApi { static async getProfileLike(uid: string) { @@ -50,14 +50,6 @@ export class NTQQUserApi { static async setGroupAvatar(gc: string, filePath: string) { return napCatCore.session.getGroupService().setHeader(gc, filePath); } - - static async getSelfInfo() { - - } - - static async getUserInfo(uid: string) { - - } // enum ProfileBizType { // KALL, // KBASEEXTEND, @@ -139,7 +131,7 @@ export class NTQQUserApi { return RetUser; } static async getUserDetailInfo(uid: string) { - if (requireMinNTQBuild('26702')) { + if (requireMinNTQQBuild('26702')) { return this.fetchUserDetailInfo(uid); } return this.getUserDetailInfoOld(uid); diff --git a/src/core/src/core.ts b/src/core/src/core.ts index 3174a37e..ab5108c5 100644 --- a/src/core/src/core.ts +++ b/src/core/src/core.ts @@ -15,7 +15,7 @@ import { DependsAdapter, DispatcherAdapter, GlobalAdapter, NodeIGlobalAdapter } import path from 'node:path'; import os from 'node:os'; import fs from 'node:fs'; -import { appid, qqVersionConfigInfo } from '@/common/utils/QQBasicInfo'; +import { getFullQQVesion, getQUA, QQVersionAppid } from '@/common/utils/QQBasicInfo'; import { hostname, systemVersion } from '@/common/utils/system'; import { genSessionConfig } from '@/core/sessionConfig'; import { sleep } from '@/common/utils/helper'; @@ -139,10 +139,10 @@ export class NapCatCore { base_path_prefix: '', platform_type: 3, app_type: 4, - app_version: qqVersionConfigInfo.curVersion, + app_version: getFullQQVesion(), os_version: 'Windows 10 Pro', use_xlog: true, - qua: `V1_WIN_NQ_${qqVersionConfigInfo.curVersion.replace('-', '_')}_GW_B`, + qua: getQUA(), global_path_config: { desktopGlobalPath: this.dataPathGlobal, }, @@ -150,10 +150,10 @@ export class NapCatCore { }, new QQWrapper.NodeIGlobalAdapter(new GlobalAdapter())); this.loginService.initConfig({ machineId: '', - appid, + appid: QQVersionAppid, platVer: systemVersion, commonPath: this.dataPathGlobal, - clientVer: qqVersionConfigInfo.curVersion, + clientVer: getFullQQVesion(), hostName: hostname }); } diff --git a/src/core/src/sessionConfig.ts b/src/core/src/sessionConfig.ts index c31f90db..272507a1 100644 --- a/src/core/src/sessionConfig.ts +++ b/src/core/src/sessionConfig.ts @@ -1,4 +1,4 @@ -import { appid, qqPkgInfo, qqVersionConfigInfo } from '@/common/utils/QQBasicInfo'; +import { getFullQQVesion, QQVersionAppid } from '@/common/utils/QQBasicInfo'; import { hostname, systemName, systemVersion } from '@/common/utils/system'; import path from 'node:path'; import fs from 'node:fs'; @@ -79,7 +79,7 @@ export async function genSessionConfig(selfUin: string, selfUid: string, account fs.mkdirSync(downloadPath, { recursive: true }); let guid: string = await getMachineId(); //console.log(guid); - // guid = '52afb776-82f6-4e59-9d38-44705b112d0a'; + // guid = '52afb776-82f6-4e59-9d38-44705b112d0a'; //let guid: string = await getMachineId(); const config: WrapperSessionInitConfig = { selfUin, @@ -87,14 +87,14 @@ export async function genSessionConfig(selfUin: string, selfUid: string, account desktopPathConfig: { account_path // 可以通过NodeQQNTWrapperUtil().getNTUserDataInfoConfig()获取 }, - clientVer: qqVersionConfigInfo.curVersion, // 9.9.8-22355 + clientVer: getFullQQVesion(), // 9.9.8-22355 a2: '', d2: '', d2Key: '', machineId: '', platform: 3, // 3是Windows? platVer: systemVersion, // 系统版本号, 应该可以固定 - appid: appid, + appid: QQVersionAppid, rdeliveryConfig: { appKey: '', systemId: 0, @@ -110,18 +110,18 @@ export async function genSessionConfig(selfUin: string, selfUid: string, account serverUrl: '', fixedAfterHitKeys: [''] }, - 'defaultFileDownloadPath': downloadPath, - 'deviceInfo': { + defaultFileDownloadPath: downloadPath, + deviceInfo: { guid, - 'buildVer': qqPkgInfo.version, - 'localId': 2052, - 'devName': hostname, - 'devType': systemName, - 'vendorName': '', - 'osVer': systemVersion, - 'vendorOsName': systemName, - 'setMute': false, - 'vendorType': 0 + buildVer: getFullQQVesion(), + localId: 2052, + devName: hostname, + devType: systemName, + vendorName: '', + osVer: systemVersion, + vendorOsName: systemName, + setMute: false, + vendorType: 0 }, 'deviceConfig': '{"appearance":{"isSplitViewMode":true},"msg":{}}' }; diff --git a/src/core/src/wrapper.ts b/src/core/src/wrapper.ts index ff960cd1..62f17b87 100644 --- a/src/core/src/wrapper.ts +++ b/src/core/src/wrapper.ts @@ -26,7 +26,6 @@ import { NodeIKernelRichMediaService, NodeIKernelAvatarService, } from './services'; -import { qqVersionConfigInfo } from '@/common/utils/QQBasicInfo'; import { NodeIKernelStorageCleanService } from './services/NodeIKernelStorageCleanService'; import { NodeIKernelRobotService } from './services/NodeIKernelRobotService'; import { dirname } from "node:path" @@ -43,6 +42,7 @@ import { NodeIKernelRecentContactService } from './services/NodeIKernelRecentCon import { NodeIKernelMSFService } from './services/NodeIKernelMSFService'; import { NodeIkernelTestPerformanceService } from './services/NodeIkernelTestPerformanceService'; import { NodeIKernelECDHService } from './services/NodeIKernelECDHService'; +import { getFullQQVesion } from '@/common/utils/QQBasicInfo'; const __filename = fileURLToPath(import.meta.url); @@ -292,7 +292,7 @@ export interface WrapperNodeApi { let wrapperNodePath = path.resolve(path.dirname(process.execPath), './resources/app/wrapper.node'); if (!fs.existsSync(wrapperNodePath)) { - wrapperNodePath = path.join(path.dirname(process.execPath), `resources/app/versions/${qqVersionConfigInfo.curVersion}/wrapper.node`); + wrapperNodePath = path.join(path.dirname(process.execPath), `resources/app/versions/${getFullQQVesion()}/wrapper.node`); } const nativemodule: any = { exports: {} }; process.dlopen(nativemodule, wrapperNodePath);