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:
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 4,
|
"manifest_version": 4,
|
||||||
"type": "extension",
|
"type": "extension",
|
||||||
"name": "LLOneBot v3.22.1",
|
"name": "LLOneBot v3.23.0",
|
||||||
"slug": "LLOneBot",
|
"slug": "LLOneBot",
|
||||||
"description": "使你的NTQQ支持OneBot11协议进行QQ机器人开发, 不支持商店在线更新",
|
"description": "使你的NTQQ支持OneBot11协议进行QQ机器人开发, 不支持商店在线更新",
|
||||||
"version": "3.22.1",
|
"version": "3.23.0",
|
||||||
"icon": "./icon.jpg",
|
"icon": "./icon.jpg",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
import {callNTQQApi, GeneralCallResult, NTQQApiClass, NTQQApiMethod} from "../ntcall";
|
import {callNTQQApi, GeneralCallResult, NTQQApiClass, NTQQApiMethod} from "../ntcall";
|
||||||
import {SelfInfo, User} from "../types";
|
import {Group, SelfInfo, User} from "../types";
|
||||||
import {ReceiveCmdS} from "../hook";
|
import {ReceiveCmdS} from "../hook";
|
||||||
import {uidMaps} from "../../common/data";
|
import {selfInfo, uidMaps} from "../../common/data";
|
||||||
import {NTQQWindowApi, NTQQWindows} from "./window";
|
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
|
let userInfoCache: Record<string, User> = {}; // uid: User
|
||||||
|
|
||||||
@@ -68,7 +68,8 @@ export class NTQQUserApi{
|
|||||||
return userInfo
|
return userInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getPSkey() {
|
// return 'p_uin=o0xxx; p_skey=orXDssiGF8axxxxxxxxxxxxxx_; skey='
|
||||||
|
static async getCookieWithoutSkey() {
|
||||||
return await callNTQQApi<string>({
|
return await callNTQQApi<string>({
|
||||||
className: NTQQApiClass.GROUP_HOME_WORK,
|
className: NTQQApiClass.GROUP_HOME_WORK,
|
||||||
methodName: NTQQApiMethod.UPDATE_SKEY,
|
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){
|
private genBkn(sKey: string){
|
||||||
sKey = sKey || "";
|
return NTQQUserApi.genBkn(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();
|
|
||||||
}
|
}
|
||||||
private async init(){
|
private async init(){
|
||||||
if (!WebApi.bkn) {
|
if (!WebApi.bkn) {
|
||||||
const group = groups[0];
|
const group = groups[0];
|
||||||
WebApi.skey = (await NTQQUserApi.getSkey(group.groupName, group.groupCode)).data;
|
WebApi.skey = (await NTQQUserApi.getSkey(group.groupName, group.groupCode)).data;
|
||||||
WebApi.bkn = this.genBkn(WebApi.skey);
|
WebApi.bkn = this.genBkn(WebApi.skey);
|
||||||
let cookie = await NTQQUserApi.getPSkey();
|
let cookie = await NTQQUserApi.getCookieWithoutSkey();
|
||||||
const pskeyRegex = /p_skey=([^;]+)/;
|
const pskeyRegex = /p_skey=([^;]+)/;
|
||||||
const match = cookie.match(pskeyRegex);
|
const match = cookie.match(pskeyRegex);
|
||||||
const pskeyValue = match ? match[1] : null;
|
const pskeyValue = match ? match[1] : null;
|
||||||
|
@@ -40,6 +40,7 @@ import GoCQHTTPDownloadFile from "./go-cqhttp/DownloadFile";
|
|||||||
import GoCQHTTPGetGroupMsgHistory from "./go-cqhttp/GetGroupMsgHistory";
|
import GoCQHTTPGetGroupMsgHistory from "./go-cqhttp/GetGroupMsgHistory";
|
||||||
import GetFile from "./file/GetFile";
|
import GetFile from "./file/GetFile";
|
||||||
import {GoCQHTTGetForwardMsgAction} from "./go-cqhttp/GetForwardMsg";
|
import {GoCQHTTGetForwardMsgAction} from "./go-cqhttp/GetForwardMsg";
|
||||||
|
import {GetCookies} from "./user/GetCookie";
|
||||||
|
|
||||||
export const actionHandlers = [
|
export const actionHandlers = [
|
||||||
new GetFile(),
|
new GetFile(),
|
||||||
@@ -72,7 +73,7 @@ export const actionHandlers = [
|
|||||||
new GetImage(),
|
new GetImage(),
|
||||||
new GetRecord(),
|
new GetRecord(),
|
||||||
new CleanCache(),
|
new CleanCache(),
|
||||||
|
new GetCookies(),
|
||||||
//以下为go-cqhttp api
|
//以下为go-cqhttp api
|
||||||
new GoCQHTTPSendForwardMsg(),
|
new GoCQHTTPSendForwardMsg(),
|
||||||
new GoCQHTTPSendGroupForwardMsg(),
|
new GoCQHTTPSendGroupForwardMsg(),
|
||||||
|
@@ -50,6 +50,7 @@ export enum ActionName {
|
|||||||
GetImage = "get_image",
|
GetImage = "get_image",
|
||||||
GetRecord = "get_record",
|
GetRecord = "get_record",
|
||||||
CleanCache = "clean_cache",
|
CleanCache = "clean_cache",
|
||||||
|
GetCookies = "get_cookies",
|
||||||
// 以下为go-cqhttp api
|
// 以下为go-cqhttp api
|
||||||
GoCQHTTP_SendForwardMsg = "send_forward_msg",
|
GoCQHTTP_SendForwardMsg = "send_forward_msg",
|
||||||
GoCQHTTP_SendGroupForwardMsg = "send_group_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"
|
Reference in New Issue
Block a user