From 12b947523a0166bd75c21e7daa1638b24db05cb9 Mon Sep 17 00:00:00 2001 From: Ctrlcvs <1509167646@qq.com> Date: Fri, 19 Aug 2022 17:39:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3stoken=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=AD=BE=E5=88=B0salt=E8=87=B33.35.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/sign.js | 10 ++++----- model/gsCfg.js | 47 +++++++++++++++++++++++++++-------------- model/mys/mihoyo-api.js | 22 +++++++++---------- 3 files changed, 45 insertions(+), 34 deletions(-) diff --git a/apps/sign.js b/apps/sign.js index c8e39dc..86aee8a 100644 --- a/apps/sign.js +++ b/apps/sign.js @@ -123,7 +123,7 @@ export async function mysSign(e) { let iscount = ""; let miHoYoApi = new MihoYoApi(e); let stokens=await miHoYoApi.getStoken(e.user_id) - if (!stokens) { + if (Object.keys(stokens).length>0) { e.reply("未读取到stoken请检查cookies是否包含login_ticket、以及云崽是否为最新版本V3、V2兼容") return true; } @@ -233,7 +233,7 @@ export async function bbsSeach(e){ } let miHoYoApi = new MihoYoApi(e); let stokens=await miHoYoApi.getStoken(e.user_id) - if (!stokens) { + if (Object.keys(stokens).length>0) { let cookiesDoc = await getcookiesDoc() await replyMsg(e, "未读取到stoken请检查cookies是否包含login_ticket,请先绑定stoken再查询~\n"+cookiesDoc); return true; @@ -288,13 +288,12 @@ async function cookie(e) { } = await getCookie(e); let miHoYoApi = new MihoYoApi(e); let cookiesDoc = await getcookiesDoc(); - if (!cookie) { e.reply("cookie失效请重新绑定~【教程】\n" + cookiesDoc) return false; } -let stokens=miHoYoApi.getStoken(e.user_id) - if (!stokens) { + let stokens=miHoYoApi.getStoken(e.user_id) + if (Object.keys(stokens).length>0) { return true; } if (!cookie.includes("login_ticket") && (isV3 && !skuid?.login_ticket)) { @@ -302,7 +301,6 @@ let stokens=miHoYoApi.getStoken(e.user_id) return false; } let flot = (await miHoYoApi.stoken(cookie, e)); - // console.log(flot) await utils.sleepAsync(1000); //延迟加载防止文件未生成 if (!flot) { e.reply("登录失效请重新登录获取cookie发送机器人~") diff --git a/model/gsCfg.js b/model/gsCfg.js index 1547574..5d38268 100644 --- a/model/gsCfg.js +++ b/model/gsCfg.js @@ -5,7 +5,9 @@ import { promisify } from 'node:util' import lodash from 'lodash' - +import { + Data +} from "../components/index.js"; const plugin = "xiaoyao-cvs-plugin" /** 配置文件 */ class GsCfg { @@ -47,9 +49,9 @@ class GsCfg { } } /** 通用yaml读取*/ - getfileYaml(path,name){ + getfileYaml(path, name) { return YAML.parse( - fs.readFileSync(path+name+".yaml", 'utf8') + fs.readFileSync(path + name + ".yaml", 'utf8') ) } /** @@ -133,7 +135,7 @@ class GsCfg { ckQQ } } - /** 读取所有用户绑定的stoken */ + /** 读取所有用户绑定的stoken */ async getBingStoken() { let ck = [] let ckQQ = {} @@ -146,7 +148,7 @@ class GsCfg { files.forEach((v) => promises.push(readFile(`${dir}${v}`, 'utf8'))) const res = await Promise.all(promises) - res.forEach((v,index) => { + res.forEach((v, index) => { let tmp = YAML.parse(v) ck.push(tmp) }) @@ -167,14 +169,18 @@ class GsCfg { try { let ck = fs.readFileSync(file, 'utf-8') ck = YAML.parse(ck) - for(let item in ck){ + for (let item in ck) { let login_ticket; - if(!ck[item].isMain){ + if (!ck[item].isMain) { continue; } - login_ticket=ck[item]?.login_ticket - ck=ck[item].ck - return {ck,item,login_ticket}; + login_ticket = ck[item]?.login_ticket + ck = ck[item].ck + return { + ck, + item, + login_ticket + }; } } catch (error) { return {} @@ -189,16 +195,25 @@ class GsCfg { fs.writeFileSync(file, yaml, 'utf8') } } - saveBingStoken(userId, data) { + saveBingStoken(userId, data) { let file = `./plugins/${plugin}/data/yaml/${userId}.yaml` - console.log(data) - console.log(file) if (lodash.isEmpty(data)) { fs.existsSync(file) && fs.unlinkSync(file) } else { - let yaml = YAML.stringify(data) - - fs.writeFileSync(file, yaml, 'utf8') + fs.exists(file, (exists) => { + if (!exists) { + fs.writeFileSync(file, "", 'utf8') + } + let ck = fs.readFileSync(file, 'utf-8') + let yaml = YAML.stringify(data) + ck = YAML.parse(ck) + if (!ck) { + fs.writeFileSync(file, yaml, 'utf8') + } else { + ck = YAML.stringify(ck) + fs.writeFileSync(file, yaml + ck, 'utf8') + } + }) } } /** diff --git a/model/mys/mihoyo-api.js b/model/mys/mihoyo-api.js index 20a3a2b..2afb4dd 100644 --- a/model/mys/mihoyo-api.js +++ b/model/mys/mihoyo-api.js @@ -12,9 +12,10 @@ import { isV3 } from '../../components/Changelog.js'; import fetch from "node-fetch" -const APP_VERSION = "2.34.1"; -const salt = "z8DRIUjNDT7IT5IZXvrUAxyupA1peND9"; +const APP_VERSION = "2.35.2"; +const salt = "ZSHlXeQUBis52qD1kEgKt5lUYed4b7Bb"; const salt2="t0qEgfub6cvueAPgR5m9aQWWVciEer7v"; +const saltWeb="N50pqm7FSy2AkFz2B3TqtuZMJ5TOl3Ep"; //b253c83ab2609b1b600eddfe974df47b const DEVICE_ID = utils.randomString(32).toUpperCase(); const DEVICE_NAME = utils.randomString(_.random(1, 10)); @@ -266,8 +267,8 @@ export default class MihoYoApi { async stoken(cookie, e) { this.e = e; - let datalist=this.getStoken(e.user_id) - if (datalist){ + let datalist=this.getStoken(e.user_id) || {} + if (Object.keys(datalist).length>0){ return true; } const map = this.getCookieMap(cookie); @@ -297,7 +298,6 @@ export default class MihoYoApi { return false; } response.json().then(function(data) { - // console.log(data); if (!data.data) { return false; } @@ -306,12 +306,10 @@ export default class MihoYoApi { stoken: data.data.list[0].token, ltoken: data.data.list[1].token, uid: e.uid, - userId:this.e.user_id, + userId:e.user_id, is_sign:true } gsCfg.saveBingStoken(e.user_id,datalist) - // let yamlStr = YAML.stringify(datalist); - // fs.writeFileSync(`${YamlDataUrl}/${e.user_id}.yaml`, yamlStr, 'utf8'); return true; }); } @@ -325,7 +323,7 @@ export default class MihoYoApi { getpubHeaders(board) { const randomStr = utils.randomString(6); const timestamp = Math.floor(Date.now() / 1000) - let sign = md5(`salt=9nQiU3AV0rJSIBWgdynfoGMGKaklfbM7&t=${timestamp}&r=${randomStr}`); + let sign = md5(`salt=${saltWeb}&t=${timestamp}&r=${randomStr}`); return { 'accept-language': 'zh-CN,zh;q=0.9,ja-JP;q=0.8,ja;q=0.7,en-US;q=0.6,en;q=0.5', 'x-rpc-device_id': DEVICE_ID, @@ -333,7 +331,7 @@ export default class MihoYoApi { Referer: board.getReferer(), Host: 'api-takumi.mihoyo.com', 'x-rpc-channel': 'appstore', - 'x-rpc-app_version': '2.34.1', + 'x-rpc-app_version': APP_VERSION, 'x-requested-with': 'com.mihoyo.hyperion', 'x-rpc-client_type': '5', 'Content-Type': 'application/json;charset=UTF-8', @@ -371,7 +369,7 @@ export default class MihoYoApi { 'x-rpc-client_type': '2', // 1 - iOS, 2 - Android, 4 - Web 'DS': ds, "Referer": "https://app.mihoyo.com", - "x-rpc-sys_version": "6.0.1", + "x-rpc-sys_version": "12", "Host": "bbs-api.mihoyo.com", "User-Agent": "okhttp/4.8.0", // 'DS': `1602569298,k0xfEh,07f4545f5d88eac59cb1257aef74a570` @@ -421,7 +419,7 @@ export default class MihoYoApi { ck=datalist gsCfg.saveBingStoken(this.e.user_id,datalist) } - return ck[this.e.uid] + return ck[this.e.uid]||{} } catch (error) { return {} }