fix: adaptation 27187

This commit is contained in:
idranme
2024-08-22 05:45:02 +08:00
parent 1afaeb0396
commit 8b57ebd7de
5 changed files with 225 additions and 104 deletions

View File

@@ -298,10 +298,26 @@ export class NTQQMsgApi {
throw new Error('转发消息超时') throw new Error('转发消息超时')
} }
/** 27187 TODO */
static async getMsgsBySeqAndCount(peer: Peer, seq: string, count: number, desc: boolean, z: boolean) { static async getMsgsBySeqAndCount(peer: Peer, seq: string, count: number, desc: boolean, z: boolean) {
const session = getSession() const session = getSession()
return await session?.getMsgService().getMsgsBySeqAndCount(peer, seq, count, desc, z) if (session) {
return await session.getMsgService().getMsgsBySeqAndCount(peer, seq, count, desc, z)
} else {
return await invoke<GeneralCallResult & {
msgList: RawMessage[]
}>({
methodName: 'nodeIKernelMsgService/getMsgsBySeqAndCount',
args: [
{
peer,
cnt: count,
msgSeq: seq,
queryOrder: desc
},
null,
],
})
}
} }
/** 27187 TODO */ /** 27187 TODO */
@@ -320,9 +336,23 @@ export class NTQQMsgApi {
return ret return ret
} }
/** 27187 TODO */
static async getSingleMsg(peer: Peer, seq: string) { static async getSingleMsg(peer: Peer, seq: string) {
const session = getSession() const session = getSession()
return await session?.getMsgService().getSingleMsg(peer, seq) if (session) {
return await session.getMsgService().getSingleMsg(peer, seq)
} else {
return await invoke<GeneralCallResult & {
msgList: RawMessage[]
}>({
methodName: 'nodeIKernelMsgService/getSingleMsg',
args: [
{
peer,
msgSeq: seq,
},
null,
],
})
}
} }
} }

View File

