From a9902d910909ed8ab39f45a29a30f0f4da043e85 Mon Sep 17 00:00:00 2001 From: idranme Date: Mon, 5 Aug 2024 22:49:48 +0800 Subject: [PATCH] sync --- src/ntqqapi/api/user.ts | 80 +++++++++++++++---- .../listeners/NodeIKernelProfileListener.ts | 44 ++++++++++ src/ntqqapi/listeners/index.ts | 1 + src/ntqqapi/types/user.ts | 37 +++++++++ src/onebot11/action/quick-operation.ts | 8 +- 5 files changed, 149 insertions(+), 21 deletions(-) create mode 100644 src/ntqqapi/listeners/NodeIKernelProfileListener.ts create mode 100644 src/ntqqapi/listeners/index.ts diff --git a/src/ntqqapi/api/user.ts b/src/ntqqapi/api/user.ts index e5da023..ab7d1ed 100644 --- a/src/ntqqapi/api/user.ts +++ b/src/ntqqapi/api/user.ts @@ -5,14 +5,18 @@ import { selfInfo, uidMaps } from '../../common/data' import { cacheFunc, isQQ998, log, sleep } from '../../common/utils' import { wrapperApi } from '@/ntqqapi/wrapper' import { RequestUtil } from '@/common/utils/request' +import { NodeIKernelProfileService, UserDetailSource, ProfileBizType } from '../services' +import { NodeIKernelProfileListener } from '../listeners' +import { NTEventDispatch } from '@/common/utils/EventTask' +import { qqPkgInfo } from '@/common/utils/QQBasicInfo' const userInfoCache: Record = {} // uid: User export interface ClientKeyData extends GeneralCallResult { - url: string; - keyIndex: string; - clientKey: string; - expireTime: string; + url: string + keyIndex: string + clientKey: string + expireTime: string } export class NTQQUserApi { @@ -46,8 +50,49 @@ export class NTQQUserApi { return result.profiles.get(uid) } + // 26702 + static async fetchUserDetailInfo(uid: string) { + type EventService = NodeIKernelProfileService['fetchUserDetailInfo'] + type EventListener = NodeIKernelProfileListener['onUserDetailInfoChanged'] + const [_retData, profile] = await NTEventDispatch.CallNormalEvent + + ( + 'NodeIKernelProfileService/fetchUserDetailInfo', + 'NodeIKernelProfileListener/onUserDetailInfoChanged', + 1, + 5000, + (profile) => { + if (profile.uid === uid) { + return true; + } + return false; + }, + 'BuddyProfileStore', + [ + uid + ], + UserDetailSource.KSERVER, + [ + ProfileBizType.KALL + ] + ) + const RetUser: User = { + ...profile.simpleInfo.coreInfo, + ...profile.simpleInfo.status, + ...profile.simpleInfo.vasInfo, + ...profile.commonExt, + ...profile.simpleInfo.baseInfo, + qqLevel: profile.commonExt.qqLevel, + pendantId: '' + } + return RetUser + } + static async getUserDetailInfo(uid: string, getLevel = false, withBizInfo = true) { - // this.getUserInfo(uid); + if (+qqPkgInfo.buildVersion >= 26702) { + return this.fetchUserDetailInfo(uid) + } + // this.getUserInfo(uid) let methodName = !isQQ998 ? NTQQApiMethod.USER_DETAIL_INFO : NTQQApiMethod.USER_DETAIL_INFO_WITH_BIZ_INFO if (!withBizInfo) { methodName = NTQQApiMethod.USER_DETAIL_INFO @@ -80,7 +125,7 @@ export class NTQQUserApi { await fetchInfo() await sleep(1000) } - let userInfo = await fetchInfo() + const userInfo = await fetchInfo() userInfoCache[uid] = userInfo return userInfo } @@ -97,16 +142,17 @@ export class NTQQUserApi { ], }) } + static async getQzoneCookies() { const requestUrl = 'https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=' + selfInfo.uin + '&clientkey=' + (await this.getClientKey()).clientKey + '&u1=https%3A%2F%2Fuser.qzone.qq.com%2F' + selfInfo.uin + '%2Finfocenter&keyindex=19%27' - let cookies: { [key: string]: string; } = {}; + let cookies: { [key: string]: string } = {} try { - cookies = await RequestUtil.HttpsGetCookies(requestUrl); + cookies = await RequestUtil.HttpsGetCookies(requestUrl) } catch (e: any) { log('获取QZone Cookies失败', e) cookies = {} } - return cookies; + return cookies } static async getSkey(): Promise { const clientKeyData = await this.getClientKey() @@ -115,24 +161,24 @@ export class NTQQUserApi { } const url = 'https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=' + selfInfo.uin + '&clientkey=' + clientKeyData.clientKey - + '&u1=https%3A%2F%2Fh5.qzone.qq.com%2Fqqnt%2Fqzoneinpcqq%2Ffriend%3Frefresh%3D0%26clientuin%3D0%26darkMode%3D0&keyindex=' + clientKeyData.keyIndex; - return (await RequestUtil.HttpsGetCookies(url))?.skey; + + '&u1=https%3A%2F%2Fh5.qzone.qq.com%2Fqqnt%2Fqzoneinpcqq%2Ffriend%3Frefresh%3D0%26clientuin%3D0%26darkMode%3D0&keyindex=' + clientKeyData.keyIndex + return (await RequestUtil.HttpsGetCookies(url))?.skey } @cacheFunc(60 * 30 * 1000) static async getCookies(domain: string) { if (domain.endsWith("qzone.qq.com")) { - let data = (await NTQQUserApi.getQzoneCookies()); - const CookieValue = 'p_skey=' + data.p_skey + '; skey=' + data.skey + '; p_uin=o' + selfInfo.uin + '; uin=o' + selfInfo.uin; - return { bkn: NTQQUserApi.genBkn(data.p_skey), cookies: CookieValue }; + let data = (await NTQQUserApi.getQzoneCookies()) + const CookieValue = 'p_skey=' + data.p_skey + '; skey=' + data.skey + '; p_uin=o' + selfInfo.uin + '; uin=o' + selfInfo.uin + return { bkn: NTQQUserApi.genBkn(data.p_skey), cookies: CookieValue } } - const skey = await this.getSkey(); - const pskey = (await this.getPSkey([domain])).get(domain); + const skey = await this.getSkey() + const pskey = (await this.getPSkey([domain])).get(domain) if (!pskey || !skey) { throw new Error('获取Cookies失败') } const bkn = NTQQUserApi.genBkn(skey) - const cookies = `p_skey=${pskey}; skey=${skey}; p_uin=o${selfInfo.uin}; uin=o${selfInfo.uin}`; + const cookies = `p_skey=${pskey}; skey=${skey}; p_uin=o${selfInfo.uin}; uin=o${selfInfo.uin}` return { cookies, bkn } } diff --git a/src/ntqqapi/listeners/NodeIKernelProfileListener.ts b/src/ntqqapi/listeners/NodeIKernelProfileListener.ts new file mode 100644 index 0000000..c0a53ad --- /dev/null +++ b/src/ntqqapi/listeners/NodeIKernelProfileListener.ts @@ -0,0 +1,44 @@ +import { User, UserDetailInfoListenerArg } from '@/ntqqapi/types' + +interface IProfileListener { + onProfileSimpleChanged(...args: unknown[]): void + + onUserDetailInfoChanged(arg: UserDetailInfoListenerArg): void + + onProfileDetailInfoChanged(profile: User): void + + onStatusUpdate(...args: unknown[]): void + + onSelfStatusChanged(...args: unknown[]): void + + onStrangerRemarkChanged(...args: unknown[]): void +} + +export interface NodeIKernelProfileListener extends IProfileListener { + new(listener: IProfileListener): NodeIKernelProfileListener +} + +export class ProfileListener implements IProfileListener { + onUserDetailInfoChanged(arg: UserDetailInfoListenerArg): void { + + } + onProfileSimpleChanged(...args: unknown[]) { + + } + + onProfileDetailInfoChanged(profile: User) { + + } + + onStatusUpdate(...args: unknown[]) { + + } + + onSelfStatusChanged(...args: unknown[]) { + + } + + onStrangerRemarkChanged(...args: unknown[]) { + + } +} \ No newline at end of file diff --git a/src/ntqqapi/listeners/index.ts b/src/ntqqapi/listeners/index.ts new file mode 100644 index 0000000..b3932e9 --- /dev/null +++ b/src/ntqqapi/listeners/index.ts @@ -0,0 +1 @@ +export * from './NodeIKernelProfileListener' \ No newline at end of file diff --git a/src/ntqqapi/types/user.ts b/src/ntqqapi/types/user.ts index b879034..8538265 100644 --- a/src/ntqqapi/types/user.ts +++ b/src/ntqqapi/types/user.ts @@ -221,4 +221,41 @@ interface RelationFlags { export interface FriendV2 extends SimpleInfo { categoryId?: number categroyName?: string +} + +interface CommonExt { + constellation: number + shengXiao: number + kBloodType: number + homeTown: string + makeFriendCareer: number + pos: string + college: string + country: string + province: string + city: string + postCode: string + address: string + regTime: number + interest: string + labels: any[] + qqLevel: QQLevel +} + +interface Pic { + picId: string + picTime: number + picUrlMap: Record +} + +interface PhotoWall { + picList: Pic[] +} + +export interface UserDetailInfoListenerArg { + uid: string + uin: string + simpleInfo: SimpleInfo + commonExt: CommonExt + photoWall: PhotoWall } \ No newline at end of file diff --git a/src/onebot11/action/quick-operation.ts b/src/onebot11/action/quick-operation.ts index fa9c1bf..4042cc3 100644 --- a/src/onebot11/action/quick-operation.ts +++ b/src/onebot11/action/quick-operation.ts @@ -5,8 +5,8 @@ import { OB11Message, OB11MessageAt, OB11MessageData, OB11MessageDataType } from import { OB11FriendRequestEvent } from '../event/request/OB11FriendRequest' import { OB11GroupRequestEvent } from '../event/request/OB11GroupRequest' import { dbUtil } from '@/common/db' -import { NTQQFriendApi, NTQQGroupApi, NTQQMsgApi, Peer } from '@/ntqqapi/api' -import { ChatType, Group, GroupRequestOperateTypes } from '@/ntqqapi/types' +import { NTQQFriendApi, NTQQGroupApi, NTQQMsgApi } from '@/ntqqapi/api' +import { ChatType, Group, GroupRequestOperateTypes, Peer } from '@/ntqqapi/types' import { getGroup, getUidByUin } from '@/common/data' import { convertMessage2List, createSendElements, sendMsg } from './msg/SendMsg' import { isNull, log } from '@/common/utils' @@ -129,7 +129,7 @@ async function handleMsg(msg: OB11Message, quickAction: QuickOperationPrivateMes } async function handleFriendRequest(request: OB11FriendRequestEvent, - quickAction: QuickOperationFriendRequest) { + quickAction: QuickOperationFriendRequest) { if (!isNull(quickAction.approve)) { // todo: set remark NTQQFriendApi.handleFriendRequest(request.flag, quickAction.approve).then().catch(log) @@ -138,7 +138,7 @@ async function handleFriendRequest(request: OB11FriendRequestEvent, async function handleGroupRequest(request: OB11GroupRequestEvent, - quickAction: QuickOperationGroupRequest) { + quickAction: QuickOperationGroupRequest) { if (!isNull(quickAction.approve)) { NTQQGroupApi.handleGroupRequest( request.flag,