From 8a43d320cfa4918ed83782d9c63d364c0d9153f6 Mon Sep 17 00:00:00 2001 From: UPToZ Date: Mon, 14 Jul 2025 09:37:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=AF=B7=E6=B1=82=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E5=A2=9E=E5=8A=A0UA=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iKuuu/README.md | 5 +++++ iKuuu/ik_signin.py | 17 ++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/iKuuu/README.md b/iKuuu/README.md index 5a499b9..5c09e03 100644 --- a/iKuuu/README.md +++ b/iKuuu/README.md @@ -40,6 +40,11 @@ task ik_signin 0 0 1 * * ? ## 更新日志 +### 2025-01-14 +- 接口请求统一增加UA标识 + +--- + ### 2025-06-01 - 增加剩余流量显示 diff --git a/iKuuu/ik_signin.py b/iKuuu/ik_signin.py index d5edf8a..e31ba0f 100644 --- a/iKuuu/ik_signin.py +++ b/iKuuu/ik_signin.py @@ -41,10 +41,13 @@ except ImportError: ikun_host = "ikuuu.one" # 自动更新于2025-04-29 13:08:20 backup_hosts = ["ikuuu.one", "ikuuu.pw", "ikuuu.me"] # 备用域名列表 +# 统一的User-Agent +USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" + def get_latest_ikun_host(): test_url = f"https://{ikun_host}/" try: - response = requests.get(test_url, timeout=10) + response = requests.get(test_url, headers={"User-Agent": USER_AGENT}, timeout=10) if response.status_code == 200: if "官网域名已更改" in response.text or "Domain deprecated" in response.text: print("检测到域名变更通知,正在提取新域名...") @@ -87,7 +90,7 @@ def update_self_host(new_host): def test_host_reachable(host): try: - response = requests.get(f"https://{host}/", timeout=10) + response = requests.get(f"https://{host}/", headers={"User-Agent": USER_AGENT}, timeout=10) return response.status_code == 200 except: return False @@ -97,7 +100,7 @@ def get_remaining_flow(cookies): user_url = f'https://{ikun_host}/user' try: # 获取用户页面 - user_page = requests.get(user_url, cookies=cookies, timeout=15) + user_page = requests.get(user_url, cookies=cookies, headers={"User-Agent": USER_AGENT}, timeout=15) if user_page.status_code != 200: return "获取流量失败", "状态码: " + str(user_page.status_code) @@ -139,8 +142,8 @@ def ikuuu_signin(email, password): params = {'email': email, 'passwd': password, 'code': ''} login_url = f'https://{ikun_host}/auth/login' try: - # 登录请求 - login_res = requests.post(login_url, data=params, timeout=15) + # 登录请求,添加User-Agent + login_res = requests.post(login_url, data=params, headers={"User-Agent": USER_AGENT}, timeout=15) if login_res.status_code != 200: flow_value, flow_unit = "登录失败", "无法获取" return False, f"登录失败(状态码{login_res.status_code})", flow_value, flow_unit @@ -154,8 +157,8 @@ def ikuuu_signin(email, password): cookies = login_res.cookies flow_value, flow_unit = get_remaining_flow(cookies) - # 执行签到 - checkin_res = requests.post(f'https://{ikun_host}/user/checkin', cookies=cookies, timeout=15) + # 执行签到,添加User-Agent + checkin_res = requests.post(f'https://{ikun_host}/user/checkin', cookies=cookies, headers={"User-Agent": USER_AGENT}, timeout=15) if checkin_res.status_code != 200: return False, f"签到失败(状态码{checkin_res.status_code})", flow_value, flow_unit