@@ -78,25 +78,42 @@ export class NTQQUserApi {
if (getBuildVersion() >= 26702) { if (getBuildVersion() >= 26702) {
return NTQQUserApi.fetchUserDetailInfo(uid) return NTQQUserApi.fetchUserDetailInfo(uid)
} }
type EventService = NodeIKernelProfileService['getUserDetailInfoWithBizInfo'] if (NTEventDispatch.initialised) {
type EventListener = NodeIKernelProfileListener['onProfileDetailInfoChanged'] type EventService = NodeIKernelProfileService['getUserDetailInfoWithBizInfo']
const [_retData, profile] = await NTEventDispatch.CallNormalEvent type EventListener = NodeIKernelProfileListener['onProfileDetailInfoChanged']
<EventService, EventListener> const [_retData, profile] = await NTEventDispatch.CallNormalEvent
( <EventService, EventListener>
'NodeIKernelProfileService/getUserDetailInfoWithBizInfo', (
'NodeIKernelProfileListener/onProfileDetailInfoChanged', 'NodeIKernelProfileService/getUserDetailInfoWithBizInfo',
2, 'NodeIKernelProfileListener/onProfileDetailInfoChanged',
5000, 2,
(profile) => profile.uid === uid, 5000,
uid, (profile) => profile.uid === uid,
[0] uid,
) [0]
return profile )
return profile
} else {
const result = await invoke<{ info: User }>({
methodName: 'nodeIKernelProfileService/getUserDetailInfoWithBizInfo',
cbCmd: 'nodeIKernelProfileListener/onProfileDetailInfoChanged',
afterFirstCmd: false,
cmdCB: (payload) => payload.info.uid === uid,
args: [
{
uid,
bizList: [0]
},
null,
],
})
return result.info
}
} }
static async getSkey(): Promise<string> { static async getSkey(): Promise<string> {
const clientKeyData = await NTQQUserApi.getClientKey() const clientKeyData = await NTQQUserApi.forceFetchClientKey()
if (clientKeyData.result !== 0) { if (clientKeyData?.result !== 0) {
throw new Error('获取clientKey失败') throw new Error('获取clientKey失败')
} }
const url = 'https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=' + getSelfUin() const url = 'https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=' + getSelfUin()
@@ -107,9 +124,12 @@ export class NTQQUserApi {
@CacheClassFuncAsync(1800 * 1000) @CacheClassFuncAsync(1800 * 1000)
static async getCookies(domain: string) { static async getCookies(domain: string) {
const ClientKeyData = await NTQQUserApi.forceFetchClientKey() const clientKeyData = await NTQQUserApi.forceFetchClientKey()
if (clientKeyData?.result !== 0) {
throw new Error('获取clientKey失败')
}
const uin = getSelfUin() const uin = getSelfUin()
const requestUrl = 'https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=' + uin + '&clientkey=' + ClientKeyData.clientKey + '&u1=https%3A%2F%2F' + domain + '%2F' + uin + '%2Finfocenter&keyindex=19%27' const requestUrl = 'https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=' + uin + '&clientkey=' + clientKeyData.clientKey + '&u1=https%3A%2F%2F' + domain + '%2F' + uin + '%2Finfocenter&keyindex=19%27'
const cookies: { [key: string]: string; } = await RequestUtil.HttpsGetCookies(requestUrl) const cookies: { [key: string]: string; } = await RequestUtil.HttpsGetCookies(requestUrl)
return cookies return cookies
} }
@@ -126,6 +146,7 @@ export class NTQQUserApi {
return (hash & 0x7fffffff).toString() return (hash & 0x7fffffff).toString()
} }
/** 27187 TODO */
static async getPSkey(domains: string[]): Promise<Map<string, string>> { static async getPSkey(domains: string[]): Promise<Map<string, string>> {
const session = getSession() const session = getSession()
const res = await session?.getTipOffService().getPskey(domains, true) const res = await session?.getTipOffService().getPskey(domains, true)
@@ -135,19 +156,15 @@ export class NTQQUserApi {
return res.domainPskeyMap return res.domainPskeyMap
} }
static async getClientKey() { /** 27187 TODO */
const session = getSession() static async like(uid: string, count = 1) {
return await session?.getTicketService().forceFetchClientKey('')!
}
static async like(uid: string, count = 1): Promise<{ result: number, errMsg: string, succCounts: number }> {
const session = getSession() const session = getSession()
return session?.getProfileLikeService().setBuddyProfileLike({ return session?.getProfileLikeService().setBuddyProfileLike({
friendUid: uid, friendUid: uid,
sourceId: 71, sourceId: 71,
doLikeCount: count, doLikeCount: count,
doLikeTollCount: 0 doLikeTollCount: 0
})! })
} }
static async getUidByUinV1(Uin: string) { static async getUidByUinV1(Uin: string) {
@@ -182,17 +199,45 @@ export class NTQQUserApi {
} }
static async getUidByUinV2(uin: string) { static async getUidByUinV2(uin: string) {
const session = getSession()! const session = getSession()
let uid = (await session.getGroupService().getUidByUins([uin])).uids.get(uin) if (session) {
if (uid) return uid let uid = (await session.getGroupService().getUidByUins([uin])).uids.get(uin)
uid = (await session.getProfileService().getUidByUin('FriendsServiceImpl', [uin])).get(uin) if (uid) return uid
if (uid) return uid uid = (await session.getProfileService().getUidByUin('FriendsServiceImpl', [uin])).get(uin)
uid = (await session.getUixConvertService().getUid([uin])).uidInfo.get(uin) if (uid) return uid
if (uid) return uid uid = (await session.getUixConvertService().getUid([uin])).uidInfo.get(uin)
if (uid) return uid
} else {
let uid = (await invoke<{ uids: Map<string, string> }>({
methodName: 'nodeIKernelGroupService/getUidByUins',
args: [
{ uin: [uin] },
null,
],
})).uids.get(uin)
if (uid) return uid
uid = (await invoke<Map<string, string>>({
methodName: 'nodeIKernelProfileService/getUidByUin',
args: [
{
callFrom: 'FriendsServiceImpl',
uin: [uin],
},
null,
],
})).get(uin)
if (uid) return uid
uid = (await invoke<{ uidInfo: Map<string, string> }>({
methodName: 'nodeIKernelUixConvertService/getUid',
args: [
{ uin: [uin] },
null,
],
})).uidInfo.get(uin)
if (uid) return uid
}
const unveifyUid = (await NTQQUserApi.getUserDetailInfoByUinV2(uin)).detail.uid //从QQ Native 特殊转换 const unveifyUid = (await NTQQUserApi.getUserDetailInfoByUinV2(uin)).detail.uid //从QQ Native 特殊转换
if (unveifyUid.indexOf('*') == -1) uid = unveifyUid if (unveifyUid.indexOf('*') == -1) return unveifyUid
//if (uid) return uid
return uid
} }
static async getUidByUin(Uin: string) { static async getUidByUin(Uin: string) {
@@ -202,14 +247,25 @@ export class NTQQUserApi {
return await NTQQUserApi.getUidByUinV1(Uin) return await NTQQUserApi.getUidByUinV1(Uin)
} }
static async getUserDetailInfoByUinV2(Uin: string) { static async getUserDetailInfoByUinV2(uin: string) {
return await NTEventDispatch.CallNoListenerEvent if (NTEventDispatch.initialised) {
<(Uin: string) => Promise<UserDetailInfoByUinV2>>( return await NTEventDispatch.CallNoListenerEvent
'NodeIKernelProfileService/getUserDetailInfoByUin', <(Uin: string) => Promise<UserDetailInfoByUinV2>>(
5000, 'NodeIKernelProfileService/getUserDetailInfoByUin',
Uin 5000,
) uin
)
} else {
return await invoke<UserDetailInfoByUinV2>({
methodName: 'nodeIKernelProfileService/getUserDetailInfoByUin',
args: [
{ uin },
null,
],
})
}
} }
static async getUserDetailInfoByUin(Uin: string) { static async getUserDetailInfoByUin(Uin: string) {
return NTEventDispatch.CallNoListenerEvent return NTEventDispatch.CallNoListenerEvent
<(Uin: string) => Promise<UserDetailInfoByUin>>( <(Uin: string) => Promise<UserDetailInfoByUin>>(
@@ -242,29 +298,59 @@ export class NTQQUserApi {
} }
static async getUinByUidV2(uid: string) { static async getUinByUidV2(uid: string) {
const session = getSession()! const session = getSession()
let uin = (await session.getGroupService().getUinByUids([uid])).uins.get(uid) if (session) {
if (uin) return uin let uin = (await session.getGroupService().getUinByUids([uid])).uins.get(uid)
uin = (await session.getProfileService().getUinByUid('FriendsServiceImpl', [uid])).get(uid) if (uin) return uin
if (uin) return uin uin = (await session.getProfileService().getUinByUid('FriendsServiceImpl', [uid])).get(uid)
uin = (await session.getUixConvertService().getUin([uid])).uinInfo.get(uid) if (uin) return uin
if (uin) return uin uin = (await session.getUixConvertService().getUin([uid])).uinInfo.get(uid)
uin = (await NTQQFriendApi.getBuddyIdMap(true)).getKey(uid) if (uin) return uin
return uin
} else {
let uin = (await invoke<{ uins: Map<string, string> }>({
methodName: 'nodeIKernelGroupService/getUinByUids',
args: [
{ uid: [uid] },
null,
],
})).uins.get(uid)
if (uin) return uin
uin = (await invoke<Map<string, string>>({
methodName: 'nodeIKernelProfileService/getUinByUid',
args: [
{
callFrom: 'FriendsServiceImpl',
uid: [uid],
},
null,
],
})).get(uid)
if (uin) return uin
uin = (await invoke<{ uinInfo: Map<string, string> }>({
methodName: 'nodeIKernelUixConvertService/getUin',
args: [
{ uid: [uid] },
null,
],
})).uinInfo.get(uid)
if (uin) return uin
}
let uin = (await NTQQFriendApi.getBuddyIdMap(true)).getKey(uid)
if (uin) return uin if (uin) return uin
uin = (await NTQQUserApi.getUserDetailInfo(uid)).uin //从QQ Native 转换 uin = (await NTQQUserApi.getUserDetailInfo(uid)).uin //从QQ Native 转换
return uin
} }
static async getUinByUid(Uid: string) { static async getUinByUid(Uid: string) {
if (getBuildVersion() >= 26702) { if (getBuildVersion() >= 26702) {
return await NTQQUserApi.getUinByUidV2(Uid) return (await NTQQUserApi.getUinByUidV2(Uid))!
} }
return await NTQQUserApi.getUinByUidV1(Uid) return await NTQQUserApi.getUinByUidV1(Uid)
} }
@CacheClassFuncAsync(3600 * 1000, 'ClientKey') /** 27187 TODO */
static async forceFetchClientKey() { static async forceFetchClientKey() {
const session = getSession() const session = getSession()
return await session?.getTicketService().forceFetchClientKey('')! return await session?.getTicketService().forceFetchClientKey('')
} }
} }

View File

@@ -118,57 +118,63 @@ export function invoke<ReturnType>(params: InvokeParams<ReturnType>) {
} }
const apiArgs = [params.methodName, ...(params.args ?? [])] const apiArgs = [params.methodName, ...(params.args ?? [])]
//log('callNTQQApi', channel, eventName, apiArgs, uuid) //log('callNTQQApi', channel, eventName, apiArgs, uuid)
return Promise.race([ return new Promise((resolve: (data: ReturnType) => void, reject) => {
new Promise<ReturnType>((_, reject) => setTimeout(() => { let success = false
log(`ntqq api timeout ${channel}, ${eventName}, ${params.methodName}`, apiArgs) if (!params.cbCmd) {
reject(`ntqq api timeout ${channel}, ${eventName}, ${params.methodName}, ${apiArgs}`) // QQ后端会返回结果并且可以根据uuid识别
}, timeout)), hookApiCallbacks[uuid] = (r: ReturnType) => {
new Promise<ReturnType>((resolve: (data: ReturnType) => void, reject) => { success = true
if (!params.cbCmd) { resolve(r)
// QQ后端会返回结果并且可以根据uuid识别
hookApiCallbacks[uuid] = (r: ReturnType) => {
resolve(r)
}
} }
else { }
// 这里的callback比较特殊QQ后端先返回是否调用成功再返回一条结果数据 else {
const secondCallback = () => { // 这里的callback比较特殊QQ后端先返回是否调用成功再返回一条结果数据
const hookId = registerReceiveHook<ReturnType>(params.cbCmd!, (payload) => { const secondCallback = () => {
// log(methodName, "second callback", cbCmd, payload, cmdCB); const hookId = registerReceiveHook<ReturnType>(params.cbCmd!, (payload) => {
if (!!params.cmdCB) { // log(methodName, "second callback", cbCmd, payload, cmdCB);
if (params.cmdCB(payload)) { if (!!params.cmdCB) {
removeReceiveHook(hookId) if (params.cmdCB(payload)) {
resolve(payload)
}
}
else {
removeReceiveHook(hookId) removeReceiveHook(hookId)
success = true
resolve(payload) resolve(payload)
} }
})
}
!afterFirstCmd && secondCallback()
hookApiCallbacks[uuid] = (result: GeneralCallResult) => {
log(`${params.methodName} callback`, result)
if (result?.result === 0 || result === undefined) {
afterFirstCmd && secondCallback()
} }
else { else {
reject(`ntqq api call failed, ${result.errMsg}`) removeReceiveHook(hookId)
success = true
resolve(payload)
} }
})
}
!afterFirstCmd && secondCallback()
hookApiCallbacks[uuid] = (result: GeneralCallResult) => {
if (result?.result === 0 || result === undefined) {
log(`${params.methodName} callback`, result)
afterFirstCmd && secondCallback()
}
else {
log('ntqq api call failed', result)
reject(`ntqq api call failed, ${result.errMsg}`)
} }
} }
ipcMain.emit( }
channel, setTimeout(() => {
{ if (!success) {
sender: { log(`ntqq api timeout ${channel}, ${eventName}, ${params.methodName}`, apiArgs)
send: (..._args: unknown[]) => { reject(`ntqq api timeout ${channel}, ${eventName}, ${params.methodName}, ${apiArgs}`)
}, }
}, timeout)
ipcMain.emit(
channel,
{
sender: {
send: (..._args: unknown[]) => {
}, },
}, },
{ type: 'request', callbackId: uuid, eventName }, },
apiArgs, { type: 'request', callbackId: uuid, eventName },
) apiArgs,
}) )
]) })
} }

