查询扭蛋碎片+点券
This commit is contained in:
@@ -36,6 +36,27 @@ func (a *App) QueryScore(accountName string) types.ScoreResult {
|
||||
return types.ScoreResult{Score: strconv.Itoa(score)}
|
||||
}
|
||||
|
||||
// QueryXiaodianAssets 一次查询所有账号的和平小店点券和扭蛋碎片。
|
||||
func (a *App) QueryXiaodianAssets() types.XiaodianAssetsResult {
|
||||
results := make(map[string]types.XiaodianAssets)
|
||||
if !a.getClient().Activity.IsXiaodian {
|
||||
return types.XiaodianAssetsResult{Results: results}
|
||||
}
|
||||
for _, account := range a.scheduler.AccountSnapshot() {
|
||||
if strings.TrimSpace(account.Cookie) == "" {
|
||||
results[account.Name] = types.XiaodianAssets{Error: "Cookie 为空"}
|
||||
continue
|
||||
}
|
||||
assets, err := a.getClient().XiaodianAssets(account.Cookie)
|
||||
if err != nil {
|
||||
results[account.Name] = types.XiaodianAssets{Error: "查询失败: " + err.Error()}
|
||||
continue
|
||||
}
|
||||
results[account.Name] = assets
|
||||
}
|
||||
return types.XiaodianAssetsResult{Results: results}
|
||||
}
|
||||
|
||||
// VerifyExchange 查询兑换记录,用于复验抢购结果。
|
||||
func (a *App) VerifyExchange(accountName string) types.ExchangeRecordsResult {
|
||||
if accountName == "" {
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -61,6 +61,19 @@ type ScoreResult struct {
|
||||
Score string `json:"score"`
|
||||
}
|
||||
|
||||
// XiaodianAssets 单个账号的和平小店点券与扭蛋碎片余额。
|
||||
type XiaodianAssets struct {
|
||||
Success bool `json:"success"`
|
||||
Coupons int `json:"coupons"`
|
||||
Fragments int `json:"fragments"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
// XiaodianAssetsResult 批量查询和平小店资产的结果。
|
||||
type XiaodianAssetsResult struct {
|
||||
Results map[string]XiaodianAssets `json:"results"`
|
||||
}
|
||||
|
||||
// ExchangeRecordsResult 兑换记录查询结果。
|
||||
type ExchangeRecordsResult struct {
|
||||
Success bool `json:"success"`
|
||||
|
||||
Reference in New Issue
Block a user