From d904235308faf96d48340f932f521a84bc14630f Mon Sep 17 00:00:00 2001 From: Hex Date: Mon, 6 Mar 2023 17:24:31 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E7=AD=BE=E5=88=B0=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 1 - smzdm_checkin.js | 184 ++++++++++++++++++++++++++++++++++++++++++++++ smzdm_checkin.py | 186 ----------------------------------------------- 3 files changed, 184 insertions(+), 187 deletions(-) delete mode 100644 requirements.txt create mode 100644 smzdm_checkin.js delete mode 100644 smzdm_checkin.py diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index ba07d19..0000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -requests==2.28.2 diff --git a/smzdm_checkin.js b/smzdm_checkin.js new file mode 100644 index 0000000..3e54e5b --- /dev/null +++ b/smzdm_checkin.js @@ -0,0 +1,184 @@ +/* +什么值得买签到脚本 +项目地址: https://github.com/hex-ci/smzdm_script + +cron: 10 8 * * * +*/ + +const Env = require('./env'); +const { SmzdmBot, requestApi, removeTags } = require('./bot'); +const notify = require('./sendNotify'); + +// ------------------------------------ + +const $ = new Env('什么值得买签到'); + +class SmzdmCheckinBot extends SmzdmBot { + constructor(cookie) { + super(cookie); + } + + async run() { + const { msg } = await this.checkin(); + + await this.allReward(); + + await this.extraReward(); + + return msg; + } + + async checkin() { + const { isSuccess, data, response } = await requestApi('https://user-api.smzdm.com/checkin', { + method: 'post', + headers: this.getHeaders(), + data: { + touchstone_event: '', + sk: '1', + token: this.token, + captcha: '' + } + }); + + if (isSuccess) { + return { + isSuccess, + msg: `⭐签到成功${data.data.daily_num}天 +🏅金币: ${data.data.cgold} +🏅碎银: ${data.data.pre_re_silver} +🏅积分: ${data.data.cpoints} +🏅经验: ${data.data.cexperience} +🏅等级: ${data.data.rank} +🏅补签卡: ${data.data.cards}` + }; + } + else { + $.log(`签到失败!${response}`); + + return { + isSuccess, + msg: '签到失败!' + }; + } + } + + async allReward() { + const { isSuccess, data, response } = await requestApi('https://user-api.smzdm.com/checkin/all_reward', { + method: 'post', + headers: this.getHeaders() + }); + + if (isSuccess) { + $.log(`${data.data.normal_reward.reward_add.title}: ${data.data.normal_reward.reward_add.content}`); + $.log(`${data.data.normal_reward.gift.title}: ${data.data.normal_reward.gift.content_str}\n`); + } + else { + if (data.error_code != '4') { + $.log(`查询奖励失败!${response}`); + } + } + + return { + isSuccess + }; + } + + async extraReward() { + const isContinue = await this.isContinueCheckin(); + + if (!isContinue) { + $.log('今天没有额外奖励'); + + return false; + } + + const { isSuccess, data, response } = await requestApi('https://user-api.smzdm.com/checkin/extra_reward', { + method: 'post', + headers: this.getHeaders() + }); + + if (isSuccess) { + $.log(`${data.data.title}: ${removeTags(data.data.gift.content)}`); + + return true; + } + else { + $.log(`领取额外奖励失败!${response}`); + + return false; + } + } + + async isContinueCheckin() { + const { isSuccess, data, response } = await requestApi('https://user-api.smzdm.com/checkin/show_view_v2', { + method: 'post', + headers: this.getHeaders() + }); + + if (isSuccess) { + const result = data.data.rows.find(item => item.cell_type == '18001'); + + return result.cell_data.checkin_continue.continue_checkin_reward_show; + } + else { + $.log(`查询是否有额外奖励失败!${response}`); + + return false; + } + } +} + +!(async () => { + let cookies = []; + + // 判断环境变量里面是否有 cookie + if (process.env.SMZDM_COOKIE) { + if (process.env.SMZDM_COOKIE.indexOf('&') > -1) { + cookies = process.env.SMZDM_COOKIE.split('&'); + } + else if (process.env.SMZDM_COOKIE.indexOf('\n') > -1) { + cookies = process.env.SMZDM_COOKIE.split('\n'); + } + else { + cookies = [process.env.SMZDM_COOKIE]; + } + } + + if (!cookies[0]) { + $.log('\n请先设置 SMZDM_COOKIE 环境变量'); + + return; + } + + let notifyContent = ''; + + for (let i = 0; i < cookies.length; i++) { + const cookie = cookies[i]; + + if (!cookie) { + continue; + } + + if (i > 0) { + $.log('\n延迟 5 秒执行\n'); + await $.wait(5000); + } + + const sep = `\n******开始账号${i + 1}******\n`; + + $.log(sep); + + const bot = new SmzdmCheckinBot(cookie); + const msg = await bot.run(); + + $.log(msg + '\n'); + + notifyContent += sep + msg + '\n'; + } + + await notify.sendNotify($.name, notifyContent); +})().catch((e) => { + $.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '') +}).finally(() => { + $.done(); +}); diff --git a/smzdm_checkin.py b/smzdm_checkin.py deleted file mode 100644 index c6240f8..0000000 --- a/smzdm_checkin.py +++ /dev/null @@ -1,186 +0,0 @@ -""" -什么值得买自动签到脚本 -项目地址: https://github.com/hex-ci/smzdm_script -0 8 * * * smzdm_checkin.py -const $ = new Env("什么值得买签到"); -""" - -import hashlib -import os -import random -import sys -import time -import re -import requests -from notify import send - - -class SmzdmBot(object): - KEY = "apr1$AwP!wRRT$gJ/q.X24poeBInlUJC" - DEFAULT_USER_AGENT = "smzdm_android_V10.2.0 rv:860 (Redmi Note 3;Android10;zh)smzdmapp" - - def __init__(self, conf_kwargs: dict, index): - self.conf_kwargs = conf_kwargs - self.index = index - self.session = requests.Session() - - def _set_header(self): - request_key = f"{random.randint(10000000, 100000000) * 10000000000 + self.start_timestamp}" - headers = { - "user-agent": os.environ.get("SMZDM_USER_AGENT") or self.DEFAULT_USER_AGENT, - "request_key": request_key, - "cookie": self.conf_kwargs["COOKIE"], - "content-type": "application/x-www-form-urlencoded", - "connection": "keep-alive", - } - self.session.headers = headers - - def _data(self): - self.start_timestamp = int(time.time()) - self._set_header() - microtime = self.start_timestamp * 1000 - sk = "1" - token = self.conf_kwargs.get("TOKEN") - sign_str = f"f=android&sk={sk}&time={microtime}&token={token}&v=10.2.0&weixin=1&key={self.KEY}" - sign = self._str_to_md5(sign_str).upper() - data = { - "weixin": "1", - "captcha": "", - "f": "android", - "v": "10.2.0", - "sk": sk, - "sign": sign, - "touchstone_event": "", - "time": microtime, - "token": token, - } - return data - - def _str_to_md5(self, m: str): - return hashlib.md5(m.encode()).hexdigest() - - def checkin(self): - url = "https://user-api.smzdm.com/checkin" - - if self.index > 1: - print("延时 5 秒执行") - time.sleep(5) - - sep = "\n********开始账号" + str(self.index) + "********" - print(sep + "\n") - - data = self._data() - - resp = self.session.post(url, data) - - if resp.status_code == 200 and int(resp.json()["error_code"]) == 0: - resp_data = resp.json()["data"] - checkin_num = resp_data["daily_num"] - gold = resp_data["cgold"] - point = resp_data["cpoints"] - exp = resp_data["cexperience"] - rank = resp_data["rank"] - cards = resp_data["cards"] - - msg = f"""⭐签到成功{checkin_num}天 -🏅金币: {gold} -🏅积分: {point} -🏅经验: {exp} -🏅等级: {rank} -🏅补签卡: {cards}\n""" - - print(msg) - return sep + "\n" + msg - else: - print("登录失败", resp.json()) - msg += "登录失败\n" - return sep + "\n" + msg - - def all_reward(self): - url = "https://user-api.smzdm.com/checkin/all_reward" - data = self._data() - resp = self.session.post(url, data) - if resp.status_code == 200 and int(resp.json()["error_code"]) == 0: - resp_data = resp.json()["data"] - print(resp_data["normal_reward"]["reward_add"]["title"] + ": " + resp_data["normal_reward"]["reward_add"]["content"]) - print(resp_data["normal_reward"]["gift"]["title"] + ": " + resp_data["normal_reward"]["gift"]["content_str"] + "\n") - - def extra_reward(self): - continue_checkin_reward_show = False - userdata_v2 = self._show_view_v2() - try: - for item in userdata_v2["data"]["rows"]: - if item["cell_type"] == "18001": - continue_checkin_reward_show = item["cell_data"][ - "checkin_continue" - ]["continue_checkin_reward_show"] - break - except Exception as e: - print(f"检查额外奖励失败: {e}\n") - if not continue_checkin_reward_show: - print("今天没有额外奖励\n") - return - url = "https://user-api.smzdm.com/checkin/extra_reward" - data = self._data() - resp = self.session.post(url, data) - resp_data = resp.json()["data"] - print(resp_data["title"] + ": " + re.sub('<[^<]+?>', '', resp_data["gift"]["content"]) + "\n") - - def _show_view_v2(self): - url = "https://user-api.smzdm.com/checkin/show_view_v2" - data = self._data() - resp = self.session.post(url, data) - if resp.status_code == 200 and int(resp.json()["error_code"]) == 0: - return resp.json() - - def _vip(self): - url = "https://user-api.smzdm.com/vip" - data = self._data() - resp = self.session.post(url, data) - print(resp.json()["data"]) - - -def conf_kwargs(): - conf_kwargs = [] - - if os.environ.get("SMZDM_COOKIE", None): - cookies = os.environ["SMZDM_COOKIE"].split("&") - for cookie in cookies: - try: - token = re.findall(r"sess=(.*?);", cookie)[0] - cookie = cookie.replace("iphone", "android").replace("iPhone", "Android").replace("apk_partner_name=appstore", "apk_partner_name=android") - conf_kwargs.append({ - "COOKIE": cookie, - "TOKEN": token, - }) - except: - print("发生异常错误") - else: - print("请先设置 SMZDM_COOKIE 环境变量") - sys.exit(1) - return conf_kwargs - - -def main(conf_kwargs): - msg = "" - index = 0 - for config in conf_kwargs: - try: - index += 1 - bot = SmzdmBot(config, index) - msg += bot.checkin() - bot.all_reward() - bot.extra_reward() - except Exception as e: - print(e) - continue - - send("什么值得买签到", msg) - - if msg is None or "Fail to login in" in msg: - print("发生异常错误") - sys.exit(1) - - -if __name__ == "__main__": - main(conf_kwargs())