diff --git a/README.md b/README.md
index 74578cb..274eeb1 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,10 @@
# 什么值得买每日签到脚本
+
+
-
-
-
+
## 1. 实现功能
@@ -38,9 +38,9 @@ schedule:
6. (可选) Secret 新增`TG_BOT_TOKEN` 和`TG_USER_ID`用于推送通知
7. (可选) Secret 新增`TG_BOT_API`用于自定义反代的`Telegram Bot API`
-### 2.2 本地运行
+### 2.2 本地运行(支持多用户)
-复制`app/config/config_example.toml`为`app/config/config.toml`,并按照需求配置
+参考模板`app/config/config_example.toml`. 复制`app/config/config_example.toml`为`app/config/config.toml`,并按照需求配置
```bash
python3 -m venv .venv
@@ -78,15 +78,23 @@ SCH_MINUTE=
### 3.1 手机抓包
+> 抓包有一定门槛,请酌情尝试.
+
抓包工具可使用 HttpCanary,教程参考[HttpCanary 抓包](https://juejin.cn/post/7177682063699968061)
1. 按照上述教程配置好 HttpCanary
2. 开始抓包,并打开什么值得买 APP
3. 过滤域名为`user-api.smzdm.com`的 post 请求
+4. 点击右上角分享,复制 cURL,转换 curl 请求为 python 格式,[方法](https://curlconverter.com/)
## 更新日志
- 2022-12-08, 签到失败,浏览器端签到需要滑动验证码认证
- 2023-01-11, 更改`User-Agent`为`iPhone`后可`bypass`滑块认证
- 2023-01-14, 登录认证失败, 签到失效
-- 2023-02-18, 通过安卓端验证登录,感谢[jzksnsjswkw/smzdm-app](https://github.com/jzksnsjswkw/smzdm-app)的思路。旧版代码查看[old](https://github.com/Chasing66/smzdm_bot/tree/old)分支
+- 2023-02-18, 通过安卓端验证登录,感谢[jzksnsjswkw/smzdm-app](https://github.com/jzksnsjswkw/smzdm-app)的思路. 旧版代码查看[old](https://github.com/Chasing66/smzdm_bot/tree/old)分支
+- 2023-02-25, 新增`all_reward` 和`extra_reward`两个接口,本地支持多用户运行
+
+## Stargazers over time
+
+[](https://starchart.cc/Chasing66/smzdm_bot)
diff --git a/app/config/config_example.toml b/app/config/config_example.toml
index 55affbc..a52fe3e 100644
--- a/app/config/config_example.toml
+++ b/app/config/config_example.toml
@@ -1,11 +1,18 @@
-# Cookie
+[user.A]
USER_AGENT = ""
ANDROID_COOKIE = ""
SK = ""
TOKEN = ""
-# Notification
+[user.B]
+USER_AGENT = ""
+ANDROID_COOKIE = ""
+SK = ""
+TOKEN = ""
+
+
+[notify]
PUSH_PLUS_TOKEN = ""
SC_KEY = ""
TG_BOT_TOKEN = ""
-TG_USER_ID = ""
+TG_USER_ID = ""
\ No newline at end of file
diff --git a/app/main.py b/app/main.py
index bf5b92a..7cafe9a 100644
--- a/app/main.py
+++ b/app/main.py
@@ -8,7 +8,6 @@ from pathlib import Path
import prettytable as pt
import requests
from loguru import logger
-
from notify.notify import NotifyBot
from utils.file_helper import TomlHelper
@@ -28,10 +27,11 @@ class SmzdmBot(object):
def _set_header(self):
request_key = f"{random.randint(10000000, 100000000) * 10000000000 + self.start_timestamp}"
headers = {
- "user-agent": self.conf_kwargs.get("USER_AGENT"),
+ "user-agent": self.conf_kwargs["USER_AGENT"],
"request_key": request_key,
- "cookie": self.conf_kwargs.get("ANDROID_COOKIE"),
+ "cookie": self.conf_kwargs["ANDROID_COOKIE"],
"content-type": "application/x-www-form-urlencoded",
+ "connection": "keep-alive",
}
self.session.headers = headers
@@ -73,7 +73,7 @@ class SmzdmBot(object):
tb.field_names = ["签到天数", "金币", "积分", "经验", "等级", "补签卡"]
tb.add_row([checkin_num, gold, point, exp, rank, cards])
logger.info(f"\n{tb}")
- msg = f"""⭐签到成功{checkin_num}天
+ msg = f"""\n⭐签到成功{checkin_num}天
🏅金币{gold}
🏅积分{point}
🏅经验{exp}
@@ -85,13 +85,54 @@ class SmzdmBot(object):
msg = "Fail to login in"
return msg
+ def all_reward(self):
+ url = "https://user-api.smzdm.com/checkin/extra_reward"
+ data = self._data()
+ resp = self.session.post(url, data)
+ if resp.status_code == 200 and int(resp.json()["error_code"]) == 0:
+ logger.info(resp.json()["data"])
-def main():
+ 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:
+ logger.error(f"Fail to check extra reward: {e}")
+ if not continue_checkin_reward_show:
+ logger.info("No extra reward today")
+ return
+ url = "https://user-api.smzdm.com/checkin/extra_reward"
+ data = self._data()
+ resp = self.session.post(url, data)
+ logger.info(resp.json()["data"])
+
+ 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)
+ logger.info(resp.json()["data"])
+
+
+def conf_kwargs():
conf_kwargs = {}
if Path.exists(Path(CONFIG_PATH, "config.toml")):
logger.info("Get configration from config.toml")
conf_kwargs = TomlHelper(Path(CONFIG_PATH, "config.toml")).read()
+ conf_kwargs.update({"toml_conf": True})
elif os.environ.get("ANDROID_COOKIE", None):
logger.info("Get configration from env")
conf_kwargs = {
@@ -105,15 +146,36 @@ def main():
"TG_USER_ID": os.environ.get("TG_USER_ID", None),
"TG_BOT_API": os.environ.get("TG_BOT_API", None),
}
+ conf_kwargs.update({"env_conf": True})
else:
logger.info("Please set cookies first")
sys.exit(1)
- msg = SmzdmBot(conf_kwargs).checkin()
- NotifyBot(content=msg, **conf_kwargs)
- if msg == "Fail to login in":
+ return conf_kwargs
+
+
+def main(conf_kwargs):
+ msg = ""
+ if conf_kwargs.get("toml_conf"):
+ for i in conf_kwargs["user"]:
+ try:
+ bot = SmzdmBot(conf_kwargs["user"][i])
+ msg += bot.checkin()
+ bot.all_reward()
+ bot.extra_reward()
+ except Exception as e:
+ logger.error(e)
+ continue
+ NotifyBot(content=msg, **conf_kwargs["notify"])
+ else:
+ bot = SmzdmBot(conf_kwargs)
+ msg = bot.checkin()
+ bot.all_reward()
+ bot.extra_reward()
+ NotifyBot(content=msg, **conf_kwargs)
+ if msg is None or "Fail to login in" in msg:
logger.error("Fail the Github action job")
sys.exit(1)
if __name__ == "__main__":
- main()
+ main(conf_kwargs())
diff --git a/app/notify/notify.py b/app/notify/notify.py
index 60c29b3..914ab01 100644
--- a/app/notify/notify.py
+++ b/app/notify/notify.py
@@ -71,15 +71,15 @@ class NotifyBot(object):
)
return
- TG_BOT_API = self.kwargs.get("TG_BOT_API", "https://api.telegram.org")
+ TG_BOT_API = self.kwargs.get("TG_BOT_API", "https://api.telegram.org/")
url = urljoin(TG_BOT_API, f"/bot{TG_BOT_TOKEN}/sendMessage")
headers = {"Content-Type": "application/x-www-form-urlencoded"}
- payload = {
+ params = {
"chat_id": str(TG_USER_ID),
- "text": f"{self.title}\n\n{self.content}",
+ "text": f"{self.title}\n{self.content}",
"disable_web_page_preview": "true",
}
- resp = requests.post(url=url, headers=headers, params=payload)
+ resp = requests.post(url=url, headers=headers, params=params)
if resp.status_code == 200:
logger.info("✅ Telegram Bot notified")
return resp.json()