Skip to content

Commit

Permalink
添加自定义通关次数
Browse files Browse the repository at this point in the history
  • Loading branch information
zc2638 committed Sep 15, 2022
1 parent 146795c commit fc854be
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 34 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,20 @@ go install github.com/zc2638/ylgy/cmd/ylgy@latest

### 1、命令行

执行以下命令前,将 `<your-custom-token>` 替换为实际内容
- 执行以下命令前,将 `<your-custom-token>` 替换为实际内容
- `--times` 对应设置通关次数,默认为 `1`

```shell
ylgy --token <your-custom-token>
ylgy --token <your-custom-token> --times 1
```

### 2、Docker

执行以下命令前,将 `<your-custom-token>` 替换为实际内容
- 执行以下命令前,将 `<your-custom-token>` 替换为实际内容
- `--times` 对应设置通关次数,默认为 `1`

```shell
docker run --rm -it zc2638/ylgy sh -c 'ylgy --token <your-custom-token>'
docker run --rm -it zc2638/ylgy sh -c 'ylgy --token <your-custom-token> --times 1'
```

## 声明
Expand Down
75 changes: 45 additions & 30 deletions pkg/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

type Option struct {
Token string
Times int
}

func NewRootCommand() *cobra.Command {
Expand All @@ -30,42 +31,56 @@ func NewRootCommand() *cobra.Command {
return errors.New("token 必填")
}

// 生成通关时间(s)
consumeTime := rand.Int63n(1000)

client := resty.New()
client.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")

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", opt.Token).
Get("/sheep/v1/game/game_over")

if err != nil {
return fmt.Errorf("请求失败: %v", err)
times := 1
if opt.Times > 0 {
times = opt.Times
}
if resp.StatusCode() != http.StatusOK {
return fmt.Errorf("[%d] 请求错误: %s", resp.StatusCode(), resp.String())
for i := 0; i < times; i++ {
if err := Send(opt.Token); err != nil {
return err
}
fmt.Printf("[%d] 通关!\n", i+1)
}

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

cmd.Flags().StringVar(&opt.Token, "token", opt.Token, "设置token")
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
}

0 comments on commit fc854be

Please sign in to comment.