和平小店可以返回所有商品
This commit is contained in:
@@ -827,6 +827,7 @@ class DouyuActivityClient:
|
||||
XPD_RECOMMEND_API = "https://apps.game.qq.com/daoju/v3/recommend_xn_live_cjm/common"
|
||||
XPD_BALANCE_API = "https://apps.game.qq.com/daoju/igw/live/"
|
||||
XPD_LIVE_BUY_API = "https://apps.game.qq.com/daoju/igw/livebuy/"
|
||||
XPD_GOODS_PAGE_SIZE = 10
|
||||
XPD_UA = (
|
||||
"Mozilla/5.0 (Linux; Android 12; HBN-AL00 Build/V417IR; wv) "
|
||||
"AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 "
|
||||
@@ -953,20 +954,17 @@ class DouyuActivityClient:
|
||||
roleid: str,
|
||||
areaid: str = "1",
|
||||
) -> dict[str, Any]:
|
||||
"""查询和平小店推荐商品(category=76 全部商品)。"""
|
||||
params = {
|
||||
"""查询和平小店全部商品,排除热门抢购分类并拉取全部分页。"""
|
||||
base_params = {
|
||||
"_service": "act.recommend.query",
|
||||
"_biz_code": "cjm",
|
||||
"_app_id": "2123",
|
||||
"app_id": "2123",
|
||||
"page_begin": "0",
|
||||
"page_num": "1",
|
||||
"page_size": "200",
|
||||
"fields": (
|
||||
"iRelationGoodsid,dtModifyTime,sBuyLimitInfo,sGoodsWaterMark,dtShowBeginTime,"
|
||||
"dtShowEndTime,iSort,iGoodsId,sGoodsName,iJbPrice,iJbOrgPrice,iJb2Price,"
|
||||
"iJb2OrgPrice,iPrice,iOrgPrice,sGoodsPic,sGoodsDesc,sPayType,dtBeginTime,"
|
||||
"dtEndTime,iActionId,sExtShowInfo,sExtInfo,iCategoryId,iGoodsLeft,dtRushBegin,dtRushEnd"
|
||||
"dtEndTime,iActionId,sExtShowInfo,sExtInfo,iCategoryId,dtRushBegin,dtRushEnd"
|
||||
),
|
||||
"actionFields": "iActionId,sActionName,dtBeginTime,dtEndTime",
|
||||
"order_by": "dtShowBeginTime",
|
||||
@@ -974,36 +972,69 @@ class DouyuActivityClient:
|
||||
"desc": "1",
|
||||
"_act_id": act_id,
|
||||
"actid": act_id,
|
||||
"category": "76",
|
||||
# category=76 是“热门抢购”;全部商品页明确将其排除。
|
||||
"excludeFields": "iCategoryId_76",
|
||||
"userid": openid,
|
||||
"roleid": roleid,
|
||||
"area": "1",
|
||||
"areaid": str(areaid),
|
||||
"need_limit": "1",
|
||||
}
|
||||
response = self._request(
|
||||
"get",
|
||||
self.XPD_RECOMMEND_API,
|
||||
source="刷新小店商品",
|
||||
params=params,
|
||||
headers=self._xpd_daoju_headers(),
|
||||
)
|
||||
recommend = self._xpd_parse_var(response.text, "recommend")
|
||||
items = (((recommend.get("data") or {}).get("client_data") or {}).get("itemsdetail")) or []
|
||||
goods = []
|
||||
for item in items:
|
||||
goods.append(
|
||||
{
|
||||
"commodity_id": str(item.get("iGoodsId") or ""),
|
||||
"name": str(item.get("sGoodsName") or ""),
|
||||
"price": self._xpd_int(item.get("iPrice")),
|
||||
"org_price": self._xpd_int(item.get("iOrgPrice")),
|
||||
"category": str(item.get("iCategoryId") or ""),
|
||||
"goods_left": self._xpd_int(item.get("iGoodsLeft")),
|
||||
"raw": item,
|
||||
}
|
||||
goods: list[dict[str, Any]] = []
|
||||
seen_ids: set[str] = set()
|
||||
pages: list[dict[str, Any]] = []
|
||||
offset = 0
|
||||
page_num = 1
|
||||
|
||||
while True:
|
||||
params = {
|
||||
**base_params,
|
||||
"page_begin": str(offset),
|
||||
"page_num": str(page_num),
|
||||
"page_size": str(self.XPD_GOODS_PAGE_SIZE),
|
||||
}
|
||||
response = self._request(
|
||||
"get",
|
||||
self.XPD_RECOMMEND_API,
|
||||
source=f"刷新小店全部商品第 {page_num} 页",
|
||||
params=params,
|
||||
headers=self._xpd_daoju_headers(),
|
||||
)
|
||||
return {"goods": goods, "raw": recommend}
|
||||
recommend = self._xpd_parse_var(response.text, "recommend")
|
||||
if str(recommend.get("errcode") or "0") != "0":
|
||||
raise DouyuActivityError(str(recommend.get("errdesc") or "小店商品查询失败"))
|
||||
pages.append(recommend)
|
||||
items = (((recommend.get("data") or {}).get("client_data") or {}).get("itemsdetail")) or []
|
||||
if not isinstance(items, list):
|
||||
raise DouyuActivityError("小店商品响应格式异常")
|
||||
|
||||
for item in items:
|
||||
if not isinstance(item, dict):
|
||||
continue
|
||||
commodity_id = str(item.get("iGoodsId") or "")
|
||||
if not commodity_id or commodity_id in seen_ids:
|
||||
continue
|
||||
seen_ids.add(commodity_id)
|
||||
goods.append(
|
||||
{
|
||||
"commodity_id": commodity_id,
|
||||
"name": str(item.get("sGoodsName") or ""),
|
||||
"price": self._xpd_int(item.get("iPrice")),
|
||||
"org_price": self._xpd_int(item.get("iOrgPrice")),
|
||||
"category": str(item.get("iCategoryId") or ""),
|
||||
"goods_left": self._xpd_int(item.get("iGoodsLeft")),
|
||||
"raw": item,
|
||||
}
|
||||
)
|
||||
|
||||
if len(items) < self.XPD_GOODS_PAGE_SIZE:
|
||||
break
|
||||
offset += self.XPD_GOODS_PAGE_SIZE
|
||||
page_num += 1
|
||||
if page_num > 100:
|
||||
raise DouyuActivityError("小店商品分页超出安全上限")
|
||||
|
||||
return {"goods": goods, "raw": {"pages": pages}}
|
||||
|
||||
def xpd_bind_qr(self, *, act_alias: str) -> dict[str, Any]:
|
||||
"""生成和平小店绑定二维码链接(微信扫码进入 livelink 小程序绑定角色)。
|
||||
|
||||
Reference in New Issue
Block a user