"""HTTP cdnws 通道的下单/支付参数对齐(2026-10-13 积分中心抓包)。 外部 CK(只有登录态、无网页设备态)会走 HTTP 通道,因此 HTTP 侧的参数必须与 抓包一致:jifencenter 标记、空点击序列、m-shop.huya.com 回调、appInfo.scene 与 订单 src/orderScene 分离。 """ from core.huya.http_client import HuyaHttpClient def _recording_client(): client = HuyaHttpClient(logger=lambda _message: None) recorded: list[tuple[str, str, object]] = [] def fake_call_rpc( service, method, req_struct, rsp_class=None, uid=0, guid="", cookie="", **kwargs ): recorded.append((service, method, req_struct)) client.call_rpc = fake_call_rpc # type: ignore[method-assign] return client, recorded def test_http_create_order_matches_points_capture(): client, recorded = _recording_client() client.create_order( uid=1199665170519, guid="", cookie="yyuid=1199665170519", pid=1199650619883, spu_id="hy-8328015", sku_id=7756811, ) service, method, req = recorded[-1] assert (service, method) == ("shopMiddleUI", "createOrderV5") assert req.shopAppInfo.scene == 7 # appInfo scene assert req.src == 4 # 订单侧 scene assert req.orderScene == 4 assert req.orderType == 6 assert req.extraParam.bizParams == '{ "jifencenter": 1 }' assert req.env == {"user_click_seq": "[]"} assert req.bizType == 5 assert req.gameCategoryId == 507 def test_http_get_goods_info_uses_app_scene(): client, recorded = _recording_client() client.get_goods_info( uid=1199665170519, guid="", cookie="yyuid=1199665170519", pid=1199650619883, spu_id="hy-8328015", ) service, method, req = recorded[-1] assert (service, method) == ("shopMiddleUI", "getGoodsInfoV5") assert req.shopAppInfo.scene == 7 assert req.pid == 1199650619883 assert req.spuId == "hy-8328015" def test_http_pay_order_submit_points_callback_and_env(monkeypatch): captured: dict[str, bytes] = {} class _StopAfterCapture(Exception): pass def fake_urlopen(request, timeout=None): captured["body"] = request.data raise _StopAfterCapture monkeypatch.setattr("urllib.request.urlopen", fake_urlopen) client = HuyaHttpClient(logger=lambda _message: None) result = client.pay_order_submit( uid=1199665170519, guid="", cookie="yyuid=1199665170519", order_id=11339649, pay_type="Zfb", pid=1199650619883, ) assert result is None # 捕获到请求即中断,不关心响应 body = captured["body"] assert ( b"https://m-shop.huya.com/points.html#/consumer/paycallback" b"?orderId=11339649&pid=1199650619883&sourceId=yellowcarlist" ) in body assert b"user_click_seq" in body assert b"input_1" not in body