Created
September 5, 2020 06:25
-
-
Save caiguanhao/93cb3e7be2b74c5ae357cf5283519f0c to your computer and use it in GitHub Desktop.
fake requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module github.com/caiguanhao/fake-req | |
go 1.14 | |
require github.com/google/uuid v1.1.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= | |
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/md5" | |
"errors" | |
"flag" | |
"fmt" | |
"io" | |
"io/ioutil" | |
"log" | |
"math/rand" | |
"net/http" | |
"net/url" | |
"strconv" | |
"strings" | |
"time" | |
"github.com/google/uuid" | |
) | |
var ( | |
count = 0 | |
) | |
func getMD5(input string) string { | |
h := md5.New() | |
io.WriteString(h, input) | |
return fmt.Sprintf("%x", h.Sum(nil)) | |
} | |
func run(isAndroid bool) error { | |
id := uuid.Must(uuid.NewRandom()) | |
imei := strings.Replace(id.String(), "-", "", -1) | |
channel := "1077" | |
random := rand.Intn(9999-1000) + 1000 | |
timestamp := time.Now().Format("20060102150405") | |
stamp := fmt.Sprintf("%s%s0%d", timestamp, strings.ToUpper(id.String()), random) | |
var model string | |
if isAndroid { | |
models := []string{ | |
"MI 9", | |
"MI 6", | |
"MI 2S", | |
"OPPO R11", | |
"OPPO R17", | |
"OPPO A9", | |
"OPPO A7X", | |
"OPPO Reno", | |
"VOG-AL10", | |
"VIVO Z3X", | |
"VIVO S1", | |
} | |
model = models[rand.Intn(len(models))] | |
} else { | |
models := []string{ | |
"iPhone SE", | |
"iPhone 6", | |
"iPhone 7", | |
"iPhone 7 Plus", | |
"iPhone 8", | |
"iPhone 8 Plus", | |
} | |
model = models[rand.Intn(len(models))] | |
} | |
count += 1 | |
fmt.Printf("[%s] count=%04d uuid=%s channel=%s model=%s", timestamp, count, id.String(), channel, model) | |
data := url.Values{} | |
data.Set("UID", imei) | |
if isAndroid { | |
data.Set("app-version", "4.0.1") | |
data.Set("appVersion", "4.0.1") | |
} else { | |
data.Set("app-version", "3.3.2") | |
data.Set("appVersion", "3.3.2") | |
} | |
data.Set("channelId", channel) | |
data.Set("flavor", "2") | |
data.Set("fsSign", getMD5(getMD5(imei)+getMD5(channel))) | |
data.Set("imei", imei) | |
if isAndroid { | |
data.Set("os", "android") | |
data.Set("osVersion", "7.1.2") | |
} else { | |
data.Set("os", "iOS") | |
data.Set("osVersion", "13.6") | |
} | |
data.Set("phoneType", model) | |
data.Set("stamp", stamp) | |
data.Set("sign", getMD5(stamp+"5BvKRTgCEPsCGUMP")) | |
data.Set("token", "") | |
client := &http.Client{} | |
req, err := http.NewRequest("POST", "https://api.foshanplus.com/foshan/api/v2/addChannelStatistics", strings.NewReader(data.Encode())) | |
if err != nil { | |
return err | |
} | |
req.Header.Set("Accept", "*/*") | |
req.Header.Set("Accept-Language", "zh-Hans-CN;q=1, en-CN;q=0.9") | |
req.Header.Set("Content-Type", "application/x-www-form-urlencoded") | |
if isAndroid { | |
req.Header.Set("User-Agent", "foshanplusNews-android/4.0.1") | |
} else { | |
req.Header.Set("User-Agent", "foshanplusNews-ios/3.3.2 (iPhone; iOS 13.6; Scale/3.00)") | |
} | |
resp, err := client.Do(req) | |
if err != nil { | |
return err | |
} | |
res, err := ioutil.ReadAll(resp.Body) | |
if err != nil { | |
return err | |
} | |
resp.Body.Close() | |
if err != nil { | |
return err | |
} | |
// fmt.Println(data.Encode()) | |
resText := string(res) | |
if resText == `{"ret":1}` { | |
return nil | |
} else { | |
return errors.New(resText) | |
} | |
} | |
func main() { | |
isAndroid := flag.Bool("android", false, "android mode") | |
flag.Parse() | |
args := flag.Args() | |
if len(args) < 2 { | |
log.Fatalln("please provide min max seconds") | |
} | |
min, _ := strconv.Atoi(args[0]) | |
max, _ := strconv.Atoi(args[1]) | |
if max < 1 { | |
max = 20 | |
} else if max > 60 { | |
max = 60 | |
} | |
if min < 1 || min > max { | |
min = 5 | |
} | |
for { | |
err := run(*isAndroid) | |
fmt.Printf(": ") | |
if err == nil { | |
fmt.Println("OK") | |
} else { | |
fmt.Println(err) | |
} | |
wait := rand.Intn(max-min) + min | |
time.Sleep(time.Duration(wait) * time.Second) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment