mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-16 21:09:23 +00:00
feat: Packet Rkey
This commit is contained in:
parent
d21da47a7d
commit
f91991e25c
@ -375,17 +375,24 @@ export class NTQQFileApi {
|
||||
group_rkey: 'CAQSKAB6JWENi5LM_xp9vumLbuThJSaYf-yzMrbZsuq7Uz2qffcqm614gds',
|
||||
online_rkey: false
|
||||
};
|
||||
|
||||
try {
|
||||
let tempRkeyData = await this.rkeyManager.getRkey();
|
||||
rkeyData.group_rkey = tempRkeyData.group_rkey;
|
||||
rkeyData.private_rkey = tempRkeyData.private_rkey;
|
||||
rkeyData.online_rkey = tempRkeyData.expired_time > Date.now() / 1000;
|
||||
} catch (e) {
|
||||
this.context.logger.logError.bind(this.context.logger)('获取rkey失败 Fallback Old Mode', e);
|
||||
if (this.core.apis.PacketApi.PacketClient?.isConnected) {
|
||||
let rkeylist = await this.core.apis.PacketApi.sendRkeyPacket();
|
||||
if (rkeylist.length > 0) {
|
||||
rkeyData.group_rkey = rkeylist[0].rkey;
|
||||
rkeyData.private_rkey = rkeylist[1].rkey;
|
||||
rkeyData.online_rkey = true;
|
||||
}
|
||||
}
|
||||
if (!rkeyData.online_rkey) {
|
||||
try {
|
||||
let tempRkeyData = await this.rkeyManager.getRkey();
|
||||
rkeyData.group_rkey = tempRkeyData.group_rkey;
|
||||
rkeyData.private_rkey = tempRkeyData.private_rkey;
|
||||
rkeyData.online_rkey = tempRkeyData.expired_time > Date.now() / 1000;
|
||||
} catch (e) {
|
||||
this.context.logger.logError.bind(this.context.logger)('获取rkey失败 Fallback Old Mode', e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (isNTV2 && urlRkey) {
|
||||
return IMAGE_HTTP_HOST_NT + urlRkey;
|
||||
} else if (isNTV2 && rkeyData.online_rkey) {
|
||||
|
@ -4,8 +4,8 @@ import offset from '@/core/external/offset.json';
|
||||
import * as crypto from 'crypto';
|
||||
import { PacketClient } from '../helper/packet';
|
||||
import { NapProtoMsg } from '../proto/NapProto';
|
||||
import { OidbSvcTrpcTcp0X9067_202 } from '../proto/oidb/Oidb.0x9067_202';
|
||||
import { OidbSvcTrpcTcpBase } from '../proto/oidb/OidbBase';
|
||||
import { OidbSvcTrpcTcp0X9067_202, OidbSvcTrpcTcp0X9067_202_Rsp_Body } from '../proto/oidb/Oidb.0x9067_202';
|
||||
import { OidbSvcTrpcTcpBase, OidbSvcTrpcTcpBaseRsp } from '../proto/oidb/OidbBase';
|
||||
import { OidbSvcTrpcTcp0XFE1_2, OidbSvcTrpcTcp0XFE1_2RSP } from '../proto/oidb/Oidb.fe1_2';
|
||||
import { OidbSvcTrpcTcp0X8FC_2, OidbSvcTrpcTcp0X8FC_2_Body } from '../proto/oidb/Oidb.0x8FC_2';
|
||||
|
||||
@ -71,6 +71,16 @@ export class NTQQPacketApi {
|
||||
}).then((res) => resolve(res)).catch((e) => reject(e));
|
||||
});
|
||||
}
|
||||
async sendRkeyPacket() {
|
||||
let u8 = await this.core.apis.PacketApi.buildRkeyPacket()
|
||||
let ret = await this.core.apis.PacketApi.sendPacket('OidbSvcTrpcTcp.0x9067_202', Buffer.from(u8).toString('hex'), true);
|
||||
if(!ret?.hex_data) return []
|
||||
let body = new NapProtoMsg(OidbSvcTrpcTcpBaseRsp).decode(Buffer.from(ret.hex_data,'hex')).body;
|
||||
//console.log('ret: ', Buffer.from(body).toString('hex'));
|
||||
let retdata = new NapProtoMsg(OidbSvcTrpcTcp0X9067_202_Rsp_Body).decode(body)
|
||||
//console.log('ret: ', JSON.stringify(retdata.data.rkeyList));
|
||||
return retdata.data.rkeyList;
|
||||
}
|
||||
async buildRkeyPacket() {
|
||||
let oidb_0x9067_202 = new NapProtoMsg(OidbSvcTrpcTcp0X9067_202).encode({
|
||||
reqHead: {
|
||||
|
@ -2,6 +2,7 @@ import { ScalarType } from "@protobuf-ts/runtime";
|
||||
import { ProtoField } from "../NapProto";
|
||||
import { MultiMediaReqHead } from "./common/Ntv2.RichMedia";
|
||||
|
||||
//Req
|
||||
export const OidbSvcTrpcTcp0X9067_202 = {
|
||||
ReqHead: ProtoField(1, () => MultiMediaReqHead),
|
||||
DownloadRKeyReq: ProtoField(4, () => OidbSvcTrpcTcp0X9067_202Key),
|
||||
@ -9,3 +10,17 @@ export const OidbSvcTrpcTcp0X9067_202 = {
|
||||
export const OidbSvcTrpcTcp0X9067_202Key = {
|
||||
key: ProtoField(1, ScalarType.INT32, false, true),
|
||||
}
|
||||
|
||||
//Rsp
|
||||
export const OidbSvcTrpcTcp0X9067_202_RkeyList = {
|
||||
rkey: ProtoField(1, ScalarType.STRING),
|
||||
time: ProtoField(4, ScalarType.UINT32),
|
||||
type: ProtoField(5, ScalarType.UINT32),
|
||||
|
||||
}
|
||||
export const OidbSvcTrpcTcp0X9067_202_Data = {
|
||||
rkeyList: ProtoField(1, () => OidbSvcTrpcTcp0X9067_202_RkeyList, false, true),
|
||||
}
|
||||
export const OidbSvcTrpcTcp0X9067_202_Rsp_Body = {
|
||||
data: ProtoField(4, () => OidbSvcTrpcTcp0X9067_202_Data),
|
||||
}
|
@ -8,3 +8,6 @@ export const OidbSvcTrpcTcpBase = {
|
||||
errorMsg: ProtoField(5, ScalarType.STRING, true),
|
||||
isReserved: ProtoField(12, ScalarType.UINT32)
|
||||
}
|
||||
export const OidbSvcTrpcTcpBaseRsp = {
|
||||
body: ProtoField(4, ScalarType.BYTES)
|
||||
}
|
23
src/onebot/action/extends/GetRkey.ts
Normal file
23
src/onebot/action/extends/GetRkey.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
// no_cache get时传字符串
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
},
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class GetUserStatus extends BaseAction<Payload, Array<any>> {
|
||||
actionName = ActionName.GetUserStatus;
|
||||
payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
if (!this.core.apis.PacketApi.PacketClient?.isConnected) {
|
||||
throw new Error('PacketClient is not init');
|
||||
}
|
||||
return await this.core.apis.PacketApi.sendRkeyPacket();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user