From f1c0f4e2109e5d017370f4d74293b6076ff6da7d Mon Sep 17 00:00:00 2001
From: ctrlcvs <1509167646@qq.com>
Date: Sun, 31 Jul 2022 13:22:35 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=89=88=E6=9C=AC=E4=B8=8D?=
 =?UTF-8?q?=E5=85=BC=E5=AE=B9=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 apps/sign.js            |  9 +++++----
 model/mys/mihoyo-api.js | 41 ++++++++++++++++++++++++-----------------
 2 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/apps/sign.js b/apps/sign.js
index 8f4fdcc..5c819d3 100644
--- a/apps/sign.js
+++ b/apps/sign.js
@@ -18,7 +18,7 @@ export const rule = {
 		describe: "米游社米游币签到(理论上会签到全部所以区分开了)"
 	},
 	sign: {
-		reg: "^#*(原神|崩坏3|崩坏2|未定事件簿|大别野|崩坏星穹铁道|绝区零)签到$",
+		reg: "^#*(崩坏3|崩坏2|未定事件簿|大别野|崩坏星穹铁道|绝区零)签到$",
 		describe: "米社规则签到"
 	},
 	cookiesDocHelp: {
@@ -188,9 +188,6 @@ async function cookie(e) {
 	let cookie, uid;
 	let miHoYoApi = new MihoYoApi(e);
 	let skuid;
-	if(Object.keys((await miHoYoApi.getStoken(e.user_id))).length != 0){
-		return true;
-	}
 	let cookiesDoc=await getcookiesDoc();
 	if (isV3) {
 		skuid= await gsCfg.getBingCookie(e.user_id);
@@ -210,6 +207,10 @@ async function cookie(e) {
 		return false;
 	}
 	e.uid = uid;
+	e.cookie=cookie;
+	if(Object.keys((await miHoYoApi.getStoken(e.user_id))).length != 0){
+		return true;
+	}
 	if (!cookie.includes("login_ticket")&&(isV3&&!skuid?.login_ticket)) {
 		e.reply("米游社登录cookie不完整,请前往米游社通行证处重新获取cookie~\ncookies必须包含login_ticket【教程】 "+cookiesDoc)
 		return false;
diff --git a/model/mys/mihoyo-api.js b/model/mys/mihoyo-api.js
index 5e95e72..5194506 100644
--- a/model/mys/mihoyo-api.js
+++ b/model/mys/mihoyo-api.js
@@ -82,15 +82,16 @@ export default class MihoYoApi {
 	constructor(e) {
 		if (e) {
 			this.e = e
+			this.cookie=e.cookie
 			this.userId = String(e.user_id)
 			this.msgName = e.msg.replace(/#|签到|井|米游社|mys|社区/g, "")
 		}
 		Data.createDir("", YamlDataUrl, false);
-		//初始化配置文件
+		// //初始化配置文件
 		let data = this.getStoken(this.e.user_id);
-		let dataCk = gsCfg.getfileYaml(`${_path}/data/MysCookie/`, e.user_id);
-		this.cookies = `stuid=${data.stuid};stoken=${data.stoken};ltoken=${data.ltoken};`;
-		this.cookie = `account_id=${data.account_id};cookie_token=${data.cookie_token};`;
+		if(data){
+			this.cookies = `stuid=${data.stuid};stoken=${data.stoken};ltoken=${data.ltoken};`;
+		}
 	}
 	getbody() {
 		for (let item in boards) {
@@ -103,12 +104,11 @@ export default class MihoYoApi {
 		let kkbody = this.getbody();
 		try {
 			// 获取账号信息
-			const {
-				game_uid,
-				region,
-				nickname
-			} = await this.getUserInfo(kkbody)
-			if (!nickname) {
+			const  objData= await this.getUserInfo(kkbody)
+			if(objData.retcode!=200) {
+				return objData
+			}
+			if (!objData.nickname) {
 				return {
 					message: `未绑定${this.msgName}信息`
 				}
@@ -124,7 +124,7 @@ export default class MihoYoApi {
 			// 	}
 			// }
 			// 签到操作
-			return await this.postSign(kkbody, game_uid, region)
+			return await this.postSign(kkbody, objData.game_uid, objData.region)
 		} catch (error) {
 			logger.mark(`error.message`, error.message)
 		}
@@ -174,9 +174,7 @@ export default class MihoYoApi {
 		return "";
 	}
 
-	async getHonkai2SignInfo(game_uid, region, nickname, board) {
-
-	}
+	
 	async forumPostList(forumId) {
 		const url =
 			`https://api-takumi.mihoyo.com/post/api/getForumPostList?forum_id=${forumId}&is_good=false&is_hot=false&page_size=10&sort_type=1`;
@@ -334,19 +332,28 @@ export default class MihoYoApi {
 				.getpubHeaders(board)).timeout(10000);
 		let resObj = JSON.parse(res.text);
 		let data = resObj.data
+		if(resObj.retcode!=0){
+			return resObj
+		}
 		const game_uid = data?.list?. [0]?.game_uid
 		const region = data?.list?. [0]?.region
 		const nickname = data?.list?. [0]?.nickname
 		return {
 			game_uid,
 			region,
-			nickname
+			nickname,retcode:200
 		}
 	}
-	// 游戏签到操作 逻辑通用, 根据传入的 board 构建不同的参数
+	// 游戏签到操作 	
 	async postSign(board, game_uid, region) {
 		let url =
-			`https://api-takumi.mihoyo.com/common/eutheniav2/sign?region=${region}&act_id=${board.actid}&uid=${game_uid}`
+			`https://api-takumi.mihoyo.com/common/eutheniav2/sign`
+			if(board.name=="原神"){
+				url=`https://api-takumi.mihoyo.com/event/bbs_sign_reward/sign`
+			}
+			url+=`?region=${region}&act_id=${board.actid}&uid=${game_uid}`
+			// console.log(url)
+			// console.log(this.e)
 		let res = await superagent.post(url).set(this.getpubHeaders(board)).timeout(10000);
 		let resObj = JSON.parse(res.text);
 		return resObj