接口请求统一增加UA标识
This commit is contained in:
parent
fc97994ba2
commit
8a43d320cf
@ -40,6 +40,11 @@ task ik_signin 0 0 1 * * ?
|
||||
|
||||
## 更新日志
|
||||
|
||||
### 2025-01-14
|
||||
- 接口请求统一增加UA标识
|
||||
|
||||
---
|
||||
|
||||
### 2025-06-01
|
||||
- 增加剩余流量显示
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user