From 36a300bb28a141aff9926555acfbfb0a3330b61f Mon Sep 17 00:00:00 2001 From: Ctrlcvs <1509167646@qq.com> Date: Wed, 31 Aug 2022 23:26:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8C=87=E4=BB=A4=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=8A=BD=E5=8D=A1=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 27 +++----- apps/index.js | 8 +-- apps/user.js | 82 ++++++++++++++++++---- model/mys/mihoyo-api.js | 149 ++++++++++++++++++++++++++-------------- model/mys/utils.js | 1 - 5 files changed, 181 insertions(+), 86 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c56c45..d0a1327 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,25 +1,14 @@ -# 1.1.8 +# 1.1.9 +* 优化部分代码以及配置 +* 新增指令`#更新抽卡记录` + *必须绑定stoken +* 默认配置文件位于****xiaoyao-cvs-plugin/defSet/config/config.yaml**** + *后续叠加配置数据会在此文件中增加 +# 1.1.2~1.1.8 * 新增指令`#ck查询` * 可查询当前cookie绑定状态的签到信息以及米游币信息数据 -# 1.1.7 * 新增指令`#米币查询` * 新增`道具图鉴`图鉴数据 -* 修正米游币签到逻辑 -* 补充指令`原神签到` - * 由于原神签到有提示验证码问题可能导致签到不了 - * 补充指令 `原神签到`以及`米社原神全部签到`进行二次签到避免漏签 -# 1.1.6 -* 通过发送token以及devId给机器人实现绑定 -* 格式支持`ai=*;ci=*;oi=*;ct=***********;si=**************;bi=***********;devId=***********` -* 新增指令`#云原神签到`可进行云原神签到 -* 新增指令`#云原神查询`可查询当前绑定token的剩余时间 -* 新增云原神自动签到 -* 新增`云原神帮助` -# 1.1.5 -* 体力模板列表更改为转发形式更具体呈现效果 -* 新增自动签到配置 - *可在`xiaoyao-cvs-plugin/config/config.yaml`中修改是否启用自动签到 -# 1.1.2~1.1.4 * 新增指令`#米游币全部签到` *为所有存在的stoken进行社区米游币签到 * 新增指令`#米社全部签到` @@ -57,4 +46,4 @@ *可以通过`#体力模板设置随机`来恢复之前的状态 * 增加`#**图鉴`用于查看逍遥全图鉴 * 增加`#图鉴更新`用于获取图鉴数据 -* 增加`#图鉴插件(强制)更新`用于插件包更新 \ No newline at end of file +* 增加`#图鉴插件(强制)更新`用于插件包更新 diff --git a/apps/index.js b/apps/index.js index 425362f..bee5eed 100644 --- a/apps/index.js +++ b/apps/index.js @@ -24,7 +24,7 @@ import { } from "../components/Changelog.js"; import { rule as userRule, - userInfo + userInfo,gclog } from "./user.js" import { rule as signRule, @@ -33,11 +33,11 @@ import { cookiesDocHelp, signlist,yunSignlist,yunAllSign, allMysSign,yunSign,sendyunTime,yuntoken,yunHelp, - allSign,bbsSeach + allSign,bbsSeach,delSign } from "./sign.js" export { - updateRes,yunSignlist, - signlist, + updateRes,yunSignlist,delSign, + signlist,gclog, updateMiaoPlugin,userInfo, sign,bbsSeach, versionInfo,yunAllSign, diff --git a/apps/user.js b/apps/user.js index 56a5fd7..b8d0c4f 100644 --- a/apps/user.js +++ b/apps/user.js @@ -6,7 +6,7 @@ import { Data } from "../components/index.js"; import moment from 'moment'; - +import lodash from 'lodash'; import Common from "../components/Common.js"; import { isV3 @@ -23,25 +23,32 @@ export const rule = { reg: "^#*(ck|stoken|cookie|cookies|签到)查询$", describe: "用户个人信息查询" }, + gclog: { + reg: "^#*更新抽卡记录$", + describe: "更新抽卡记录" + } } -export async function userInfo(e,{render}){ - let user=new User(e); +const _path = process.cwd(); +export async function userInfo(e, { + render +}) { + let user = new User(e); e.reply("正在获取角色信息请稍等...") - let sumData=await user.getCkData() + let sumData = await user.getCkData() let week = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]; let day = moment(new Date()).format("yyyy年MM月DD日 HH:mm") + " " + week[new Date().getDay()]; - if(Object.keys(sumData).length==0){ + if (Object.keys(sumData).length == 0) { return true; } - let ck=""; - if(e.cookie){ - ck= user.getCookieMap(e.cookie); - ck=ck.get("ltuid") + let ck = ""; + if (e.cookie) { + ck = user.getCookieMap(e.cookie); + ck = ck.get("ltuid") } return await Common.render(`user/userInfo`, { uid: e.user_id, - ltuid:ck||e.user_id, - save_id:e.user_id, + ltuid: ck || e.user_id, + save_id: e.user_id, day, sumData }, { @@ -50,4 +57,55 @@ export async function userInfo(e,{render}){ scale: 1.2 }) return true; -} \ No newline at end of file +} + +export async function gclog(e) { + let user = new User(e); + await user.cookie(e) + if(!e.cookies){ + e.reply("暂未绑定stoken\n请先绑定stoken") + return true; + } + let miHoYoApi = new MihoYoApi(e); + let kkbody = await miHoYoApi.getbody("原神"); + const objData = await miHoYoApi.getUserInfo(kkbody) + let data = objData.data + e.region = e.uid[0] == 5 ? "cn_qd01" : "cn_gf01" + let authkeyrow = await miHoYoApi.authkey(data); + let authkey=authkeyrow.data["authkey"] + let postdata = { + 'authkey_ver': '1', + 'sign_type': '2', + 'auth_appid': 'webview_gacha', + 'init_type': '301', + 'gacha_id': 'fecafa7b6560db5f3182222395d88aaa6aaac1bc', + 'timestamp': Math.floor(Date.now() / 1000), //当前时间搓 + 'lang': 'zh-cn', + 'device_type': 'mobile', + 'plat_type': 'ios', + 'region': e.region, + 'authkey': encodeURIComponent(authkey), + 'game_biz': 'hk4e_cn', + 'gacha_type': "301", + 'page': 1, + 'size': 5, + 'end_id': 0, + } + let url = `https://hk4e-api.mihoyo.com/event/gacha_info/api/getGachaLog?` + for (let item of Object.keys(postdata)) { + url += `${item}=${postdata[item]}&` + } + let plyurl = url.substring(0, url.length - 1); + e.msg=plyurl + if(isV3){ + let gclog= (await import(`file:///${_path}/plugins/genshin/model/gachaLog.js`)).default + await (new gclog(e)).logUrl() + } else { + let { + bing + } = (await import(`file:///${_path}/lib/app/gachaLog.js`)) + e.isPrivate = true; + await bing(e) + } + return true; +} diff --git a/model/mys/mihoyo-api.js b/model/mys/mihoyo-api.js index 2afb4dd..6b9ddfd 100644 --- a/model/mys/mihoyo-api.js +++ b/model/mys/mihoyo-api.js @@ -12,15 +12,20 @@ import { isV3 } from '../../components/Changelog.js'; import fetch from "node-fetch" + const APP_VERSION = "2.35.2"; +const mhyVersion = "2.11.1"; const salt = "ZSHlXeQUBis52qD1kEgKt5lUYed4b7Bb"; -const salt2="t0qEgfub6cvueAPgR5m9aQWWVciEer7v"; -const saltWeb="N50pqm7FSy2AkFz2B3TqtuZMJ5TOl3Ep"; +const salt2 = "t0qEgfub6cvueAPgR5m9aQWWVciEer7v"; +const saltWeb = "N50pqm7FSy2AkFz2B3TqtuZMJ5TOl3Ep"; +const oldsalt = "z8DRIUjNDT7IT5IZXvrUAxyupA1peND9"; //b253c83ab2609b1b600eddfe974df47b const DEVICE_ID = utils.randomString(32).toUpperCase(); const DEVICE_NAME = utils.randomString(_.random(1, 10)); const _path = process.cwd(); let YamlDataUrl = `${_path}/plugins/xiaoyao-cvs-plugin/data/yaml`; +let web_api = `https://api-takumi.mihoyo.com` +let hk4_api = `https://hk4e-api.mihoyo.com`; // 米游社的版块 const boards = { honkai3rd: { @@ -82,7 +87,7 @@ const boards = { url: "https://bbs.mihoyo.com/zzz/" } } -let web_api = `https://api-takumi.mihoyo.com` + export default class MihoYoApi { constructor(e) { if (e) { @@ -95,7 +100,7 @@ export default class MihoYoApi { let data = this.getStoken(this.e.user_id); if (data) { this.cookies = `stuid=${data.stuid};stoken=${data.stoken};ltoken=${data.ltoken};`; - this.e.cookies=this.cookies + this.e.cookies = this.cookies } } Data.createDir("", YamlDataUrl, false); @@ -114,44 +119,46 @@ export default class MihoYoApi { // 获取账号信息 const objData = await this.getUserInfo(kkbody) let data = objData.data - if (data?.list?.length == 0||!data?.list) { + if (data?.list?.length == 0 || !data?.list) { return { message: `未绑定${name}信息` } } let message = `\n${name}共计${data.list.length}个账号\n`; - let upData=[]; + let upData = []; for (let item of data.list) { - item.upName=name + item.upName = name let objshuj = await this.isPostSign(kkbody, item.game_uid, item.region) - item.total_sign_day=objshuj?.data?.total_sign_day - if(objshuj?.data?.is_sign){ - item.is_sign=true; + item.total_sign_day = objshuj?.data?.total_sign_day + if (objshuj?.data?.is_sign) { + item.is_sign = true; // console.log(objshuj) - message+=`游戏id:${item.nickname}-${item.game_uid}:今日已签到~\n`; - }else{ - objshuj=(await this.postSign(kkbody, item.game_uid, item.region)) - if(objshuj?.data?.gt){ - item.is_sign=false; - message+=`游戏id:${item.nickname}-${item.game_uid}:签到出现验证码~\n请晚点后重试,或者手动上米游社签到`; - }else{ + message += `游戏id:${item.nickname}-${item.game_uid}:今日已签到~\n`; + } else { + objshuj = (await this.postSign(kkbody, item.game_uid, item.region)) + if (objshuj?.data?.gt) { + item.is_sign = false; + message += `游戏id:${item.nickname}-${item.game_uid}:签到出现验证码~\n请晚点后重试,或者手动上米游社签到`; + } else { item.total_sign_day++; - item.is_sign=true; - message += `游戏id:${item.nickname}-${item.game_uid}:${objshuj.message=="OK"?"签到成功":objshuj.message}\n` + item.is_sign = true; + message += + `游戏id:${item.nickname}-${item.game_uid}:${objshuj.message=="OK"?"签到成功":objshuj.message}\n` } } //获取签到信息和奖励信息 const SignInfo = await this.getSignInfo(kkbody) if (SignInfo) { - let awards= SignInfo.data.awards[item.total_sign_day-1]; - item.awards=awards.name+"*"+awards.cnt + let awards = SignInfo.data.awards[item.total_sign_day - 1]; + item.awards = awards.name + "*" + awards.cnt } upData.push(item) await utils.randomSleepAsync(); } // 签到操作 return { - message,upData + message, + upData } } catch (error) { Bot.logger.mark(`error.message`, error.message) @@ -159,8 +166,10 @@ export default class MihoYoApi { } async forumSign(forumId) { 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); + 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; @@ -173,7 +182,7 @@ export default class MihoYoApi { } // 获取签到状态和奖励信息 async getSignInfo(board) { - let url=`${web_api}/event/luna/home?lang=zh-cn&` + let url = `${web_api}/event/luna/home?lang=zh-cn&` if (board.name == "原神") { url = `${web_api}/event/bbs_sign_reward/home?` } @@ -244,14 +253,11 @@ export default class MihoYoApi { let reward_msg = item.msg; url = `https://api-cloudgame.mihoyo.com/hk4e_cg_cn/gamer/api/ackNotification?id=${reward_id}`; res = await superagent.post(url).set(this.getyunHeader()).timeout(10000); - let log_msg = `\n领取奖励,ID:${reward_id},Msg:${reward_msg.msg}`; + let log_msg = `\n领取奖励,ID:${reward_id},Msg:${reward_msg}`; Bot.logger.info(log_msg) sendMSg += log_msg } - // log_msg="\n\n"+(await this.logyunGenshen()).log_msg - // sendMSg += log_msg resObj.sendMSg = sendMSg; - // Bot.logger.info(log_msg) return resObj; } @@ -267,8 +273,8 @@ export default class MihoYoApi { async stoken(cookie, e) { this.e = e; - let datalist=this.getStoken(e.user_id) || {} - if (Object.keys(datalist).length>0){ + let datalist = this.getStoken(e.user_id) || {} + if (Object.keys(datalist).length > 0) { return true; } const map = this.getCookieMap(cookie); @@ -306,10 +312,10 @@ export default class MihoYoApi { stoken: data.data.list[0].token, ltoken: data.data.list[1].token, uid: e.uid, - userId:e.user_id, - is_sign:true + userId: e.user_id, + is_sign: true } - gsCfg.saveBingStoken(e.user_id,datalist) + gsCfg.saveBingStoken(e.user_id, datalist) return true; }); } @@ -340,24 +346,26 @@ export default class MihoYoApi { } } //社区签到ds - get_ds2(q="",b){ + get_ds2(q = "", b) { let n = salt2 let i = Math.floor(Date.now() / 1000) - let r = _.random(100001,200000) + let r = _.random(100001, 200000) let add = `&b=${b}&q=${q}` - let c= md5("salt=" + n + "&t=" + i + "&r=" + r + add) + 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=""; + let ds = `${timestamp},${randomStr},${sign}` + if (this.forumId) { + ds = this.get_ds2("", JSON.stringify({ + gids: this.forumId * 1 + })); + this.forumId = ""; } return { 'Cookie': this.cookies, @@ -395,7 +403,48 @@ export default class MihoYoApi { "User-Agent": "okhttp/3.14.9" } } - + //一个奇怪的请求头 + getHeader() { + return { + 'x-rpc-app_version': mhyVersion, + 'User-Agent': `Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) miHoYoBBS/2.11.1`, + 'x-rpc-client_type': '5', + 'Referer': 'https://webstatic.mihoyo.com/', + 'Origin': 'https://webstatic.mihoyo.com', + } + } + old_version_get_ds_token() { + let n = 'N50pqm7FSy2AkFz2B3TqtuZMJ5TOl3Ep' + let i = Math.floor(Date.now() / 1000) + let r = utils.randomString(6) + let c = md5('salt=' + n + '&t=' + i + '&r=' + r) + return i + ',' + r + ',' + c + } + async authkey(e) { + let url = `${web_api}/binding/api/genAuthKey`; + let HEADER = this.getHeader(); + HEADER['Cookie'] = this.cookies + HEADER['DS'] = this.old_version_get_ds_token() + HEADER['User-Agent'] = 'okhttp/4.8.0' + HEADER['x-rpc-app_version'] = '2.35.2' + HEADER['x-rpc-sys_version'] = '12' + HEADER['x-rpc-client_type'] = '5' + HEADER['x-rpc-channel'] = 'mihoyo' + HEADER['x-rpc-device_id'] = utils.randomString(32).toUpperCase(); + HEADER['x-rpc-device_name'] = utils.randomString(_.random(1, 10)); + HEADER['x-rpc-device_model'] = 'Mi 10' + HEADER['Referer'] = 'https://app.mihoyo.com' + HEADER['Host'] = 'api-takumi.mihoyo.com' + let data = { + 'auth_appid': 'webview_gacha', + 'game_biz': 'hk4e_cn', + 'game_uid': this.e.uid * 1, + 'region': this.e.region, + } + let res = await superagent.post(url).set(HEADER).send(JSON.stringify(data)); + let resObj = JSON.parse(res.text); + return resObj + } getCookieMap(cookie) { let cookiePattern = /^(\S+)=(\S+)$/; let cookieArray = cookie.replace(/\s*/g, "").split(";"); @@ -412,14 +461,14 @@ export default class MihoYoApi { try { let ck = fs.readFileSync(file, 'utf-8') ck = YAML.parse(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) + 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]||{} + return ck[this.e.uid] || {} } catch (error) { return {} } diff --git a/model/mys/utils.js b/model/mys/utils.js index a1eccd6..ecacc27 100644 --- a/model/mys/utils.js +++ b/model/mys/utils.js @@ -18,7 +18,6 @@ export function randomString(length){ let randomStr = ''; for (let i = 0; i < length; i++) { randomStr += _.sample('abcdefghijklmnopqrstuvwxyz0123456789'); - // randomStr += _.sample('dWCcD2FsOUXEstC5f9xubswZxEeoBOTc'); } return randomStr; }