查询扭蛋碎片+点券
This commit is contained in:
@@ -280,6 +280,7 @@ type xiaodianRoleContext struct {
|
||||
RoleID xiaodianFlexibleString `json:"roleId"`
|
||||
Type xiaodianFlexibleString `json:"type"`
|
||||
Area xiaodianFlexibleString `json:"area"`
|
||||
PlatID xiaodianFlexibleString `json:"platId"`
|
||||
}
|
||||
|
||||
// xiaodianEmbedQuery 获取斗鱼为当前账号签发的短时道具城参数。
|
||||
@@ -504,6 +505,89 @@ func (c *DouyuClient) xiaodianProductPage(endpoint *url.URL, query url.Values) (
|
||||
return items, nil
|
||||
}
|
||||
|
||||
// XiaodianAssets 查询一个账号的点券与扭蛋碎片,角色信息只解析一次。
|
||||
func (c *DouyuClient) XiaodianAssets(cookie string) (types.XiaodianAssets, error) {
|
||||
if !c.Activity.IsXiaodian {
|
||||
return types.XiaodianAssets{}, errors.New("当前活动不是和平小店")
|
||||
}
|
||||
if strings.TrimSpace(cookie) == "" {
|
||||
return types.XiaodianAssets{}, errors.New("Cookie 为空")
|
||||
}
|
||||
embedQuery, err := c.xiaodianEmbedQuery(cookie)
|
||||
if err != nil {
|
||||
return types.XiaodianAssets{}, err
|
||||
}
|
||||
role, err := c.xiaodianRole(embedQuery)
|
||||
if err != nil {
|
||||
return types.XiaodianAssets{}, err
|
||||
}
|
||||
if role.OpenID == "" || role.RoleID == "" {
|
||||
return types.XiaodianAssets{}, errors.New("未获取到和平小店绑定角色")
|
||||
}
|
||||
areaID := parseXiaodianInt(string(role.Area))
|
||||
if areaID <= 0 {
|
||||
areaID = 1
|
||||
}
|
||||
platID := parseXiaodianInt(string(role.PlatID))
|
||||
if platID <= 0 {
|
||||
platID = 1
|
||||
}
|
||||
coupons, err := c.xiaodianAsset(cookie, role, areaID, platID, "banlanceInfo", "pay.midas.dq.get.ttpp", "balance", true)
|
||||
if err != nil {
|
||||
return types.XiaodianAssets{}, err
|
||||
}
|
||||
fragments, err := c.xiaodianAsset(cookie, role, areaID, platID, "jbInfos", "pay.idip.gamecoin.get", "jb2", false)
|
||||
if err != nil {
|
||||
return types.XiaodianAssets{}, err
|
||||
}
|
||||
return types.XiaodianAssets{Success: true, Coupons: coupons, Fragments: fragments}, 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 {
|
||||
return 0, err
|
||||
}
|
||||
query := endpoint.Query()
|
||||
query.Set("_jsvar", variable)
|
||||
query.Set("_service", service)
|
||||
query.Set("_app_id", "2123")
|
||||
query.Set("acctype", "ttpp")
|
||||
query.Set("areaid", strconv.Itoa(areaID))
|
||||
query.Set("eventid", "")
|
||||
query.Set("interwork", "0")
|
||||
query.Set("openid", string(role.OpenID))
|
||||
query.Set("openkey", "openkey")
|
||||
query.Set("partition", "0")
|
||||
query.Set("pay_token", "")
|
||||
query.Set("plat", strconv.Itoa(platID))
|
||||
query.Set("plat_pc", "0")
|
||||
query.Set("roleid", string(role.RoleID))
|
||||
query.Set("_biz_code", "cjm")
|
||||
query.Set("_act_id", c.Activity.ActID)
|
||||
query.Set("_sid", "6")
|
||||
if withTime {
|
||||
query.Set("_time", strconv.FormatInt(time.Now().Unix(), 10))
|
||||
} else {
|
||||
query.Set("coin_type", "1")
|
||||
}
|
||||
endpoint.RawQuery = query.Encode()
|
||||
req, err := http.NewRequest(http.MethodGet, endpoint.String(), nil)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
c.setXiaodianHeaders(req)
|
||||
body, err := c.doText(req, "查询小店资产", true)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
var payload map[string]xiaodianFlexibleString
|
||||
if err := parseXiaodianVariable(body, variable, &payload); err != nil {
|
||||
return 0, fmt.Errorf("和平小店%s响应解析失败: %w", field, err)
|
||||
}
|
||||
return parseXiaodianInt(string(payload[field])), nil
|
||||
}
|
||||
|
||||
// parseXiaodianInt 将 QQ 道具接口中的字符串数值转为界面商品字段。
|
||||
func parseXiaodianInt(value string) int {
|
||||
parsed, err := strconv.Atoi(strings.TrimSpace(value))
|
||||
|
||||
Reference in New Issue
Block a user