Skip to content

Commit

Permalink
add topic complete
Browse files Browse the repository at this point in the history
  • Loading branch information
zc2638 committed Sep 19, 2022
1 parent fc854be commit dff5e96
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 64 deletions.
22 changes: 0 additions & 22 deletions index.html

This file was deleted.

44 changes: 2 additions & 42 deletions pkg/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ package command
import (
"errors"
"fmt"
"math/rand"
"net/http"
"strconv"

"github.com/tidwall/gjson"

"github.com/go-resty/resty/v2"
"github.com/spf13/cobra"
"github.com/zc2638/ylgy/pkg/core"
)

type Option struct {
Expand All @@ -36,7 +31,7 @@ func NewRootCommand() *cobra.Command {
times = opt.Times
}
for i := 0; i < times; i++ {
if err := Send(opt.Token); err != nil {
if err := core.Send(opt.Token); err != nil {
return err
}
fmt.Printf("[%d] 通关!\n", i+1)
Expand All @@ -49,38 +44,3 @@ func NewRootCommand() *cobra.Command {
cmd.Flags().IntVar(&opt.Times, "times", opt.Times, "设置次数")
return cmd
}

var client = resty.New().
SetBaseURL("https://cat-match.easygame2021.com").
SetHeader("Host", "cat-match.easygame2021.com").
SetHeader("Content-Type", "application/json").
SetHeader("Accept-Encoding", "gzip,compress,br,deflate").
SetHeader("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 15_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.28(0x18001c25) NetType/WIFI Language/zh_CN")

func Send(token string) error {
// 生成通关时间(s)
consumeTime := rand.Int63n(1000)

resp, err := client.R().
SetHeader("Referer", "https://servicewechat.com/wx141bfb9b73c970a9/15/page-frame.html").
SetQueryParam("rank_score", "1").
SetQueryParam("rank_state", "1").
SetQueryParam("rank_time", strconv.FormatInt(consumeTime, 10)).
SetQueryParam("rank_role", "1").
SetQueryParam("skin", "1").
SetHeader("t", token).
Get("/sheep/v1/game/game_over")

if err != nil {
return fmt.Errorf("请求失败: %v", err)
}
if resp.StatusCode() != http.StatusOK {
return fmt.Errorf("[%d] 请求错误: %s", resp.StatusCode(), resp.String())
}

jsonResult := gjson.Parse(resp.String())
if jsonResult.Get("err_code").Int() != 0 {
return fmt.Errorf("请求错误: %s", resp.String())
}
return nil
}
57 changes: 57 additions & 0 deletions pkg/core/core.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright © 2022 zc2638 <[email protected]>.

package core

import (
"fmt"
"math/rand"
"net/http"
"strconv"

"github.com/go-resty/resty/v2"
"github.com/tidwall/gjson"
)

var client = resty.New().
SetBaseURL("https://cat-match.easygame2021.com").
SetHeader("Host", "cat-match.easygame2021.com").
SetHeader("Content-Type", "application/json").
SetHeader("Accept-Encoding", "gzip,compress,br,deflate").
SetHeader("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 15_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.28(0x18001c25) NetType/WIFI Language/zh_CN")

func send(url, rankRole, token string) error {
// 生成通关时间(s)
consumeTime := rand.Int63n(1000)
resp, err := client.R().
SetHeader("Referer", "https://servicewechat.com/wx141bfb9b73c970a9/15/page-frame.html").
SetQueryParam("rank_score", "1").
SetQueryParam("rank_state", "1").
SetQueryParam("rank_time", strconv.FormatInt(consumeTime, 10)).
SetQueryParam("rank_role", rankRole).
SetQueryParam("skin", "1").
SetHeader("t", token).
Get(url)

if err != nil {
return fmt.Errorf("请求失败: %v", err)
}
if resp.StatusCode() != http.StatusOK {
return fmt.Errorf("[%d] 请求错误: %s", resp.StatusCode(), resp.String())
}

jsonResult := gjson.Parse(resp.String())
if jsonResult.Get("err_code").Int() != 0 {
return fmt.Errorf("请求错误: %s", resp.String())
}
return nil
}

func Send(token string) error {
if err := send("/sheep/v1/game/game_over", "1", token); err != nil {
return fmt.Errorf("完成闯关失败: %v", err)
}
if err := send("/sheep/v1/game/topic_game_over", "2", token); err != nil {
return fmt.Errorf("完成话题失败: %v", err)
}
return nil
}

0 comments on commit dff5e96

Please sign in to comment.