更新
This commit is contained in:
@@ -8,7 +8,7 @@ from urllib.parse import unquote
|
||||
import requests
|
||||
|
||||
from .auth import DouyinAuth
|
||||
from .dy_util import generate_a_bogus, generate_msToken, generate_webid, splice_url
|
||||
from .dy_util import DEFAULT_USER_AGENT, generate_a_bogus, generate_msToken, generate_webid, splice_url
|
||||
from .session import DouyinImSession, is_frontier_ws_url
|
||||
|
||||
logger = logging.getLogger("douyin_im.frontier")
|
||||
@@ -42,6 +42,7 @@ def fetch_device_id(session: DouyinImSession) -> str:
|
||||
session.cookie_header(),
|
||||
session.web_protect_str,
|
||||
session.keys_str,
|
||||
user_agent=session.user_agent or DEFAULT_USER_AGENT,
|
||||
)
|
||||
url = "https://www.douyin.com/aweme/v1/web/query/user"
|
||||
headers = {
|
||||
@@ -134,12 +135,31 @@ def ensure_frontier_ws(session: DouyinImSession) -> Optional[str]:
|
||||
logger.info("Using captured real frontier WS URL (with sdk_cert)")
|
||||
return url
|
||||
|
||||
# Only fpid=9 is Douyin private messaging. Other Frontier products (for
|
||||
# example fpid=971 opened by the generic /chat page shell) also handshake
|
||||
# successfully but never carry this account's IM push stream.
|
||||
for url in session.ws_urls:
|
||||
if (
|
||||
is_frontier_ws_url(url)
|
||||
and "zijieapi.com" in url
|
||||
and "access_key=" in url
|
||||
and re.search(r"[?&]fpid=9(?:&|$)", url)
|
||||
and _ws_device_matches_session(session, url)
|
||||
):
|
||||
session.ws_urls = [url]
|
||||
logger.info("Using captured browser frontier WebSocket URL")
|
||||
return url
|
||||
|
||||
for url in session.ws_urls:
|
||||
if is_frontier_ws_url(url) and _ws_token_looks_encoded(url):
|
||||
session.ws_urls = [url]
|
||||
logger.info("Using captured frontier WS URL")
|
||||
return url
|
||||
|
||||
# frontier 按 device_id 寻址推送,它不是账号 UID:抖音 query/user 返回的
|
||||
# id 才是本浏览器的设备注册号(my_uid 走 DouyinAuth,两者不能互换)。
|
||||
# 用 my_uid 拼出来的地址握手同样成功,但订阅的是另一个地址,
|
||||
# 于是长连接一直是「连上但收不到任何私信」。
|
||||
device_id = resolve_frontier_device_id(session)
|
||||
if not device_id:
|
||||
session.ws_urls = []
|
||||
|
||||
Reference in New Issue
Block a user