View File

@@ -15,8 +15,8 @@ export default class SendLike extends BaseAction<Payload, null> {
const qq = payload.user_id.toString() const qq = payload.user_id.toString()
const uid: string = await NTQQUserApi.getUidByUin(qq) || '' const uid: string = await NTQQUserApi.getUidByUin(qq) || ''
const result = await NTQQUserApi.like(uid, parseInt(payload.times?.toString()) || 1) const result = await NTQQUserApi.like(uid, parseInt(payload.times?.toString()) || 1)
if (result.result !== 0) { if (result?.result !== 0) {
throw Error(result.errMsg) throw Error(result?.errMsg)
} }
} catch (e) { } catch (e) {
throw `点赞失败 ${e}` throw `点赞失败 ${e}`

View File

@@ -170,8 +170,7 @@ export class OB11Constructor {
if ((!replyMsg || records.msgRandom !== replyMsg.msgRandom) && msg.peerUin !== '284840486') { if ((!replyMsg || records.msgRandom !== replyMsg.msgRandom) && msg.peerUin !== '284840486') {
throw new Error('回复消息消息验证失败') throw new Error('回复消息消息验证失败')
} }
if (!replyMsg) throw new Error('找不到回复消息') message_data['data']['id'] = replyMsg && MessageUnique.createMsg({
message_data['data']['id'] = MessageUnique.createMsg({
peerUid: msg.peerUid, peerUid: msg.peerUid,
guildId: '', guildId: '',
chatType: msg.chatType, chatType: msg.chatType,