重构为 HTTP SSO 扫码方案并引入 Vue3 前端
移除 Playwright 浏览器自动化,改用 passport/SSO HTTP 接口获取二维码与轮询登录;后端模块化拆分,前端替换为 Vue3 SPA。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import requests
|
||||
import time
|
||||
|
||||
UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
|
||||
headers = {
|
||||
"User-Agent": UA,
|
||||
"Referer": "https://www.douyin.com/",
|
||||
"Accept": "application/json, text/plain, */*",
|
||||
"Origin": "https://www.douyin.com",
|
||||
}
|
||||
s = requests.Session()
|
||||
reg = s.post(
|
||||
"https://ttwid.bytedance.com/ttwid/union/register/",
|
||||
json={
|
||||
"region": "cn",
|
||||
"aid": 1768,
|
||||
"needFid": False,
|
||||
"service": "www.douyin.com",
|
||||
"migrate_info": {"ticket": "", "source": "web"},
|
||||
"cbUrlProtocol": "https",
|
||||
"union": True,
|
||||
},
|
||||
headers=headers,
|
||||
timeout=15,
|
||||
).json()
|
||||
cb = reg.get("redirect_url")
|
||||
if cb:
|
||||
s.get(cb, headers=headers, timeout=15, allow_redirects=True)
|
||||
s.get("https://www.douyin.com/", headers=headers, timeout=15)
|
||||
s.get("https://www.douyin.com/passport/web/login/", headers=headers, timeout=15)
|
||||
print("cookies", [c.name for c in s.cookies])
|
||||
try:
|
||||
rr = s.get("https://www.douyin.com/passport/web/csrf/token/", headers=headers, timeout=10)
|
||||
print("csrf", rr.status_code, rr.text[:200])
|
||||
except Exception as e:
|
||||
print("csrf err", e)
|
||||
ts = int(time.time() * 1000)
|
||||
tests = [
|
||||
("sso", "https://sso.douyin.com/get_qrcode/", {"aid": "6383", "service": "https://www.douyin.com", "is_vcd": "1", "t": ts}),
|
||||
("passport", "https://www.douyin.com/passport/web/get_qrcode/", {"aid": "6383", "service": "https://www.douyin.com", "need_logo": "false", "t": ts}),
|
||||
("creator", "https://sso.douyin.com/get_qrcode/", {"aid": "2906", "next": "https://creator.douyin.com", "service": "https://creator.douyin.com", "is_vcd": "1", "t": ts}),
|
||||
]
|
||||
for name, url, params in tests:
|
||||
r = s.get(url, params=params, headers=headers, timeout=15)
|
||||
ct = r.headers.get("content-type", "")
|
||||
print("---", name, r.status_code, ct)
|
||||
print(r.text[:400])
|
||||
Reference in New Issue
Block a user