From c5b888f322e53afd23f13499405d767265481028 Mon Sep 17 00:00:00 2001 From: Ctrlcvs <1509167646@qq.com> Date: Fri, 29 Jul 2022 09:59:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6=E6=9C=AA?= =?UTF-8?q?=E8=AF=BB=E5=86=99=E5=AF=BC=E8=87=B4=E6=97=A0=E6=B3=95=E5=AD=98?= =?UTF-8?q?=E5=85=A5stoken=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/sign.js | 19 ++++++++++++++++--- model/mys/mihoyo-api.js | 5 ++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/apps/sign.js b/apps/sign.js index 17dd056..bb9ebd2 100644 --- a/apps/sign.js +++ b/apps/sign.js @@ -32,11 +32,16 @@ const RETRY_OPTIONS = { maxTimeout: 10000 }; export async function sign(e) { - if (!(await cookie(e))) { + let isck=await cookie(e); + if (!isck) { return true; } START = moment().unix(); let miHoYoApi = new MihoYoApi(e); + if(Object.keys((await miHoYoApi.getStoken(e.user_id))).length == 0){ + e.reply("未读取到stoken请尝试重新登录获取cookies") + return true; + } let resultMessage=""; let msg = e.msg.replace(/#|签到|井|米游社|mys|社区/g, ""); let ForumData = await getDataList(msg); @@ -64,11 +69,17 @@ export async function sign(e) { return true } export async function mysSign(e) { - if (!(await cookie(e))) { + let isck=await cookie(e); + if (!isck) { + return true; + } + let iscount=""; + let miHoYoApi = new MihoYoApi(e); + if(Object.keys((await miHoYoApi.getStoken(e.user_id))).length == 0){ + e.reply("未读取到stoken请尝试重新登录获取cookies") return true; } START = moment().unix(); - let miHoYoApi = new MihoYoApi(e); let resultMessage=""; // Execute task let msg = e.msg.replace(/#|签到|井|米游社|mys|社区/g, ""); @@ -173,6 +184,8 @@ async function cookie(e) { return false; } let flot = (await miHoYoApi.stoken(cookie, e)); + // console.log(flot) + await utils.sleepAsync(1000); //延迟加载防止文件未生成 if (!flot) { e.reply("登录失效请重新登录获取cookie发送机器人~") return false; diff --git a/model/mys/mihoyo-api.js b/model/mys/mihoyo-api.js index 517e40c..d4d99b3 100644 --- a/model/mys/mihoyo-api.js +++ b/model/mys/mihoyo-api.js @@ -68,7 +68,7 @@ export default class MihoYoApi { } async stoken(cookie, e) { this.e=e; - if(this.getStoken(e.user_id)){ + if(Object.keys(this.getStoken(e.user_id)).length != 0){ return true; } const map = this.getCookieMap(cookie); @@ -96,6 +96,9 @@ export default class MihoYoApi { } response.json().then(function(data) { // console.log(data); + if(!data.data){ + return false; + } let datalist = { stuid: map.get("account_id"), stoken: data.data.list[0].token,