mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
test pskey
This commit is contained in:
@@ -75,7 +75,7 @@ export class NTQQGroupApi{
|
|||||||
}
|
}
|
||||||
static async getGroupIgnoreNotifies() {
|
static async getGroupIgnoreNotifies() {
|
||||||
await NTQQGroupApi.getGroupNotifies();
|
await NTQQGroupApi.getGroupNotifies();
|
||||||
return await NTQQWindowApi.openWindow(NTQQWindows.GroupNotifyFilterWindow, ReceiveCmdS.GROUP_NOTIFY);
|
return await NTQQWindowApi.openWindow(NTQQWindows.GroupNotifyFilterWindow,[], ReceiveCmdS.GROUP_NOTIFY);
|
||||||
}
|
}
|
||||||
static async handleGroupRequest(seq: string, operateType: GroupRequestOperateTypes, reason?: string) {
|
static async handleGroupRequest(seq: string, operateType: GroupRequestOperateTypes, reason?: string) {
|
||||||
const notify: GroupNotify = await dbUtil.getGroupNotify(seq)
|
const notify: GroupNotify = await dbUtil.getGroupNotify(seq)
|
||||||
|
84
src/ntqqapi/api/webapi.ts
Normal file
84
src/ntqqapi/api/webapi.ts
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
import {net, session} from "electron";
|
||||||
|
import {NTQQApi} from "../ntcall";
|
||||||
|
import {groups} from "../../common/data";
|
||||||
|
import {log} from "../../common/utils";
|
||||||
|
|
||||||
|
export class WebApi{
|
||||||
|
private static bkn: string;
|
||||||
|
private static skey: string;
|
||||||
|
private static pskey: string;
|
||||||
|
private static cookie: string
|
||||||
|
private defaultHeaders: Record<string,string> = {
|
||||||
|
"User-Agent": "QQ/8.9.28.635 CFNetwork/1312 Darwin/21.0.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public async addGroupDigest(groupCode: string, msgSeq: string){
|
||||||
|
const url = `https://qun.qq.com/cgi-bin/group_digest/cancel_digest?random=665&X-CROSS-ORIGIN=fetch&group_code=${groupCode}&msg_seq=${msgSeq}&msg_random=444021292`
|
||||||
|
const res = await this.request(url)
|
||||||
|
return await res.json()
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getGroupDigest(groupCode: string){
|
||||||
|
const url = `https://qun.qq.com/cgi-bin/group_digest/digest_list?random=665&X-CROSS-ORIGIN=fetch&group_code=${groupCode}&page_start=0&page_limit=20`
|
||||||
|
const res = await this.request(url)
|
||||||
|
return await res.json()
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
private async init(){
|
||||||
|
if (!WebApi.bkn) {
|
||||||
|
const group = groups[0];
|
||||||
|
WebApi.skey = (await NTQQApi.getSkey(group.groupName, group.groupCode)).data;
|
||||||
|
WebApi.bkn = this.genBkn(WebApi.skey);
|
||||||
|
let cookie = await NTQQApi.getPSkey();
|
||||||
|
const pskeyRegex = /p_skey=([^;]+)/;
|
||||||
|
const match = cookie.match(pskeyRegex);
|
||||||
|
const pskeyValue = match ? match[1] : null;
|
||||||
|
WebApi.pskey = pskeyValue;
|
||||||
|
cookie = cookie.replace(/skey=.*?/, `skey=${WebApi.skey}`);
|
||||||
|
WebApi.cookie = cookie;
|
||||||
|
// for(const kv of WebApi.cookie.split(";")){
|
||||||
|
// const [key, value] = kv.split("=");
|
||||||
|
// }
|
||||||
|
// log("set cookie", key, value)
|
||||||
|
// await session.defaultSession.cookies.set({
|
||||||
|
// url: 'https://qun.qq.com', // 你要请求的域名
|
||||||
|
// name: key.trim(),
|
||||||
|
// value: value.trim(),
|
||||||
|
// expirationDate: Date.now() / 1000 + 300000, // Cookie 过期时间,例如设置为当前时间之后的300秒
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async request(url: string, method: "GET" | "POST" = "GET", headers: Record<string, string> = {}){
|
||||||
|
|
||||||
|
await this.init();
|
||||||
|
url += "&bkn=" + WebApi.bkn;
|
||||||
|
let _headers: Record<string, string> = {
|
||||||
|
...this.defaultHeaders, ...headers,
|
||||||
|
"Cookie": WebApi.cookie,
|
||||||
|
// credentials: 'include'
|
||||||
|
}
|
||||||
|
log("request", url, _headers)
|
||||||
|
const options = {
|
||||||
|
method: method,
|
||||||
|
headers: _headers
|
||||||
|
}
|
||||||
|
return fetch(url, options)
|
||||||
|
}
|
||||||
|
}
|
@@ -2,7 +2,7 @@ import {callNTQQApi, GeneralCallResult, NTQQApiClass, NTQQApiMethod} from "../nt
|
|||||||
import {ReceiveCmd} from "../hook";
|
import {ReceiveCmd} from "../hook";
|
||||||
import {BrowserWindow} from "electron";
|
import {BrowserWindow} from "electron";
|
||||||
|
|
||||||
interface NTQQWindow{
|
export interface NTQQWindow{
|
||||||
windowName: string,
|
windowName: string,
|
||||||
windowUrlHash: string,
|
windowUrlHash: string,
|
||||||
}
|
}
|
||||||
@@ -16,13 +16,17 @@ export class NTQQWindows{
|
|||||||
windowName: "GroupNotifyFilterWindow",
|
windowName: "GroupNotifyFilterWindow",
|
||||||
windowUrlHash: "#/group-notify-filter"
|
windowUrlHash: "#/group-notify-filter"
|
||||||
}
|
}
|
||||||
|
static GroupEssenceWindow: NTQQWindow = {
|
||||||
|
windowName: "GroupEssenceWindow",
|
||||||
|
windowUrlHash: "#/group-essence"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class NTQQWindowApi{
|
export class NTQQWindowApi{
|
||||||
|
|
||||||
// 打开窗口并获取对应的下发事件
|
// 打开窗口并获取对应的下发事件
|
||||||
static async openWindow(ntQQWindow: NTQQWindow, args: any[], cbCmd: ReceiveCmd=null, autoCloseSeconds: number=2){
|
static async openWindow<R=GeneralCallResult>(ntQQWindow: NTQQWindow, args: any[], cbCmd: ReceiveCmd=null, autoCloseSeconds: number=2){
|
||||||
const result = await callNTQQApi<GeneralCallResult>({
|
const result = await callNTQQApi<R>({
|
||||||
className: NTQQApiClass.WINDOW_API,
|
className: NTQQApiClass.WINDOW_API,
|
||||||
methodName: NTQQApiMethod.OPEN_EXTRA_WINDOW,
|
methodName: NTQQApiMethod.OPEN_EXTRA_WINDOW,
|
||||||
cbCmd,
|
cbCmd,
|
||||||
|
@@ -61,12 +61,18 @@ let receiveHooks: Array<{
|
|||||||
export function hookNTQQApiReceive(window: BrowserWindow) {
|
export function hookNTQQApiReceive(window: BrowserWindow) {
|
||||||
const originalSend = window.webContents.send;
|
const originalSend = window.webContents.send;
|
||||||
const patchSend = (channel: string, ...args: NTQQApiReturnData) => {
|
const patchSend = (channel: string, ...args: NTQQApiReturnData) => {
|
||||||
|
let isLogger = false
|
||||||
try {
|
try {
|
||||||
if (!args[0]?.eventName?.startsWith("ns-LoggerApi")) {
|
isLogger = args[0]?.eventName?.startsWith("ns-LoggerApi")
|
||||||
HOOK_LOG && log(`received ntqq api message: ${channel}`, JSON.stringify(args))
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
if (!isLogger) {
|
||||||
|
try {
|
||||||
|
HOOK_LOG && log(`received ntqq api message: ${channel}`, JSON.stringify(args))
|
||||||
|
}catch (e) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (args?.[1] instanceof Array) {
|
if (args?.[1] instanceof Array) {
|
||||||
for (let receiveData of args?.[1]) {
|
for (let receiveData of args?.[1]) {
|
||||||
@@ -111,12 +117,18 @@ export function hookNTQQApiCall(window: BrowserWindow) {
|
|||||||
|
|
||||||
const proxyIpcMsg = new Proxy(ipc_message_proxy, {
|
const proxyIpcMsg = new Proxy(ipc_message_proxy, {
|
||||||
apply(target, thisArg, args) {
|
apply(target, thisArg, args) {
|
||||||
|
let isLogger = false
|
||||||
try {
|
try {
|
||||||
if (args[3][1][0] !== "info") {
|
isLogger = args[3][0].eventName.startsWith("ns-LoggerApi")
|
||||||
HOOK_LOG && log("call NTQQ api", thisArg, args);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
if (!isLogger) {
|
||||||
|
try{
|
||||||
|
HOOK_LOG && log("call NTQQ api", thisArg, args);
|
||||||
|
}catch (e) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return target.apply(thisArg, args);
|
return target.apply(thisArg, args);
|
||||||
},
|
},
|
||||||
|
@@ -3,7 +3,9 @@ import {hookApiCallbacks, ReceiveCmd, ReceiveCmdS, registerReceiveHook, removeRe
|
|||||||
|
|
||||||
import {v4 as uuidv4} from "uuid"
|
import {v4 as uuidv4} from "uuid"
|
||||||
import {log} from "../common/utils/log";
|
import {log} from "../common/utils/log";
|
||||||
import {NTQQWindowApi, NTQQWindows} from "./api/window";
|
import {NTQQWindow, NTQQWindowApi, NTQQWindows} from "./api/window";
|
||||||
|
import {WebApi} from "./api/webapi";
|
||||||
|
import {HOOK_LOG} from "../common/config";
|
||||||
|
|
||||||
export enum NTQQApiClass {
|
export enum NTQQApiClass {
|
||||||
NT_API = "ns-ntApi",
|
NT_API = "ns-ntApi",
|
||||||
@@ -14,7 +16,8 @@ export enum NTQQApiClass {
|
|||||||
BUSINESS_API = "ns-BusinessApi",
|
BUSINESS_API = "ns-BusinessApi",
|
||||||
GLOBAL_DATA = "ns-GlobalDataApi",
|
GLOBAL_DATA = "ns-GlobalDataApi",
|
||||||
SKEY_API = "ns-SkeyApi",
|
SKEY_API = "ns-SkeyApi",
|
||||||
HOME_WORK = "ns-GroupHomeWork"
|
GROUP_HOME_WORK = "ns-GroupHomeWork",
|
||||||
|
GROUP_ESSENCE = "ns-GroupEssence",
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum NTQQApiMethod {
|
export enum NTQQApiMethod {
|
||||||
@@ -103,7 +106,7 @@ export function callNTQQApi<ReturnType>(params: NTQQApiParams) {
|
|||||||
timeout = timeout ?? 5;
|
timeout = timeout ?? 5;
|
||||||
afterFirstCmd = afterFirstCmd ?? true;
|
afterFirstCmd = afterFirstCmd ?? true;
|
||||||
const uuid = uuidv4();
|
const uuid = uuidv4();
|
||||||
// log("callNTQQApi", channel, className, methodName, args, uuid)
|
HOOK_LOG && log("callNTQQApi", channel, className, methodName, args, uuid)
|
||||||
return new Promise((resolve: (data: ReturnType) => void, reject) => {
|
return new Promise((resolve: (data: ReturnType) => void, reject) => {
|
||||||
// log("callNTQQApiPromise", channel, className, methodName, args, uuid)
|
// log("callNTQQApiPromise", channel, className, methodName, args, uuid)
|
||||||
const _timeout = timeout * 1000
|
const _timeout = timeout * 1000
|
||||||
@@ -183,21 +186,21 @@ export class NTQQApi {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getSkey(groupCode: string, groupName: string) {
|
static async getSkey(groupName: string, groupCode: string): Promise<{data: string}> {
|
||||||
await NTQQWindowApi.openWindow(NTQQWindows.GroupHomeWorkWindow, [{
|
return await NTQQWindowApi.openWindow<{data: string}>(NTQQWindows.GroupHomeWorkWindow, [{
|
||||||
groupName,
|
groupName,
|
||||||
groupCode,
|
groupCode,
|
||||||
"source": "funcbar"
|
"source": "funcbar"
|
||||||
}], ReceiveCmdS.SKEY_UPDATE, 1);
|
}], ReceiveCmdS.SKEY_UPDATE, 1);
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
// return await callNTQQApi<string>({
|
||||||
className: NTQQApiClass.HOME_WORK,
|
// className: NTQQApiClass.GROUP_HOME_WORK,
|
||||||
methodName: NTQQApiMethod.UPDATE_SKEY,
|
// methodName: NTQQApiMethod.UPDATE_SKEY,
|
||||||
args: [
|
// args: [
|
||||||
{
|
// {
|
||||||
domain: "qun.qq.com"
|
// domain: "qun.qq.com"
|
||||||
}
|
// }
|
||||||
]
|
// ]
|
||||||
})
|
// })
|
||||||
// return await callNTQQApi<GeneralCallResult>({
|
// return await callNTQQApi<GeneralCallResult>({
|
||||||
// methodName: NTQQApiMethod.GET_SKEY,
|
// methodName: NTQQApiMethod.GET_SKEY,
|
||||||
// args: [
|
// args: [
|
||||||
@@ -218,9 +221,9 @@ export class NTQQApi {
|
|||||||
// })
|
// })
|
||||||
}
|
}
|
||||||
|
|
||||||
static async updateSkey() {
|
static async getPSkey() {
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
return await callNTQQApi<string>({
|
||||||
className: NTQQApiClass.HOME_WORK,
|
className: NTQQApiClass.GROUP_HOME_WORK,
|
||||||
methodName: NTQQApiMethod.UPDATE_SKEY,
|
methodName: NTQQApiMethod.UPDATE_SKEY,
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
@@ -230,4 +233,11 @@ export class NTQQApi {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async addGroupDigest(groupCode: string, msgSeq: string) {
|
||||||
|
return await new WebApi().addGroupDigest(groupCode, msgSeq);
|
||||||
|
}
|
||||||
|
|
||||||
|
static async getGroupDigest(groupCode: string) {
|
||||||
|
return await new WebApi().getGroupDigest(groupCode);
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user