init
This commit is contained in:
commit
1167d46c93
3 files changed
+239
No files matched your search
@@ -0,0 +1 @@
|
||||
*.exe
|
||||
@@ -0,0 +1,235 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
|
||||
separator = "-"
|
||||
length = 28
|
||||
)
|
||||
|
||||
func generateRandomSid() string {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
var sb strings.Builder
|
||||
half := length / 2
|
||||
for i := 0; i < length; i++ {
|
||||
if i == half {
|
||||
sb.WriteString(separator)
|
||||
} else {
|
||||
sb.WriteByte(characters[rand.Intn(len(characters))])
|
||||
}
|
||||
}
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
func rangeFunc(n int) []int {
|
||||
arr := make([]int, n)
|
||||
for i := 0; i < n; i++ {
|
||||
arr[i] = i
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
func input(prompt string) (string, error) {
|
||||
fmt.Print(prompt)
|
||||
var input string
|
||||
_, err := fmt.Scanln(&input)
|
||||
return input, err
|
||||
}
|
||||
|
||||
func sleep(timeout int) {
|
||||
time.Sleep(time.Duration(timeout) * time.Millisecond)
|
||||
}
|
||||
|
||||
func praise(id int, max int) (int, error) {
|
||||
sid := generateRandomSid()
|
||||
successCount := 0
|
||||
max = min(max, 1)
|
||||
for _, _ = range rangeFunc(max) {
|
||||
url := fmt.Sprintf("https://shiqu.zhilehuo.com/api/soundRecord/praise?soundRecordId=%d¶Sid=%s", id, sid)
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
req.Header.Set("Accept", "application/json, text/plain, */*")
|
||||
req.Header.Set("Accept-Language", "zh-CN,zh;q=0.9")
|
||||
req.Header.Set("Sec-Fetch-Dest", "empty")
|
||||
req.Header.Set("Sec-Fetch-Mode", "cors")
|
||||
req.Header.Set("Sec-Fetch-Site", "same-origin")
|
||||
req.Header.Set("Cookie", fmt.Sprintf("sid=%s", sid))
|
||||
req.Header.Set("Referer", fmt.Sprintf("https://shiqu.zhilehuo.com/page/record/soundRecordDetail.html?source=share&id=%d&code=011CrS000ZlKxS1qQH300N6Ia90CrS0E&state=sq2019", id))
|
||||
req.Header.Set("Referrer-Policy", "unsafe-url")
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var result map[string]interface{}
|
||||
err = json.Unmarshal(body, &result)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
code, ok := result["code"].(float64)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("无法获取 code")
|
||||
}
|
||||
if int(code) == 0 {
|
||||
successCount++
|
||||
}
|
||||
}
|
||||
if successCount > 0 {
|
||||
fmt.Printf("帮忙点赞%d次\n", successCount)
|
||||
}
|
||||
return successCount, nil
|
||||
}
|
||||
|
||||
func getPraiseCount(id int) (int, error) {
|
||||
sid := generateRandomSid()
|
||||
url := fmt.Sprintf("https://shiqu.zhilehuo.com/api/soundRecord/getSoundRecordDetail?id=%d&from=share&startDate=&endDate=&sg=", id)
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
req.Header.Set("Accept", "application/json, text/plain, */*")
|
||||
req.Header.Set("Accept-Language", "zh-CN,zh;q=0.9")
|
||||
req.Header.Set("Sec-Fetch-Dest", "empty")
|
||||
req.Header.Set("Sec-Fetch-Mode", "cors")
|
||||
req.Header.Set("Sec-Fetch-Site", "same-origin")
|
||||
req.Header.Set("Cookie", fmt.Sprintf("sid=%s", sid))
|
||||
req.Header.Set("Referer", fmt.Sprintf("https://shiqu.zhilehuo.com/page/record/soundRecordDetail.html?source=share&id=%d", id))
|
||||
req.Header.Set("Referrer-Policy", "unsafe-url")
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
|
||||
var result map[string]interface{}
|
||||
err = json.Unmarshal(body, &result)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
|
||||
data, ok := result["data"].(map[string]interface{})
|
||||
if !ok {
|
||||
return -1, fmt.Errorf("无法获取 data")
|
||||
}
|
||||
|
||||
praiseCount, ok := data["praiseCount"].(float64)
|
||||
if !ok {
|
||||
return -1, fmt.Errorf("无法获取 praiseCount")
|
||||
}
|
||||
|
||||
return int(praiseCount), nil
|
||||
}
|
||||
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func main() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
|
||||
var id int
|
||||
var praiseCount int
|
||||
|
||||
inputUrl, err := input("点赞链接=>")
|
||||
if err != nil {
|
||||
fmt.Println("读取输入错误:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
idMatch0 := strings.Split(inputUrl, "id%3D")
|
||||
if len(idMatch0) > 1 {
|
||||
idStr := strings.Split(idMatch0[1], "%")[0]
|
||||
id, err = strconv.Atoi(idStr)
|
||||
if err != nil {
|
||||
fmt.Println("解析id错误:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
} else {
|
||||
idMatch1 := strings.Split(inputUrl, "id=")
|
||||
if len(idMatch1) > 1 {
|
||||
idStr := strings.Split(idMatch1[1], "&")[0]
|
||||
id, err = strconv.Atoi(idStr)
|
||||
if err != nil {
|
||||
fmt.Println("解析id错误:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
} else {
|
||||
fmt.Println("未识别到作品,可能是链接有误,5秒后退出")
|
||||
sleep(5000)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
fmt.Printf("id=>%d\n", id)
|
||||
|
||||
praiseCountStr, err := input("点赞次数=>")
|
||||
if err != nil {
|
||||
fmt.Println("读取输入错误:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
praiseCount, err = strconv.Atoi(praiseCountStr)
|
||||
if err != nil {
|
||||
fmt.Println("解析点赞次数错误:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
currentPraise, err := getPraiseCount(id)
|
||||
if err != nil {
|
||||
fmt.Println("获取当前点赞数错误:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("点赞前点赞数=>%d\n", currentPraise)
|
||||
|
||||
var totalSuccess int
|
||||
for praiseCount > 0 {
|
||||
c := min(praiseCount, 1)
|
||||
success, err := praise(id, c)
|
||||
if err != nil {
|
||||
fmt.Println("点赞失败:", err)
|
||||
break
|
||||
}
|
||||
totalSuccess += success
|
||||
praiseCount -= c
|
||||
// 其他代码
|
||||
}
|
||||
|
||||
finalPraise, err := getPraiseCount(id)
|
||||
if err != nil {
|
||||
fmt.Println("获取最终点赞数错误:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("点赞后点赞数=>%d\n", finalPraise)
|
||||
|
||||
sleep(5000)
|
||||
}
|
||||
Reference in new issue
Block a user