diff --git a/.env.example b/.env.example index 8a19750..b0771e0 100644 --- a/.env.example +++ b/.env.example @@ -1,9 +1,10 @@ # 复制为 .env 并填入真实值(.env 已被 .gitignore 忽略,请勿提交) ICENTER_ACCOUNT=你的工号 ICENTER_PASSWORD=你的密码 -# iEPMS token(长效)。从零纯 Python 登录被 EMM 设备绑定拦截("用户设备无效"), -# 故 token 用 tools/extract_token.py 从手机抓包中提取后填这里。 +# 登录成功后写入。也可继续用 tools/extract_token.py 从抓包更新。 ICENTER_TOKEN= +# 登录报文里的 clientIp,任意非空 IPv4 即可。不填则用 0.0.0.0。 +ICENTER_CLIENT_IP= # 打卡所属项目/组织(从抓包 listMy 请求或 x-proj-id 头获取) ICENTER_PROJECT_ID= ICENTER_ORG_ID=10001 diff --git a/src/punchlog/auth.py b/src/punchlog/auth.py index 3772bf6..f2afc99 100644 --- a/src/punchlog/auth.py +++ b/src/punchlog/auth.py @@ -10,12 +10,14 @@ Flow (from cn.com.zte.app.ztesso.manager.SSOManager.getResponse + SSOTokenReques from __future__ import annotations import json +import os import time from dataclasses import dataclass, field import requests from . import msa +from .config import load_env EMP_BASE = "https://mdm.zte.com.cn/emp/zte-itp-emp-sso" CONTENT_TYPE = "application/json; charset=utf-8" @@ -27,9 +29,11 @@ DEFAULT_DEVICE = { "deviceNum": "V02_CF64B4B1544AC5D3DB79656332385175;V02_CF64B4B1544AC5D3DB79656332385175;AID_034b7912-c21d-3bb3-9bfe-ea789d753967", "deviceBrand": "Redmi", "deviceMode": "25053RT47C", - "deviceName": "Redmi 25053RT47C", - "androidId": "034b7912-c21d-3bb3-9bfe-ea789d753967", - "clientIp": "192.168.1.100", + "deviceName": "Redmi-25053RT47C", + # getMobileAndroidID() returns "AID_" + local uuid, not the raw uuid. + "androidId": "AID_034b7912-c21d-3bb3-9bfe-ea789d753967", + # Any non-empty IPv4 is accepted. The app sends the Wi-Fi address, or 0.0.0.0 when Wi-Fi is off. + "clientIp": "0.0.0.0", "versionName": "12.8.1", "versionCode": 120805, } @@ -72,6 +76,7 @@ def _build_login_payload(emp_no: str, password: str, tenant_id: str) -> dict: Gson omits null fields, so secretKey/accountId/token are not included. """ d = DEFAULT_DEVICE + client_ip = os.environ.get("ICENTER_CLIENT_IP") or load_env().get("ICENTER_CLIENT_IP") or d["clientIp"] return { "loginName": emp_no, "loginPwd": password, @@ -83,14 +88,20 @@ def _build_login_payload(emp_no: str, password: str, tenant_id: str) -> dict: "androidId": d["androidId"], # getMobileAndroidID (AID uuid) "deviceType": 1, "deviceName": d["deviceName"], # Build.BRAND + "-" + Build.MODEL - "os": 0, - "clientIp": d["clientIp"], + # Kotlin default for the omitted os argument is 2 (Android), not 0. + "os": 2, + "clientIp": client_ip, "packageName": "com.zte.softda", "versionName": d["versionName"], - "versionCode": 0, + # Omitted versionCode calls SSOConstant.getVersionCode(), i.e. the installed versionCode. + "versionCode": d["versionCode"], "sequence": "relogin", # SSOConstant.TYPE_RELOGIN "extendMap": {"timestamp": str(int(time.time() * 1000))}, + # Omitted strings default to "" and Gson still serializes them. + "secretKey": "", + "accountId": "", "returnUserInfo": 0, + "token": "", }