diff --git a/adapter/index.js b/adapter/index.js index 5661a02..510ca58 100644 --- a/adapter/index.js +++ b/adapter/index.js @@ -18,7 +18,8 @@ export class atlas extends plugin { rule: [rule], }) Object.defineProperty(rule, 'log', { - get: () => !!this.isDispatch + // get: () => !!this.isDispatch + get: () =>true }) } accept () { diff --git a/apps/sign.js b/apps/sign.js index 1cc70f1..8277aa8 100644 --- a/apps/sign.js +++ b/apps/sign.js @@ -25,15 +25,15 @@ const RETRY_OPTIONS = { maxTimeout: 10000 }; let YamlDataUrl = `${_path}/plugins/xiaoyao-cvs-plugin/data/yaml`; -let yunpath=`${_path}/plugins/xiaoyao-cvs-plugin/data/yunToken/`; -let configSign=gsCfg.getfileYaml(`${_path}/plugins/xiaoyao-cvs-plugin/config/`, "config"); -configSign.signlist=configSign.signlist||"原神|崩坏3|崩坏2|未定事件簿".split("|") +let yunpath = `${_path}/plugins/xiaoyao-cvs-plugin/data/yunToken/`; +let configSign = gsCfg.getfileYaml(`${_path}/plugins/xiaoyao-cvs-plugin/config/`, "config"); +configSign.signlist = configSign.signlist || "原神|崩坏3|崩坏2|未定事件簿".split("|") export const rule = { mysSign: { reg: `^#*(米游社|mys|社区)(原神|崩坏3|崩坏2|未定事件簿|大别野|崩坏星穹铁道|绝区零|全部)签到$`, describe: "米游社米游币签到(理论上会签到全部所以区分开了)" }, - bbsSeach:{ + bbsSeach: { reg: "^#*(米游币|米币)查询$", describe: "米币查询" }, @@ -57,7 +57,7 @@ export const rule = { reg: "^#云原神全部签到$", describe: "云原神全部签到" }, - yuntoken:{ + yuntoken: { reg: "^(.*)ct(.*)$", describe: "云原神签到token获取" }, @@ -65,14 +65,15 @@ export const rule = { reg: "^#*(米游社|cookies|米游币|stoken|Stoken)(帮助|教程|绑定)$", describe: "cookies获取帮助" }, - yunHelp:{ + yunHelp: { reg: "^#*(云原神|云)帮助$", describe: "cookies获取帮助" } }; init() + function init() { - Data.createDir("",yunpath , false); + Data.createDir("", yunpath, false); } export async function sign(e) { let { @@ -123,11 +124,15 @@ 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) { + let stokens = await miHoYoApi.getStoken(e.user_id) + if (Object.keys(stokens).length == 0) { e.reply("未读取到stoken\n请发送【stoken帮助】查看配置教程配置~") return true; } + if (e.uid[0] * 1 > 5) { + e.reply("暂不支持hoyolab社区签到~") + return true; + } START = moment().unix(); let resultMessage = ""; let resObj=await mysSeach(e) @@ -160,7 +165,7 @@ export async function mysSign(e) { return retry(e); }); }, RETRY_OPTIONS); - Bot.logger.mark(`${e.user_id}:${forum.name} 签到结果: [${resObj.message}]`); + Bot.logger.mark(`${e.user_id}:${e.uid}:${forum.name} 签到结果: [${resObj.message}]`); resultMessage += `签到: [${resObj.message}]\n`; } catch (e) { Bot.logger.error(`${forum.name} 签到失败 [${e.message}]`); @@ -168,11 +173,11 @@ export async function mysSign(e) { } await utils.randomSleepAsync(); } - let trueDetail=0; - let Vote=0; - let Share=0; - let sumcount=0; for (let forum of ForumData) { + let trueDetail = 0; + let Vote = 0; + let Share = 0; + let sumcount = 0; resultMessage += `\n**${forum.name}**\n` try { // 2 BBS list post @@ -196,7 +201,7 @@ export async function mysSign(e) { return retry(e); }); }, RETRY_OPTIONS); - if(resObj?.message){ + if (resObj?.message) { trueDetail++; } // Bot.logger.info(`${forum.name} [${post.subject}] 读取成功 [${resObj.message}]`); @@ -209,7 +214,7 @@ export async function mysSign(e) { return retry(e); }); }, RETRY_OPTIONS); - if(resObj?.message){ + if (resObj?.message) { Vote++; } // Bot.logger.mark(`${forum.name} [${post.subject}] 点赞成功 [${resObj.message}]`); @@ -224,7 +229,7 @@ export async function mysSign(e) { return retry(e); }); }, RETRY_OPTIONS); - if(resObj?.message){ + if (resObj?.message) { Share++; } } catch (e) { @@ -234,55 +239,55 @@ export async function mysSign(e) { resultMessage += `共读取帖子记录${20*sumcount}\n浏览成功:${trueDetail}\n点赞成功:${Vote}\n分享成功:${Share}`; await utils.randomSleepAsync(); } - Bot.logger.mark(`用户qq${e.user_id}${resultMessage}`); + Bot.logger.mark(`用户qq${e.user_id}:${e.uid}:${resultMessage}`); await replyMsg(e, resultMessage); return true } -export async function bbsSeach(e){ +export async function bbsSeach(e) { START = moment().unix(); let isck = await cookie(e); if (!isck) { return true; } let miHoYoApi = new MihoYoApi(e); - let stokens=await miHoYoApi.getStoken(e.user_id) - if (Object.keys(stokens).length==0) { + let stokens = await miHoYoApi.getStoken(e.user_id) + if (Object.keys(stokens).length == 0) { let cookiesDoc = await getcookiesDoc() - await replyMsg(e, "未读取到stoken请检查cookies是否包含login_ticket,请先绑定stoken再查询~\n"+cookiesDoc); + await replyMsg(e, "未读取到stoken请检查cookies是否包含login_ticket,请先绑定stoken再查询~\n" + cookiesDoc); return true; } - let resObj=await mysSeach(e) - if(!resObj?.data){ + let resObj = await mysSeach(e) + if (!resObj?.data) { await replyMsg(e, `登录Stoken失效请重新获取cookies或stoken保存~`); - fs.unlink(`${YamlDataUrl}/${e.user_id}.yaml`,function(error){ - if(error){ + fs.unlink(`${YamlDataUrl}/${e.user_id}.yaml`, function(error) { + if (error) { return "" } }) return true; } - await replyMsg(e,`当前米游币数量为:${resObj.data.total_points},今日剩余可获取:${resObj.data.can_get_points}`); + await replyMsg(e, `当前米游币数量为:${resObj.data.total_points},今日剩余可获取:${resObj.data.can_get_points}`); return true; } -async function mysSeach(e){ +async function mysSeach(e) { let miHoYoApi = new MihoYoApi(e); - try{ + try { let resObj = await promiseRetry((retry, number) => { return miHoYoApi.getTasksList().catch((e) => { return retry(e); }); }, RETRY_OPTIONS); return resObj - }catch(e){ - + } catch (e) { + } } async function replyMsg(e, resultMessage) { const END = moment().unix(); Bot.logger.info(`运行结束, 用时 ${END - START} 秒`); resultMessage += `\n用时 ${END - START} 秒`; - e.reply([segment.at(e.user_id),"\n"+resultMessage]); + e.reply([segment.at(e.user_id), "\n" + resultMessage]); } async function getDataList(name) { @@ -298,7 +303,8 @@ async function getDataList(name) { async function cookie(e) { let { cookie, - uid,skuid + uid, + skuid } = await getCookie(e); let miHoYoApi = new MihoYoApi(e); let cookiesDoc = await getcookiesDoc(); @@ -306,8 +312,8 @@ async function cookie(e) { e.reply("cookie失效请重新绑定~【教程】\n" + cookiesDoc) return false; } - let stokens=miHoYoApi.getStoken(e.user_id) - if (Object.keys(stokens).length>0) { + let stokens = miHoYoApi.getStoken(e.user_id) + if (Object.keys(stokens).length > 0) { return true; } if (!cookie.includes("login_ticket") && (isV3 && !skuid?.login_ticket)) { @@ -360,30 +366,34 @@ export async function allMysSign() { Bot.logger.mark(`开始米社米币签到任务`); let stoken = await gsCfg.getBingStoken(); let isPushSign = await gsCfg.getfileYaml(`${_path}/plugins/xiaoyao-cvs-plugin/config/`, "config").isPushSign + //获取需要签到的用户 for (let dataUid of stoken) { - for(let uuId in dataUid){ - let data=dataUid[uuId] - let user_id = data.userId*1; - let e = { - user_id, - isTask: true - }; - e.cookie = `stuid=${data.stuid};stoken=${data.stoken};ltoken=${data.ltoken};`; - Bot.logger.mark(`正在为qq${user_id}进行米游币签到中...`); - e.msg = "全部" - e.reply = (msg) => { - //关闭签到消息推送 - if (!isPushSign||ismysbool) { - return; + for (let uuId in dataUid) { + if (uuId[0] * 1 > 5) { + continue; } - if (msg.includes("OK")) { //签到成功并且不是已签到的才推送 - // msg = msg.replace("签到成功", "自动签到成功"); - utils.relpyPrivate(user_id, msg + "uid:"+uuId+"\n自动签到成功"); - } - }; - await mysSign(e); - await utils.sleepAsync(10000); + let data = dataUid[uuId] + let user_id = data.userId * 1; + let e = { + user_id, + isTask: true + }; + e.cookie = `stuid=${data.stuid};stoken=${data.stoken};ltoken=${data.ltoken};`; + Bot.logger.mark(`正在为qq${user_id}:uid:${uuId}进行米游币签到中...`); + e.msg = "全部" + e.reply = (msg) => { + //关闭签到消息推送 + if (!isPushSign || ismysbool) { + return; + } + if (msg.includes("OK")) { //签到成功并且不是已签到的才推送 + // msg = msg.replace("签到成功", "自动签到成功"); + utils.relpyPrivate(user_id, msg + "uid:" + uuId + "\n自动签到成功"); + } + }; + await mysSign(e); + await utils.sleepAsync(10000); } } Bot.logger.mark(`米社米币签到任务完成`); @@ -391,7 +401,7 @@ export async function allMysSign() { } //定时签到任务 -export async function allSign(e="") { +export async function allSign(e = "") { Bot.logger.mark(`开始米社签到任务`); let isAllSign = await gsCfg.getfileYaml(`${_path}/plugins/xiaoyao-cvs-plugin/config/`, "config").isAllSign let userIdList = []; @@ -404,7 +414,7 @@ export async function allSign(e="") { userIdList.push(user_id) } } - let msg=e?.msg; + let msg = e?.msg; for (let qq of userIdList) { let user_id = qq; let e = { @@ -412,14 +422,14 @@ export async function allSign(e="") { qq, isTask: true }; - if(msg){ - e.msg=msg.replace(/全部|签到|米社/g,""); - }else{ + if (msg) { + e.msg = msg.replace(/全部|签到|米社/g, ""); + } else { e.msg = "全部" } Bot.logger.mark(`正在为qq${user_id}米社签到中...`); e.reply = (msg) => { - if (!isAllSign||isbool) { + if (!isAllSign || isbool) { return; } if (msg.includes("OK")) { @@ -455,39 +465,39 @@ export async function signlist(e) { let msg = e.msg.replace(/#|全部签到/g, "") e.reply(`开始执行${msg}签到中,请勿重复执行`); if (msg == "米游币") { - if(!fs.existsSync(YamlDataUrl)){ + if (!fs.existsSync(YamlDataUrl)) { Data.createDir("", YamlDataUrl, false); e.reply("未读取到可签到文件") return true; } - ismysbool=true; + ismysbool = true; await allMysSign() } else { isbool = true; await allSign(e) } e.reply(`${msg}签到任务已完成`); - ismysbool=false; + ismysbool = false; isbool = false; return true; } -let isYun=false; -export async function yunAllSign(e){ +let isYun = false; +export async function yunAllSign(e) { if (!await checkAuth(e)) { return true; } - + e.reply(`开始执行云原神签到中,请勿重复执行`); - if(isYun){ + if (isYun) { e.reply(`云原神签到中请勿重复执行`) return true; } - isYun=true; + isYun = true; await yunSignlist(e); e.reply(`云原神签到任务已完成`); } -export async function yunSignlist(e){ +export async function yunSignlist(e) { Bot.logger.mark(`云原神签到任务开始`); let files = fs.readdirSync(yunpath).filter(file => file.endsWith('.yaml')) let isYunSignMsg = await gsCfg.getfileYaml(`${_path}/plugins/xiaoyao-cvs-plugin/config/`, "config").isYunSignMsg @@ -502,7 +512,7 @@ export async function yunSignlist(e){ Bot.logger.mark(`正在为qq${user_id}云原神签到中...`); e.msg = "全部" e.reply = (msg) => { - if (!isYunSignMsg||isYun) { + if (!isYunSignMsg || isYun) { return; } if (msg.includes("领取奖励")) { @@ -516,56 +526,56 @@ export async function yunSignlist(e){ } -export async function yunSign(e){ - if(!(await getyunToken(e))){ - e.reply("尚未绑定云原神token\n"+await yunDoc()) +export async function yunSign(e) { + if (!(await getyunToken(e))) { + e.reply("尚未绑定云原神token\n" + await yunDoc()) return true; } let miHoYoApi = new MihoYoApi(e); e.reply((await miHoYoApi.yunGenshen()).sendMSg) return; } -const getyunToken=async function(e){ +const getyunToken = async function(e) { let file = `${yunpath}/${e.user_id}.yaml` try { let ck = fs.readFileSync(file, 'utf-8') ck = YAML.parse(ck) - e.devId=ck.devId; - e.yuntoken=ck.yuntoken; + e.devId = ck.devId; + e.yuntoken = ck.yuntoken; return ck } catch (error) { return "" } } -export async function sendyunTime(e){ - if(!(await getyunToken(e))){ - e.reply("尚未绑定云原神token\n"+await yunDoc()) +export async function sendyunTime(e) { + if (!(await getyunToken(e))) { + e.reply("尚未绑定云原神token\n" + await yunDoc()) return true; } let miHoYoApi = new MihoYoApi(e); e.reply((await miHoYoApi.logyunGenshen()).log_msg) return; } -export async function yuntoken(e){ - if(e.msg.includes("ltoken")||e.msg.includes("_MHYUUID")){ //防止拦截米社cookie +export async function yuntoken(e) { + if (e.msg.includes("ltoken") || e.msg.includes("_MHYUUID")) { //防止拦截米社cookie return false; } - if (["ct","si","devId"].includes(e.msg)) { + if (["ct", "si", "devId"].includes(e.msg)) { e.reply(`格式支持\nai=*;ci=*;oi=*;ct=***********;si=**************;bi=***********;devId=***********`) - return false; - } - let msg=e.msg.split("devId") - - if(msg.length<2){ return false; } - let devId=msg[1].replace(/=/,"") - let yuntoken=msg[0]; - e.devId=devId; - e.yuntoken=yuntoken; + let msg = e.msg.split("devId") + + if (msg.length < 2) { + return false; + } + let devId = msg[1].replace(/=/, "") + let yuntoken = msg[0]; + e.devId = devId; + e.yuntoken = yuntoken; let miHoYoApi = new MihoYoApi(e); - let objData=(await miHoYoApi.logyunGenshen()) //校验token是否有效 - if(objData.retcode!=0){ + let objData = (await miHoYoApi.logyunGenshen()) //校验token是否有效 + if (objData.retcode != 0) { e.reply(objData.message) return true; } @@ -583,11 +593,11 @@ export async function yuntoken(e){ } -export async function yunHelp(e){ - e.reply("云原神帮助:\n"+await yunDoc()) +export async function yunHelp(e) { + e.reply("云原神帮助:\n" + await yunDoc()) return true; } -const yunDoc=async function(){ +const yunDoc = async function() { return await gsCfg.getfileYaml(`${_path}/plugins/xiaoyao-cvs-plugin/config/`, "config").yunDoc } diff --git a/apps/user.js b/apps/user.js index 52e532d..d732208 100644 --- a/apps/user.js +++ b/apps/user.js @@ -93,10 +93,11 @@ export async function gclog(e) { return true; } let kkbody = await miHoYoApi.getbody("原神"); - const objData = await miHoYoApi.getUserInfo(kkbody) - let data = objData.data - e.region = e.uid[0] * 1 == 5 ? "cn_qd01" : "cn_gf01" - let authkeyrow = await miHoYoApi.authkey(data); + e.region = getServer(e.uid) + // const objData = await miHoYoApi.getUserInfo(kkbody) + // let data = objData.data + // console.log(data) + let authkeyrow = await miHoYoApi.authkey(e); if (!authkeyrow?.data) { e.reply("authkey获取失败:" + authkeyrow.message) return true; @@ -125,6 +126,7 @@ export async function gclog(e) { url += `${item}=${postdata[item]}&` } e.msg = url.substring(0, url.length - 1); + // e.reply(e.msg) let sendMsg = []; e.reply("抽卡记录获取中请稍等...") e._reply = e.reply; @@ -228,6 +230,7 @@ export async function updCookie(e) { sendMsg.push(msg) } for(let item of Object.keys(stoken)){ + e.region = getServer(stoken[item].uid) miHoYoApi.cookies= `stuid=${stoken[item].stuid};stoken=${stoken[item].stoken};ltoken=${stoken[item].ltoken};`; let resObj = await miHoYoApi.updCookie(); if (!resObj?.data) { @@ -252,3 +255,22 @@ export async function updCookie(e) { await utils.replyMake(e, sendMsg, 0) return true; } + +function getServer (uid) { + switch (String(uid)[0]) { + case '1': + case '2': + return 'cn_gf01' // 官服 + case '5': + return 'cn_qd01' // B服 + case '6': + return 'os_usa' // 美服 + case '7': + return 'os_euro' // 欧服 + case '8': + return 'os_asia' // 亚服 + case '9': + return 'os_cht' // 港澳台服 + } + return 'cn_gf01' +} \ No newline at end of file diff --git a/index.js b/index.js index 10817f7..5ffc01f 100644 --- a/index.js +++ b/index.js @@ -10,6 +10,7 @@ let index = { atlas: {} } if (isV3) { + Bot.logger=logger index = await Data.importModule('/plugins/xiaoyao-cvs-plugin/adapter', 'index.js') } export const atlas = index.atlas || {} diff --git a/model/mys/mihoyo-api.js b/model/mys/mihoyo-api.js index 94748b6..0bfd257 100644 --- a/model/mys/mihoyo-api.js +++ b/model/mys/mihoyo-api.js @@ -19,6 +19,7 @@ const salt = "6J1hde1Wu02eF1DFlLpMjeg2dMloAytL"; const salt2 = "t0qEgfub6cvueAPgR5m9aQWWVciEer7v"; const saltWeb = "Qqx8cyv7kuyD8fTw11SmvXSFHp7iZD29"; const oldsalt = "z8DRIUjNDT7IT5IZXvrUAxyupA1peND9"; +const osSaltWeb=''; //os 浏览帖子需要用到的salt const DEVICE_ID = utils.randomString(32).toUpperCase(); const DEVICE_NAME = utils.randomString(_.random(1, 10)); @@ -26,8 +27,11 @@ const _path = process.cwd(); const YamlDataUrl = `${_path}/plugins/xiaoyao-cvs-plugin/data/yaml`; const web_api = `https://api-takumi.mihoyo.com` const os_web_api = `https://api-os-takumi.mihoyo.com` +const os_hk4_api=`https://hk4e-api-os.hoyoverse.com`; const hk4_api = `https://hk4e-api.mihoyo.com`; const bbs_api = `https://bbs-api.mihoyo.com`; + +let HttpsProxyAgent = '' // 米游社的版块 const boards = { honkai3rd: { @@ -274,15 +278,18 @@ export default class MihoYoApi { } async updCookie() { let url = `${web_api}/auth/api/getCookieAccountInfoBySToken?game_biz=hk4e_cn`; - // if(this.e.region.includes("os")){ - //os接口暂时先不接入 - // url=`${os_web_api}/binding/api/getUserGameRolesByCookie?game_biz=hk4e_global`; - // } - // console.log(url) + if (this.e.region.includes("os")) { + url = `${os_web_api}/auth/api/getCookieAccountInfoBySToken?game_biz=hk4e_global`; + } let map = this.getCookieMap(this.cookies) url += `&stoken=${map.get("stoken")}&uid=${map.get("stuid")}`; - let res = await superagent.get(url); - let resObj = JSON.parse(res.text); + let param = { + agent: await this.getAgent(), + timeout: 10000, + method:'get' + } + let res = await fetch(url, param); + let resObj = await res.json() return resObj; } async stoken(cookie, e) { @@ -362,10 +369,12 @@ export default class MihoYoApi { //社区签到ds get_ds2(q = "", b) { let n = salt2 + // n ="6cqshh5dhw73bzxn20oexa9k516chk7s" 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) + // this.e.reply("md5"+c) return `${i},${r},${c}` } @@ -428,35 +437,63 @@ export default class MihoYoApi { } } old_version_get_ds_token() { - let n = 'N50pqm7FSy2AkFz2B3TqtuZMJ5TOl3Ep' + // 1 测试过的salt很显然都不是 也可能是header参数错误导致无法使用的 另外一个salt加密方法 get_ds + // xV8v4Qu44lUKrEYFZkJhB8cuOh9Asafs + // 2 + // t0qEgfub6cvueAPgR5m9aQWWVciEer7v + // 3 + // 599uqkwc0dlqu3h6epzjzfhgyyrd44PR + // 4 + // rk4xg2hakoi26nljpr099fv9fck1ah10 + // 5 6cqshh5dhw73bzxn20oexa9k516chk7s 签到salt?? 6s25p5ox5y14umn1p61aqyyvbvvl3lrt + let n = this.e.region.startsWith('os')?osSaltWeb:'N50pqm7FSy2AkFz2B3TqtuZMJ5TOl3Ep' let i = Math.floor(Date.now() / 1000) - let r = utils.randomString(6) - let c = md5('salt=' + n + '&t=' + i + '&r=' + r) + let r =utils.randomString(6) + let c = md5('salt=' + n + '&t=' + i + '&r=' + r ) + // this.e.reply("md5"+c) return i + ',' + r + ',' + c } async authkey(e) { - let url = `${web_api}/binding/api/genAuthKey`; + let isos=this.e.region.startsWith('os')?true:false; + let url = `${(isos?os_web_api:web_api)}/binding/api/genAuthKey`; let HEADER = this.getHeader(); HEADER['Cookie'] = this.cookies - HEADER['DS'] = this.old_version_get_ds_token() + // HEADER['DS'] = this.get_ds2("", JSON.stringify({ + // gids: 26 + // })); + 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-app_version'] =isos? '2.18.1':'2.35.2' HEADER['x-rpc-sys_version'] = '12' HEADER['x-rpc-client_type'] = '5' - HEADER['x-rpc-channel'] = 'mihoyo' + HEADER['x-rpc-channel'] =isos?'hoyolab':'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' + // HEADER['Referer'] = 'https://app.mihoyo.com' + // HEADER['Host'] = 'api-takumi.mihoyo.com' + HEADER['Referer'] = isos?'https://app.hoyolab.com':'https://app.mihoyo.com' + HEADER['Host'] = (isos?os_web_api:web_api).replace(/https:\/\//,"") + HEADER['Origin']=(isos?'https://webstatic-sea.hoyolab.com':'https://webstatic.mihoyo.com') let data = { 'auth_appid': 'webview_gacha', - 'game_biz': 'hk4e_cn', + 'game_biz': isos?'hk4e_global':'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); + let param = { + headers:HEADER, + agent: await this.getAgent(), + timeout: 10000, + body:JSON.stringify(data), + method:'post' + } + let res = await fetch(url, param); + // console.log(res) + let resObj = await res.json() + // headers + // let res = await superagent.post(url).set(HEADER).send(JSON.stringify(data)); + // let resObj = JSON.parse(res.text); return resObj } getCookieMap(cookie) { @@ -494,14 +531,14 @@ export default class MihoYoApi { async getUserInfo(board) { let url = `${web_api}/binding/api/getUserGameRolesByCookie?game_biz=${board.biz}` // if(this.e.region.includes("os")){ - //os接口暂时先不接入 + // 暂时先不接入 // url=`${os_web_api}/binding/api/getUserGameRolesByCookie?game_biz=hk4e_global`; // } let res = await superagent.get(url) .set(this .getpubHeaders(board)).timeout(10000); let resObj = JSON.parse(res.text); - let data = resObj.data + // console.log(resObj) if (resObj.retcode != 0) { return resObj } @@ -541,5 +578,26 @@ export default class MihoYoApi { return resObj } + async getAgent() { + if (isV3) { + let cfg = await import(`file://${_path}/lib/config/config.js`); + let proxyAddress = cfg.default.bot.proxyAddress + if (!proxyAddress) return null + if (proxyAddress === 'http://0.0.0.0:0') return null + if (!this.e.region.startsWith('os')) return null + + if (HttpsProxyAgent === '') { + HttpsProxyAgent = await import('https-proxy-agent').catch((err) => { + logger.error(err) + }) + + HttpsProxyAgent = HttpsProxyAgent ? HttpsProxyAgent.default : undefined + } + if (HttpsProxyAgent) { + return new HttpsProxyAgent(proxyAddress) + } + } + return null + } }