fix(weibo): 将支付风控检测并入账号 CK 校验
This commit is contained in:
+99
-4
@@ -606,8 +606,10 @@ class WeiboClient:
|
||||
def _load_recharge_context(
|
||||
self,
|
||||
activity: str,
|
||||
) -> tuple[dict[str, str], dict[str, Any], dict[str, Any]]:
|
||||
home = self.fetch_home(activity)
|
||||
*,
|
||||
home: WeiboHomeSnapshot | None = None,
|
||||
) -> tuple[str, dict[str, str], dict[str, Any], dict[str, Any]]:
|
||||
home = home or self.fetch_home(activity)
|
||||
if not home.recharge_url:
|
||||
raise WeiboRechargeError("当前活动没有可用的助威充值入口")
|
||||
subscribe = _subscribe_params(home.recharge_url)
|
||||
@@ -679,7 +681,98 @@ class WeiboClient:
|
||||
base=WEIBO_VPLUS_API_BASE,
|
||||
headers=page_headers,
|
||||
)
|
||||
return subscribe, current_tab, cashier_payload.get("data") or {}
|
||||
return home.uid, subscribe, current_tab, cashier_payload.get("data") or {}
|
||||
|
||||
def check_payment_access(
|
||||
self,
|
||||
activity: str = "",
|
||||
*,
|
||||
home: WeiboHomeSnapshot | None = None,
|
||||
) -> None:
|
||||
"""账号检测时确认 CK 也能进入微博支付域。"""
|
||||
|
||||
uid, _, _, cashier_data = self._load_recharge_context(
|
||||
activity,
|
||||
home=home,
|
||||
)
|
||||
tabs = cashier_data.get("tab_info") or []
|
||||
tab = next(
|
||||
(
|
||||
item
|
||||
for item in tabs
|
||||
if isinstance(item, dict) and item.get("is_current")
|
||||
),
|
||||
tabs[0] if tabs and isinstance(tabs[0], dict) else {},
|
||||
)
|
||||
menu = next(
|
||||
(
|
||||
item
|
||||
for item in tab.get("menu") or []
|
||||
if isinstance(item, dict) and item.get("weibo_unified_params")
|
||||
),
|
||||
None,
|
||||
)
|
||||
if menu is None:
|
||||
raise WeiboRechargeError("收银台没有返回支付检测参数")
|
||||
self._preflight_recharge(uid, menu)
|
||||
|
||||
def _preflight_recharge(
|
||||
self,
|
||||
uid: str,
|
||||
menu: dict[str, Any],
|
||||
) -> None:
|
||||
"""确认当前 CK 能通过微博支付域;此接口不会创建订单。"""
|
||||
|
||||
unified = menu.get("weibo_unified_params") or {}
|
||||
response = self.session.post(
|
||||
f"{WEIBO_PAY_BASE}/aj/pay/modular/prepare",
|
||||
data={
|
||||
"uid": uid,
|
||||
"seller_id": str(unified.get("seller_id") or ""),
|
||||
"modular_id": str(unified.get("modular_id") or ""),
|
||||
"default_cashier": str(unified.get("default_cashier") or ""),
|
||||
"total_amount": str(menu.get("price") or 6000),
|
||||
"hidden_channel": "0",
|
||||
"extra": json.dumps(
|
||||
{"goods_type": 2},
|
||||
separators=(",", ":"),
|
||||
),
|
||||
"gsid": "",
|
||||
"lang": "zh_cn",
|
||||
"is4g": "0",
|
||||
"from": "",
|
||||
"aid": "",
|
||||
"wm": "",
|
||||
},
|
||||
headers={
|
||||
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
|
||||
"User-Agent": WEIBO_DESKTOP_UA,
|
||||
"Origin": "https://vipclub.weibo.com",
|
||||
"Referer": "https://vipclub.weibo.com/",
|
||||
},
|
||||
allow_redirects=False,
|
||||
timeout=self.timeout,
|
||||
)
|
||||
location = response.headers.get("location", "")
|
||||
location_url = urlsplit(location) if location else None
|
||||
if response.status_code in {301, 302, 303, 307, 308}:
|
||||
if location_url and location_url.path == "/sso/login.php":
|
||||
raise WeiboRechargeError(
|
||||
"微博支付未登录:当前 CK 能访问微豆页面,"
|
||||
"但不能用于支付,请重新登录微博后重新导入 CK"
|
||||
)
|
||||
if location_url and location_url.path == "/sorry":
|
||||
query = parse_qs(location_url.query, keep_blank_values=True)
|
||||
if "usernotexists" in query:
|
||||
raise WeiboRechargeError(
|
||||
"微博支付账号不存在或未开通支付资格,"
|
||||
"请先在微博 App/网页确认该账号可以正常发起支付"
|
||||
)
|
||||
raise WeiboRechargeError(
|
||||
"微博支付预检被拒绝,请重新登录微博后重新导入 CK"
|
||||
)
|
||||
if response.status_code >= 400:
|
||||
raise WeiboRechargeError(f"微博支付预检失败: HTTP {response.status_code}")
|
||||
|
||||
def _recharge_bid(
|
||||
self,
|
||||
@@ -718,7 +811,9 @@ class WeiboClient:
|
||||
|
||||
if amount_yuan < 1:
|
||||
raise WeiboRechargeError("充值金额至少为 1 元")
|
||||
subscribe, current_tab, cashier_data = self._load_recharge_context(activity)
|
||||
_uid, subscribe, current_tab, cashier_data = self._load_recharge_context(
|
||||
activity
|
||||
)
|
||||
tabs = cashier_data.get("tab_info") or []
|
||||
tab = next(
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user