feat(weibo): 增加协作 CK 批量复制与商品图片代理

This commit is contained in:
yml
2026-11-12 14:12:50 +08:00
parent 31045e0f2e
commit 0e29717c97
18 changed files with 604 additions and 153 deletions
+2
View File
@@ -18,6 +18,7 @@ from .client import (
WeiboTransportError,
extract_bind_raw_url,
normalize_weibo_cookie,
normalize_weibo_image_url,
)
__all__ = [
@@ -38,4 +39,5 @@ __all__ = [
"WeiboTransportError",
"extract_bind_raw_url",
"normalize_weibo_cookie",
"normalize_weibo_image_url",
]
+28 -1
View File
@@ -221,6 +221,17 @@ def normalize_weibo_cookie(raw: str) -> str:
return "; ".join(pairs)
def normalize_weibo_image_url(value: Any) -> str:
"""把微博返回的图片地址升级为 HTTPS,避免浏览器拦截混合内容。"""
text = unescape(str(value or "")).strip()
if text.startswith("//"):
return f"https:{text}"
if text.lower().startswith("http://"):
return f"https://{text[7:]}"
return text
def _parse_cookie_pairs(cookie: str) -> dict[str, str]:
pairs: dict[str, str] = {}
for item in cookie.split(";"):
@@ -491,7 +502,23 @@ class WeiboClient:
"/mall/list",
params={"F": activity, "_t": int(time.time() * 1000)},
)
return payload.get("data") or {}
data = payload.get("data") or {}
if not isinstance(data, dict):
return {}
goods = data.get("list")
if not isinstance(goods, list):
return data
normalized_goods = []
for item in goods:
if not isinstance(item, dict):
normalized_goods.append(item)
continue
normalized = dict(item)
normalized["goods_image"] = normalize_weibo_image_url(
item.get("goods_image")
)
normalized_goods.append(normalized)
return {**data, "list": normalized_goods}
def exchange_goods(
self,