From 832c72da84ff2f305d84b3e81a60f2c881c04c7c Mon Sep 17 00:00:00 2001 From: Ctrlcvs <1509167646@qq.com> Date: Wed, 17 Aug 2022 23:07:34 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=99=A8=E9=A1=B5=E9=9D=A2=E6=88=AA=E5=9B=BE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adapter/render.js | 5 ++++- components/Common.js | 23 +++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/adapter/render.js b/adapter/render.js index 3ee70c2..4963368 100644 --- a/adapter/render.js +++ b/adapter/render.js @@ -9,10 +9,13 @@ const _path = process.cwd() export async function render (app = '', tpl = '', data = {}, imgType = 'jpeg') { // 在data中保存plugin信息 data._plugin = plugin - if (lodash.isUndefined(data._res_path)) { data._res_path = `../../../../../plugins/${plugin}/resources/` } + if(imgType == "png"){ + data.omitBackground=true; + } + data.imgType=imgType; Data.createDir(_path + '/data/', `html/${plugin}/${app}/${tpl}`) data.saveId = data.saveId || data.save_id || tpl data.tplFile = `./plugins/${plugin}/resources/${app}/${tpl}.html` diff --git a/components/Common.js b/components/Common.js index 55e37a0..c2238e0 100644 --- a/components/Common.js +++ b/components/Common.js @@ -1,15 +1,15 @@ import { Cfg } from "./index.js"; import { segment } from "oicq"; -import { currentVersion, yunzaiVersion } from "./Changelog.js"; -import {render1} from "../apps/render.js"; +import { currentVersion, yunzaiVersion,isV3 } from "./Changelog.js"; export const render = async function (path, params, cfg) { let paths = path.split("/"); let { render, e } = cfg; let _layout_path = process.cwd() + "/plugins/xiaoyao-cvs-plugin/resources/"; let layout_path= process.cwd() + "/plugins/xiaoyao-cvs-plugin/resources/common/layout/"; - let base64 = await render1(paths[0], paths[1], { + let base64 = await render(paths[0], paths[1], { ...params, _layout_path, + _tpl_path: process.cwd() + '/plugins/xiaoyao-cvs-plugin/resources/common/tpl/', defaultLayout: layout_path + "default.html", elemLayout: layout_path + "elem.html", sys: { @@ -17,21 +17,21 @@ export const render = async function (path, params, cfg) { copyright: `Created By Yunzai-Bot${yunzaiVersion} & xiaoyao-cvs-Plugin${currentVersion}` } },"png"); - + let ret = true if (base64) { - e.reply(segment.image(`base64://${base64}`)); + ret = isV3 ? await e.reply(base64) : await e.reply(segment.image(`base64://${base64}`)) } - - return true; + return cfg.retMsgId ? ret : true } export const render_path = async function (path, params, cfg,path_) { let paths = path.split("/"); let { render, e } = cfg; let _layout_path = process.cwd() + path_; - let base64 = await render1(paths[0], paths[1], { + let base64 = await render(paths[0], paths[1], { ...params, _layout_path, + _tpl_path: process.cwd() + '/plugins/xiaoyao-cvs-plugin/resources/common/tpl/', defaultLayout: _layout_path + "default.html", elemLayout: _layout_path + "elem.html", sys: { @@ -39,12 +39,11 @@ export const render_path = async function (path, params, cfg,path_) { copyright: `Created By Yunzai-Bot${yunzaiVersion} & xiaoyao-cvs-Plugin${currentVersion}` } }); - + let ret = true if (base64) { - e.reply(segment.image(`base64://${base64}`)); + ret = isV3 ? await e.reply(base64) : await e.reply(segment.image(`base64://${base64}`)) } - - return true; + return cfg.retMsgId ? ret : true } From 607f6275fe273808277ea1c03ce832a32f31d3b2 Mon Sep 17 00:00:00 2001 From: Ctrlcvs <1509167646@qq.com> Date: Wed, 17 Aug 2022 23:12:40 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E8=B0=83=E6=95=B4ck=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E7=94=A8=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/user.js | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/model/user.js b/model/user.js index 239bb51..bb1a6be 100644 --- a/model/user.js +++ b/model/user.js @@ -30,12 +30,7 @@ export default class user { await this.cookie(this.e) this.miHoYoApi = new MihoYoApi(this.e); if(this.e.yuntoken){ - let yunres = await promiseRetry((retry, number) => { - return this.miHoYoApi.logyunGenshen().catch((e) => { - return retry(e); - }); - }, RETRY_OPTIONS); - + let yunres = await this.miHoYoApi.logyunGenshen(); let yundata = yunres.data if(yunres.retcode===0){ sumData["云原神"]={ @@ -46,11 +41,7 @@ export default class user { } } if(this.e.cookies){ - let mysres = await promiseRetry((retry, number) => { - return this.miHoYoApi.getTasksList().catch((e) => { - return retry(e); - }); - }, RETRY_OPTIONS); + let mysres = await this.miHoYoApi.getTasksList(); if(mysres.retcode===0){ sumData["米游社"]={ "米游币任务":mysres.data.can_get_points!=0?"未完成":"已完成", @@ -62,11 +53,7 @@ export default class user { } if(this.e.cookie){ for(let name of nameData){ - let resSign = await promiseRetry((retry, number) => { - return this.miHoYoApi.honkai3rdSignTask(name).catch((e) => { - return retry(e); - }); - }, RETRY_OPTIONS); + let resSign = await this.miHoYoApi.honkai3rdSignTask(name); if(resSign?.upData){ // console.log(resSign?.upData) for(let item of resSign?.upData){ From 30dab3bee01a4d4f7a3a63ef01539e51db3f53dd Mon Sep 17 00:00:00 2001 From: Ctrlcvs <1509167646@qq.com> Date: Thu, 18 Aug 2022 13:21:52 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=88=B3=E4=B8=80?= =?UTF-8?q?=E6=88=B3=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/Note.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/Note.js b/apps/Note.js index ec60edb..92e8302 100644 --- a/apps/Note.js +++ b/apps/Note.js @@ -358,16 +358,16 @@ export async function DailyNoteTask() { redis.set(sendkey, "1", { EX: sendCD }); - await Note(e, getPluginRender("xiaoyao-cvs-plugin")); + // await Note(e, getPluginRender("xiaoyao-cvs-plugin")); } } } -export async function pokeNote(e) { +export async function pokeNote(e,{render}) { if (!Cfg.get("note.poke")) { return false; } - return await Note(e, getPluginRender("xiaoyao-cvs-plugin"), "poke"); + return await Note(e,{render}, "poke"); } From 7d3c0e4cbd011aa0f36167357a4e0294803d5a5d Mon Sep 17 00:00:00 2001 From: Ctrlcvs <1509167646@qq.com> Date: Thu, 18 Aug 2022 20:20:26 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=A3=9F=E7=89=A9?= =?UTF-8?q?=E5=8C=B9=E9=85=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/xiaoyao_image.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/xiaoyao_image.js b/apps/xiaoyao_image.js index d94638b..5365d4d 100644 --- a/apps/xiaoyao_image.js +++ b/apps/xiaoyao_image.js @@ -16,7 +16,7 @@ const _path = process.cwd(); const __dirname = path.resolve(); const list = ["wuqi_tujian", "shiwu_tujian", "yuanmo_tujian", "mijin_tujian", "shengyiwu_tujian", "daoju_tujian"] -const reglist=["(#|专武|武器|图鉴|突破)","(#|食物|特殊料理|特色|料理|食材)","(#|原魔|怪物|图鉴|信息)","(#|秘境|信息|图鉴)","(#|圣遗物|图鉴)","(#|图鉴|道具)"] +const reglist=["(#|专武|武器|图鉴|突破)","(#|食物|特殊料理|特色|料理|食材|图鉴)","(#|原魔|怪物|图鉴|信息)","(#|秘境|信息|图鉴)","(#|圣遗物|图鉴)","(#|图鉴|道具)"] export async function AtlasAlias(e) { if (!Cfg.get("Atlas.all")) { return false; From 698178085615d2b69c2ce848c7956f21ea7a0c6a Mon Sep 17 00:00:00 2001 From: Ctrlcvs <1509167646@qq.com> Date: Thu, 18 Aug 2022 22:33:28 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=B1=B3=E6=B8=B8?= =?UTF-8?q?=E5=B8=81=E7=AD=BE=E5=88=B0bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/mys/mihoyo-api.js | 44 ++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/model/mys/mihoyo-api.js b/model/mys/mihoyo-api.js index d9bc1c5..f0913b9 100644 --- a/model/mys/mihoyo-api.js +++ b/model/mys/mihoyo-api.js @@ -14,6 +14,7 @@ import { import fetch from "node-fetch" const APP_VERSION = "2.34.1"; const salt = "z8DRIUjNDT7IT5IZXvrUAxyupA1peND9"; +const salt2="t0qEgfub6cvueAPgR5m9aQWWVciEer7v"; //b253c83ab2609b1b600eddfe974df47b const DEVICE_ID = utils.randomString(32).toUpperCase(); const DEVICE_NAME = utils.randomString(_.random(1, 10)); @@ -156,8 +157,9 @@ export default class MihoYoApi { } } async forumSign(forumId) { - const url = `https://api-takumi.mihoyo.com/apihub/sapi/signIn?gids=${forumId}`; - let res = await superagent.post(url).set(this._getHeader()).timeout(10000); + const url = `https://bbs-api.mihoyo.com/apihub/app/api/signIn`; + this.forumId=forumId; + let res = await superagent.post(url).set(this._getHeader()).send(JSON.stringify({gids:forumId*1})).timeout(10000); let resObj = JSON.parse(res.text); // Bot.logger.mark(`ForumSign: ${res.text}`); return resObj; @@ -264,9 +266,11 @@ export default class MihoYoApi { async stoken(cookie, e) { this.e = e; - if (Object.keys(this.getStoken(e.user_id)).length != 0) { + let stokens=Object.values(this.getStoken(e.user_id)) + if (stokens.length != 0) { return true; } + let datalist={}; const map = this.getCookieMap(cookie); let loginTicket = map.get("login_ticket"); const loginUid = map.get("login_uid") ? map.get("login_uid") : map.get("ltuid"); @@ -298,12 +302,14 @@ export default class MihoYoApi { if (!data.data) { return false; } - let datalist = { + datalist[e.uid] = { stuid: map.get("account_id"), stoken: data.data.list[0].token, ltoken: data.data.list[1].token, - uid: e.uid + uid: e.uid, + 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; @@ -312,6 +318,7 @@ export default class MihoYoApi { ).catch(function(err) { return false; }); + // console.log(datalist); return true; } /** 米游社 api headers */ @@ -335,24 +342,39 @@ export default class MihoYoApi { 'Cookie': this.cookie } } + //社区签到ds + get_ds2(q="",b){ + let n = salt2 + let i = Math.floor(Date.now() / 1000) + let r = _.random(100001,200000) + let add = `&b=${b}&q=${q}` + let c= md5("salt=" + n + "&t=" + i + "&r=" + r + add) + return `${i},${r},${c}` + } + // 米游币任务的 headers _getHeader() { const randomStr = utils.randomString(6); const timestamp = Math.floor(Date.now() / 1000) let sign = md5(`salt=${salt}&t=${timestamp}&r=${randomStr}`); + let ds=`${timestamp},${randomStr},${sign}` + if(this.forumId){ + ds = this.get_ds2("",JSON.stringify({gids:this.forumId*1})); + this.forumId=""; + } return { 'Cookie': this.cookies, - "Referer": "https://app.mihoyo.com", - "x-rpc-sys_version": "6.0.1", - "Host": "bbs-api.mihoyo.com", - "User-Agent": "okhttp/4.8.0", - 'x-rpc-channel': 'appstore', + "x-rpc-channel": "miyousheluodi", 'x-rpc-device_id': DEVICE_ID, 'x-rpc-app_version': APP_VERSION, "x-rpc-device_model": "Mi 10", 'x-rpc-device_name': DEVICE_NAME, 'x-rpc-client_type': '2', // 1 - iOS, 2 - Android, 4 - Web - 'DS': `${timestamp},${randomStr},${sign}` + 'DS': ds, + "Referer": "https://app.mihoyo.com", + "x-rpc-sys_version": "6.0.1", + "Host": "bbs-api.mihoyo.com", + "User-Agent": "okhttp/4.8.0", // 'DS': `1602569298,k0xfEh,07f4545f5d88eac59cb1257aef74a570` } } From 001fccb53bd494797107eb304211cae0f41c75ee Mon Sep 17 00:00:00 2001 From: Ctrlcvs <1509167646@qq.com> Date: Thu, 18 Aug 2022 23:15:49 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E4=BF=AE=E6=AD=A3V3ck=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=A4=9A=E5=8F=B7=E6=97=A0=E6=B3=95=E8=AF=86=E5=88=AB=E9=97=AE?= =?UTF-8?q?=E9=A2=98,=E8=A1=A5=E5=85=85=E5=A4=9A=E4=B8=AAstoken=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E9=80=BB=E8=BE=91=E5=85=B7=E4=BD=93=E5=BE=85=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/sign.js | 19 +++++++---- model/gsCfg.js | 21 +++++++++--- model/mys/mihoyo-api.js | 22 +++++++----- model/user.js | 76 +++++++++++++++++++++-------------------- 4 files changed, 82 insertions(+), 56 deletions(-) diff --git a/apps/sign.js b/apps/sign.js index 0b41d8c..8bca482 100644 --- a/apps/sign.js +++ b/apps/sign.js @@ -122,7 +122,8 @@ export async function mysSign(e) { } let iscount = ""; let miHoYoApi = new MihoYoApi(e); - if (Object.keys((await miHoYoApi.getStoken(e.user_id))).length == 0) { + let stokens=await miHoYoApi.getStoken(e.user_id) + if (!stokens) { e.reply("未读取到stoken请检查cookies是否包含login_ticket、以及云崽是否为最新版本V3、V2兼容") return true; } @@ -231,7 +232,8 @@ export async function bbsSeach(e){ return true; } let miHoYoApi = new MihoYoApi(e); - if (Object.keys((await miHoYoApi.getStoken(e.user_id))).length == 0) { + let stokens=await miHoYoApi.getStoken(e.user_id) + if (!stokens) { let cookiesDoc = await getcookiesDoc() await replyMsg(e, "未读取到stoken请检查cookies是否包含login_ticket,请先绑定stoken再查询~\n"+cookiesDoc); return true; @@ -291,8 +293,8 @@ async function cookie(e) { e.reply("cookie失效请重新绑定~【教程】\n" + cookiesDoc) return false; } - - if (Object.keys((await miHoYoApi.getStoken(e.user_id))).length != 0) { +let stokens=miHoYoApi.getStoken(e.user_id) + if (!stokens) { return true; } if (!cookie.includes("login_ticket") && (isV3 && !skuid?.login_ticket)) { @@ -347,8 +349,10 @@ export async function allMysSign() { let stoken = await gsCfg.getBingStoken(); let isPushSign = await gsCfg.getfileYaml(`${_path}/plugins/xiaoyao-cvs-plugin/config/`, "config").isPushSign //获取需要签到的用户 - for (let data of stoken) { - let user_id = data.qq; + for (let dataUid of stoken) { + for(let uuId in dataUid){ + let data=dataUid[uuId] + let user_id = data.userId; let e = { user_id, isTask: true @@ -363,11 +367,12 @@ export async function allMysSign() { } if (msg.includes("OK")) { //签到成功并且不是已签到的才推送 // msg = msg.replace("签到成功", "自动签到成功"); - utils.relpyPrivate(user_id, msg + "\n自动签到成功"); + utils.relpyPrivate(user_id, msg + "uid:"+uuId+"\n自动签到成功"); } }; await mysSign(e); await utils.sleepAsync(10000); + } } Bot.logger.mark(`米社米币签到任务完成`); return true diff --git a/model/gsCfg.js b/model/gsCfg.js index 51641df..1547574 100644 --- a/model/gsCfg.js +++ b/model/gsCfg.js @@ -148,9 +148,7 @@ class GsCfg { const res = await Promise.all(promises) res.forEach((v,index) => { let tmp = YAML.parse(v) - tmp["qq"]=files[index].split(".")[0]*1 ck.push(tmp) - }) return ck } @@ -170,7 +168,11 @@ class GsCfg { let ck = fs.readFileSync(file, 'utf-8') ck = YAML.parse(ck) for(let item in ck){ - let login_ticket=ck[item]?.login_ticket + let login_ticket; + if(!ck[item].isMain){ + continue; + } + login_ticket=ck[item]?.login_ticket ck=ck[item].ck return {ck,item,login_ticket}; } @@ -187,7 +189,18 @@ class GsCfg { fs.writeFileSync(file, yaml, 'utf8') } } - + 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') + } + } /** * 原神角色id转换角色名字 */ diff --git a/model/mys/mihoyo-api.js b/model/mys/mihoyo-api.js index f0913b9..20a3a2b 100644 --- a/model/mys/mihoyo-api.js +++ b/model/mys/mihoyo-api.js @@ -266,11 +266,10 @@ export default class MihoYoApi { async stoken(cookie, e) { this.e = e; - let stokens=Object.values(this.getStoken(e.user_id)) - if (stokens.length != 0) { + let datalist=this.getStoken(e.user_id) + if (datalist){ return true; } - let datalist={}; const map = this.getCookieMap(cookie); let loginTicket = map.get("login_ticket"); const loginUid = map.get("login_uid") ? map.get("login_uid") : map.get("ltuid"); @@ -307,18 +306,18 @@ export default class MihoYoApi { stoken: data.data.list[0].token, ltoken: data.data.list[1].token, uid: e.uid, + userId:this.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'); + gsCfg.saveBingStoken(e.user_id,datalist) + // let yamlStr = YAML.stringify(datalist); + // fs.writeFileSync(`${YamlDataUrl}/${e.user_id}.yaml`, yamlStr, 'utf8'); return true; }); } ).catch(function(err) { return false; }); - // console.log(datalist); return true; } /** 米游社 api headers */ @@ -415,7 +414,14 @@ export default class MihoYoApi { try { let ck = fs.readFileSync(file, 'utf-8') ck = YAML.parse(ck) - return ck + if(ck?.uid){ + let datalist={}; + ck.userId=this.e.user_id + datalist[ck.uid]=ck; + ck=datalist + gsCfg.saveBingStoken(this.e.user_id,datalist) + } + return ck[this.e.uid] } catch (error) { return {} } diff --git a/model/user.js b/model/user.js index bb1a6be..fdf97fb 100644 --- a/model/user.js +++ b/model/user.js @@ -16,56 +16,57 @@ const RETRY_OPTIONS = { minTimeout: 5000, maxTimeout: 10000 }; -const nameData=["原神","崩坏3","崩坏2","未定事件簿"]; +const nameData = ["原神", "崩坏3", "崩坏2", "未定事件簿"]; /** 配置文件 */ export default class user { constructor(e) { - this.e=e; - this.stokenPath=`./plugins/${plugin}/data/yaml/` - this.yunPath=`./plugins/${plugin}/data/yunToken/`; + this.e = e; + this.stokenPath = `./plugins/${plugin}/data/yaml/` + this.yunPath = `./plugins/${plugin}/data/yunToken/`; this.getyunToken(this.e) } - async getCkData(){ - let sumData={}; + async getCkData() { + let sumData = {}; await this.cookie(this.e) this.miHoYoApi = new MihoYoApi(this.e); - if(this.e.yuntoken){ + if (this.e.yuntoken) { let yunres = await this.miHoYoApi.logyunGenshen(); let yundata = yunres.data - if(yunres.retcode===0){ - sumData["云原神"]={ - "今日可获取":yundata?.coin?.coin_num, - "免费时长":yundata?.free_time?.free_time, - "总时长":yundata.total_time + if (yunres.retcode === 0) { + sumData["云原神"] = { + "今日可获取": yundata?.coin?.coin_num, + "免费时长": yundata?.free_time?.free_time, + "总时长": yundata.total_time } } } - if(this.e.cookies){ + if (this.e.cookies) { let mysres = await this.miHoYoApi.getTasksList(); - if(mysres.retcode===0){ - sumData["米游社"]={ - "米游币任务":mysres.data.can_get_points!=0?"未完成":"已完成", - "米游币余额":mysres.data.total_points, - "今日剩余可获取":mysres.data.can_get_points + if (mysres.retcode === 0) { + sumData["米游社"] = { + "米游币任务": mysres.data.can_get_points != 0 ? "未完成" : "已完成", + "米游币余额": mysres.data.total_points, + "今日剩余可获取": mysres.data.can_get_points } } - + } - if(this.e.cookie){ - for(let name of nameData){ + if (this.e.cookie) { + for (let name of nameData) { let resSign = await this.miHoYoApi.honkai3rdSignTask(name); - if(resSign?.upData){ + if (resSign?.upData) { // console.log(resSign?.upData) - for(let item of resSign?.upData){ - let num= lodash.random(0, 9999); - item.upName=item.upName=="原神"?"ys":item.upName=="崩坏3"?"bh3":item.upName=="崩坏2"?"bh2":item.upName=="未定事件簿"?"wdy":"" - sumData[item.upName+""+num]={ - "uid":item.game_uid, - "游戏昵称":item.nickname, - "等级":item.level, - "今日签到":item.is_sign?"已签到":"未签到", - "累计签到":item.total_sign_day+"天", - "今天奖励":item.awards + for (let item of resSign?.upData) { + let num = lodash.random(0, 9999); + item.upName = item.upName == "原神" ? "ys" : item.upName == "崩坏3" ? "bh3" : item.upName == + "崩坏2" ? "bh2" : item.upName == "未定事件簿" ? "wdy" : "" + sumData[item.upName + "" + num] = { + "uid": item.game_uid, + "游戏昵称": item.nickname, + "等级": item.level, + "今日签到": item.is_sign ? "已签到" : "未签到", + "累计签到": item.total_sign_day + "天", + "今天奖励": item.awards } } } @@ -99,16 +100,17 @@ export default class user { async cookie(e) { let { cookie, - uid,skuid + uid, + skuid } = await this.getCookie(e); let cookiesDoc = await this.getcookiesDoc(); - let miHoYoApi = new MihoYoApi(this.e); + let miHoYoApi = new MihoYoApi(this.e); if (!cookie) { e.reply("请先#绑定cookie\n发送【体力帮助】查看配置教程") return false; } - - if (Object.keys((await miHoYoApi.getStoken(e.user_id))).length != 0) { + let stokens = miHoYoApi.getStoken(e.user_id) + if (!stokens) { return true; } if (!cookie.includes("login_ticket") && (isV3 && !skuid?.login_ticket)) { @@ -124,7 +126,7 @@ export default class user { } return true; } - async getcookiesDoc() { + async getcookiesDoc() { return await gsCfg.getfileYaml(`${_path}/plugins/xiaoyao-cvs-plugin/config/`, "config").cookiesDoc } async getCookie(e) { From 65b848e3981e7a809ba1e317980be2a9d0837968 Mon Sep 17 00:00:00 2001 From: Ctrlcvs <1509167646@qq.com> Date: Fri, 19 Aug 2022 07:31:24 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E4=BF=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/sign.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/sign.js b/apps/sign.js index 8bca482..c8e39dc 100644 --- a/apps/sign.js +++ b/apps/sign.js @@ -352,7 +352,7 @@ export async function allMysSign() { for (let dataUid of stoken) { for(let uuId in dataUid){ let data=dataUid[uuId] - let user_id = data.userId; + let user_id = data.userId*1; let e = { user_id, isTask: true 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 8/9] =?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 {} } From 33af254ca4c722aaa66492bcc5c904cc1d6cab44 Mon Sep 17 00:00:00 2001 From: Ctrlcvs <1509167646@qq.com> Date: Fri, 19 Aug 2022 17:51:30 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/sign.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/sign.js b/apps/sign.js index 86aee8a..c8144eb 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 (Object.keys(stokens).length>0) { + 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 (Object.keys(stokens).length>0) { + if (Object.keys(stokens).length==0) { let cookiesDoc = await getcookiesDoc() await replyMsg(e, "未读取到stoken请检查cookies是否包含login_ticket,请先绑定stoken再查询~\n"+cookiesDoc); return true;