新增和平小店兑换记录查询

This commit is contained in:
yml2213
2026-08-08 19:44:39 +08:00
parent 57344c7874
commit c84940a5dc
7 changed files with 668 additions and 1 deletions
+110
View File
@@ -284,6 +284,26 @@ type xiaodianRoleContext struct {
PlatID xiaodianFlexibleString `json:"platId"`
}
type xiaodianOrderList struct {
Data struct {
Count xiaodianFlexibleString `json:"cnt"`
List []xiaodianOrder `json:"list"`
} `json:"data"`
}
type xiaodianOrder struct {
BuyTime string `json:"dtBuyTime"`
PayTime string `json:"dtPayTime"`
Status string `json:"iStatus"`
GoodsRaw string `json:"sGoodsInfo"`
}
type xiaodianOrderGoods struct {
GoodsID string `json:"iGoodsId"`
GoodsName string `json:"sGoodsName"`
Quantity xiaodianFlexibleString `json:"iQuantity"`
}
// xiaodianEmbedQuery 获取斗鱼为当前账号签发的短时道具城参数。
func (c *DouyuClient) xiaodianEmbedQuery(cookie string) (url.Values, error) {
uid := cookieValue(cookie, "acf_uid")
@@ -567,6 +587,81 @@ func (c *DouyuClient) XiaodianAssets(cookie string) (types.XiaodianAssets, error
return types.XiaodianAssets{Success: true, Coupons: coupons, Fragments: fragments}, nil
}
// XiaodianExchangeList 查询和平小店真实订单记录。
func (c *DouyuClient) XiaodianExchangeList(cookie string) ([]types.XiaodianExchangeRecord, error) {
if !c.Activity.IsXiaodian {
return nil, errors.New("当前活动不是和平小店")
}
if strings.TrimSpace(cookie) == "" {
return nil, errors.New("Cookie 为空")
}
embedQuery, err := c.xiaodianEmbedQuery(cookie)
if err != nil {
return nil, err
}
endpoint, err := url.Parse(strings.TrimRight(c.Activity.RoleURL, "/") + "/")
if err != nil {
return nil, err
}
all := make([]types.XiaodianExchangeRecord, 0)
const pageSize = 100
for page := 1; page <= 100; page++ {
query := endpoint.Query()
query.Set("_service", "order.list")
query.Set("_jsvar", "info")
query.Set("acctype", "livelink")
query.Set("_app_id", "2123")
query.Set("hist", "0")
query.Set("ps", strconv.Itoa(pageSize))
query.Set("pn", strconv.Itoa(page))
query.Set("_biz_code", "cjm")
query.Set("_act_id", c.Activity.ActID)
query.Set("authType", "delegate")
query.Set("_sid", "8")
query.Set("set", "8")
for _, key := range []string{"gameId", "actId", "appId", "livePlatId", "code", "timestamp", "v", "sig"} {
query.Set(key, embedQuery.Get(key))
}
endpoint.RawQuery = query.Encode()
req, err := http.NewRequest(http.MethodGet, endpoint.String(), nil)
if err != nil {
return nil, err
}
c.setXiaodianHeaders(req)
body, err := c.doText(req, "和平小店兑换记录", true)
if err != nil {
return nil, err
}
var payload xiaodianOrderList
if err := parseXiaodianVariable(body, "info", &payload); err != nil {
return nil, fmt.Errorf("和平小店兑换记录响应解析失败: %w", err)
}
for _, order := range payload.Data.List {
var goods struct {
List []xiaodianOrderGoods `json:"list"`
}
if strings.TrimSpace(order.GoodsRaw) != "" {
if err := json.Unmarshal([]byte(order.GoodsRaw), &goods); err != nil {
return nil, fmt.Errorf("和平小店订单商品解析失败: %w", err)
}
}
for _, item := range goods.List {
all = append(all, types.XiaodianExchangeRecord{
CommodityID: item.GoodsID, CommodityName: item.GoodsName,
Quantity: parseXiaodianInt(string(item.Quantity)), BuyTime: order.BuyTime,
PayTime: order.PayTime, Status: order.Status,
})
}
}
totalCount := parseXiaodianInt(string(payload.Data.Count))
if len(payload.Data.List) == 0 || (totalCount > 0 && len(all) >= totalCount) ||
(totalCount <= 0 && len(payload.Data.List) < pageSize) {
break
}
}
return all, nil
}
func (c *DouyuClient) xiaodianAsset(cookie string, role xiaodianRoleContext, areaID, platID int, variable, service, field string, withTime bool) (int, error) {
endpoint, err := url.Parse(strings.TrimRight(c.Activity.RoleURL, "/") + "/")
if err != nil {
@@ -936,6 +1031,21 @@ func (r ExchangeListResponse) APIStatus() (int, string, bool) {
// ExchangeList 查询兑换记录列表。
func (c *DouyuClient) ExchangeList(cookie string) ([]types.ExchangeRecord, error) {
if c.Activity.IsXiaodian {
xiaodianRecords, err := c.XiaodianExchangeList(cookie)
if err != nil {
return nil, err
}
records := make([]types.ExchangeRecord, 0, len(xiaodianRecords))
for _, record := range xiaodianRecords {
records = append(records, types.ExchangeRecord{
CommodityID: record.CommodityID, CommodityName: record.CommodityName,
ShowName: record.CommodityName, ExchangeNum: record.Quantity,
Time: record.BuyTime,
})
}
return records, nil
}
var result ExchangeListResponse
if err := c.getJSON(c.Activity.ExchangeListURL, cookie, "兑换记录", &result); err != nil {
return nil, err