mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
feat: get cookies
This commit is contained in:
parent
019b590f36
commit
5562a3251d
@ -1,10 +1,10 @@
|
||||
{
|
||||
"manifest_version": 4,
|
||||
"type": "extension",
|
||||
"name": "LLOneBot v3.22.1",
|
||||
"name": "LLOneBot v3.23.0",
|
||||
"slug": "LLOneBot",
|
||||
"description": "使你的NTQQ支持OneBot11协议进行QQ机器人开发, 不支持商店在线更新",
|
||||
"version": "3.22.1",
|
||||
"version": "3.23.0",
|
||||
"icon": "./icon.jpg",
|
||||
"authors": [
|
||||
{
|
||||
|
@ -1,9 +1,9 @@
|
||||
import {callNTQQApi, GeneralCallResult, NTQQApiClass, NTQQApiMethod} from "../ntcall";
|
||||
import {SelfInfo, User} from "../types";
|
||||
import {Group, SelfInfo, User} from "../types";
|
||||
import {ReceiveCmdS} from "../hook";
|
||||
import {uidMaps} from "../../common/data";
|
||||
import {selfInfo, uidMaps} from "../../common/data";
|
||||
import {NTQQWindowApi, NTQQWindows} from "./window";
|
||||
import {isQQ998, sleep} from "../../common/utils";
|
||||
import {isQQ998, log, sleep} from "../../common/utils";
|
||||
|
||||
let userInfoCache: Record<string, User> = {}; // uid: User
|
||||
|
||||
@ -68,7 +68,8 @@ export class NTQQUserApi{
|
||||
return userInfo
|
||||
}
|
||||
|
||||
static async getPSkey() {
|
||||
// return 'p_uin=o0xxx; p_skey=orXDssiGF8axxxxxxxxxxxxxx_; skey='
|
||||
static async getCookieWithoutSkey() {
|
||||
return await callNTQQApi<string>({
|
||||
className: NTQQApiClass.GROUP_HOME_WORK,
|
||||
methodName: NTQQApiMethod.UPDATE_SKEY,
|
||||
@ -114,4 +115,34 @@ export class NTQQUserApi{
|
||||
// })
|
||||
}
|
||||
|
||||
static async getCookie(group: Group){
|
||||
let cookies = await this.getCookieWithoutSkey();
|
||||
let skey = ""
|
||||
for (let i = 0; i < 2; i++) {
|
||||
skey = (await this.getSkey(group.groupName, group.groupCode)).data;
|
||||
skey = skey.trim();
|
||||
if (skey) {
|
||||
break;
|
||||
}
|
||||
await sleep(1000);
|
||||
}
|
||||
if (!skey) {
|
||||
throw new Error("获取skey失败");
|
||||
}
|
||||
const bkn = NTQQUserApi.genBkn(skey);
|
||||
cookies = cookies.replace("skey=;", `skey=${skey};`);
|
||||
return {cookies, bkn};
|
||||
}
|
||||
|
||||
static genBkn(sKey: string){
|
||||
sKey = sKey || "";
|
||||
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();
|
||||
}
|
||||
}
|
@ -29,22 +29,14 @@ export class WebApi{
|
||||
}
|
||||
|
||||
private genBkn(sKey: string){
|
||||
sKey = sKey || "";
|
||||
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();
|
||||
return NTQQUserApi.genBkn(sKey);
|
||||
}
|
||||
private async init(){
|
||||
if (!WebApi.bkn) {
|
||||
const group = groups[0];
|
||||
WebApi.skey = (await NTQQUserApi.getSkey(group.groupName, group.groupCode)).data;
|
||||
WebApi.bkn = this.genBkn(WebApi.skey);
|
||||
let cookie = await NTQQUserApi.getPSkey();
|
||||
let cookie = await NTQQUserApi.getCookieWithoutSkey();
|
||||
const pskeyRegex = /p_skey=([^;]+)/;
|
||||
const match = cookie.match(pskeyRegex);
|
||||
const pskeyValue = match ? match[1] : null;
|
||||
|
@ -40,6 +40,7 @@ import GoCQHTTPDownloadFile from "./go-cqhttp/DownloadFile";
|
||||
import GoCQHTTPGetGroupMsgHistory from "./go-cqhttp/GetGroupMsgHistory";
|
||||
import GetFile from "./file/GetFile";
|
||||
import {GoCQHTTGetForwardMsgAction} from "./go-cqhttp/GetForwardMsg";
|
||||
import {GetCookies} from "./user/GetCookie";
|
||||
|
||||
export const actionHandlers = [
|
||||
new GetFile(),
|
||||
@ -72,7 +73,7 @@ export const actionHandlers = [
|
||||
new GetImage(),
|
||||
new GetRecord(),
|
||||
new CleanCache(),
|
||||
|
||||
new GetCookies(),
|
||||
//以下为go-cqhttp api
|
||||
new GoCQHTTPSendForwardMsg(),
|
||||
new GoCQHTTPSendGroupForwardMsg(),
|
||||
|
@ -50,6 +50,7 @@ export enum ActionName {
|
||||
GetImage = "get_image",
|
||||
GetRecord = "get_record",
|
||||
CleanCache = "clean_cache",
|
||||
GetCookies = "get_cookies",
|
||||
// 以下为go-cqhttp api
|
||||
GoCQHTTP_SendForwardMsg = "send_forward_msg",
|
||||
GoCQHTTP_SendGroupForwardMsg = "send_group_forward_msg",
|
||||
|
12
src/onebot11/action/user/GetCookie.ts
Normal file
12
src/onebot11/action/user/GetCookie.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import BaseAction from "../BaseAction";
|
||||
import {NTQQUserApi} from "../../../ntqqapi/api";
|
||||
import {groups} from "../../../common/data";
|
||||
import {ActionName} from "../types";
|
||||
|
||||
export class GetCookies extends BaseAction<null, {cookies: string, bkn: string}>{
|
||||
actionName = ActionName.GetCookies;
|
||||
|
||||
protected async _handle() {
|
||||
return NTQQUserApi.getCookie(groups[0])
|
||||
}
|
||||
}
|
@ -1 +1 @@
|
||||
export const version = "3.22.1"
|
||||
export const version = "3.23.0"
|
Loading…
x
Reference in New Issue
Block a user