Skip to content
This repository has been archived by the owner on Aug 2, 2018. It is now read-only.

Commit

Permalink
add mode flag
Browse files Browse the repository at this point in the history
  • Loading branch information
sundy-li committed Jan 23, 2018
1 parent 7b42e51 commit a74c2c7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
1. 方法一: 在[release](https://github.com/sundy-li/wechat_brain/releases)页面下载对应的操作系统执行文件, 解压后, 将最新版本的[questions.data](https://github.com/sundy-li/wechat_brain/blob/master/questions.data) 文件下载到同一个目录, 然后运行brain文件即可,命令行输入`./brain`
2. 方法二: 安装go(>=1.8)环境后, clone本repo源码到对应`$GOPATH/src/github.com/sundy-li/`下, 进入源码目录后,执行 `go run cmd/main.go`。

- 新版本(version >= v0.18)加入了两种模式, 大家根据自己的需求选择模式运行
1. 模式一: 默认模式, 修改了服务端返回的数据, 更加友好地提示正确答案, 运行方式如上所述: `./brain` 或者源码下执行 `go run cmd/main.go`
2. 模式二: 隐身模式, 严格返回原始数据, 该模式可以防止作弊检测(客户端提交返回题目和服务端对比,模式一很容易被侦测出使用了作弊, 模式二避免了这类检测), 但该模式的缺点是降低了用户的体验,题目答案的提示只能在PC电脑上显示, 运行方式如上所述 `./brain -m 1` 或者源码下执行 `go run cmd/main.go -m 1`

#### 以下为手机安装步骤

- 设置手机代理。手机连接wifi后进行代理设置,代理IP为个人pc的内网ip地址,以及端口为8998,移动网络下可通过设置新建APN并在其中设置代理的方式实现。如:
Expand Down
12 changes: 11 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
package main

import (
"flag"
"os"
"os/signal"

brain "github.com/sundy-li/wechat_brain"
)

var (
mode int
)

func init() {
flag.IntVar(&mode, "m", 0, "run mode 0 : default mode, easy to be detected of cheating; 1 : invisible mode")
flag.Parse()
}

func main() {
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, os.Kill)
go func() {
brain.Run("8998")
brain.Run("8998", mode)
}()
<-c
brain.Close()
Expand Down
16 changes: 14 additions & 2 deletions handler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package wechat_brain

import (
"bytes"
"encoding/json"
"log"
"net/url"
Expand Down Expand Up @@ -55,8 +56,19 @@ func handleQuestionResp(bs []byte) (bsNew []byte) {
}
}
bsNew, _ = json.Marshal(respQuestion)
log.Printf("Response findQuiz%v\n", string(bsNew))
return bsNew

var out bytes.Buffer
json.Indent(&out, bsNew, "", " ")
log.Printf("Question answer predict => %v\n", out.String())

//直接将答案返回在客户端,可能导致封号,所以只在服务端显示
if Mode == 0 {
//返回修改后的答案
return out.Bytes()
} else {
//返回答案
return bs
}
}

//hijack 提交请求
Expand Down
4 changes: 3 additions & 1 deletion spider.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import (

var (
_spider = newSpider()
Mode int
)

type spider struct {
proxy *goproxy.ProxyHttpServer
}

func Run(port string) {
func Run(port string, mode int) {
Mode = mode
_spider.Init()
_spider.Run(port)
}
Expand Down

0 comments on commit a74c2c7

Please sign in to comment.