mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
feat: 标准化凭据获取
This commit is contained in:
@@ -338,4 +338,12 @@ export class NTQQWebApi {
|
||||
}
|
||||
return (hash & 0x7FFFFFFF).toString();
|
||||
}
|
||||
public getBknFromSKey(sKey: string) {
|
||||
let hash = 5381;
|
||||
for (let i = 0; i < sKey.length; i++) {
|
||||
const code = sKey.charCodeAt(i);
|
||||
hash = hash + (hash << 5) + code;
|
||||
}
|
||||
return (hash & 0x7FFFFFFF).toString();
|
||||
}
|
||||
}
|
||||
|
@@ -92,6 +92,7 @@ import { GetGroupMemberList } from './group/GetGroupMemberList';
|
||||
import { GetGroupFileUrl } from "@/onebot/action/file/GetGroupFileUrl";
|
||||
import { GetPacketStatus } from "@/onebot/action/packet/GetPacketStatus";
|
||||
import { FriendPoke } from "@/onebot/action/user/FriendPoke";
|
||||
import { GetCredentials } from './system/GetCredentials';
|
||||
|
||||
|
||||
export type ActionMap = Map<string, BaseAction<any, any>>;
|
||||
@@ -180,6 +181,7 @@ export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCo
|
||||
new SetModelShow(obContext, core),
|
||||
new SetInputStatus(obContext, core),
|
||||
new GetCSRF(obContext, core),
|
||||
new GetCredentials(obContext, core),
|
||||
new DelGroupNotice(obContext, core),
|
||||
new DeleteGroupFile(obContext, core),
|
||||
new CreateGroupFileFolder(obContext, core),
|
||||
|
@@ -5,8 +5,12 @@ export class GetCSRF extends BaseAction<any, any> {
|
||||
actionName = ActionName.GetCSRF;
|
||||
|
||||
async _handle(payload: any) {
|
||||
const sKey = await this.core.apis.UserApi.getSKey();
|
||||
if (!sKey) {
|
||||
throw new Error('SKey is undefined');
|
||||
}
|
||||
return {
|
||||
token: '',
|
||||
token: +this.core.apis.WebApi.getBknFromSKey(sKey),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
31
src/onebot/action/system/GetCredentials.ts
Normal file
31
src/onebot/action/system/GetCredentials.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
interface Response {
|
||||
cookies: string,
|
||||
token: number
|
||||
}
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
domain: { type: 'string' },
|
||||
},
|
||||
required: ['domain'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class GetCredentials extends BaseAction<Payload, Response> {
|
||||
actionName = ActionName.GetCredentials;
|
||||
payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
const cookiesObject = await this.core.apis.UserApi.getCookies(payload.domain);
|
||||
//把获取到的cookiesObject转换成 k=v; 格式字符串拼接在一起
|
||||
const cookies = Object.entries(cookiesObject).map(([key, value]) => `${key}=${value}`).join('; ');
|
||||
const bkn = cookiesObject?.skey ? this.core.apis.WebApi.getBknFromCookie(cookiesObject) : '';
|
||||
return { cookies: cookies, token: +bkn };
|
||||
}
|
||||
}
|
@@ -43,8 +43,8 @@ export enum ActionName {
|
||||
GetGroupMemberList = 'get_group_member_list',
|
||||
GetGroupHonorInfo = 'get_group_honor_info',
|
||||
GetCookies = 'get_cookies',
|
||||
// GetCSRF = 'get_csrf_token',
|
||||
// GetCredentials = 'get_credentials',
|
||||
GetCSRF = 'get_csrf_token',
|
||||
GetCredentials = 'get_credentials',
|
||||
GetRecord = 'get_record',
|
||||
GetImage = 'get_image',
|
||||
CanSendImage = 'can_send_image',
|
||||
|
Reference in New Issue
Block a user