huashijie_go/pkg/huashijie_api.go

107 lines
2.2 KiB
Go
Raw Normal View History

2024-06-08 02:02:09 -07:00
package huashijie_api
import (
"fmt"
"io"
"math/rand"
"net/http"
2024-07-04 06:34:38 -07:00
"os"
2024-06-27 15:12:43 -07:00
"strings"
2024-06-08 02:02:09 -07:00
)
var XIAOMI_MODELS = []string{
"2107119DC",
"23116PN5BC",
"23124RN87C",
"24031PN0DC",
"24072PX77C",
"24074RPD2C",
"M1804E4A",
2024-06-08 02:02:09 -07:00
"M1810E5GG",
"M2001J1C",
"M2002J9E",
"MDE5",
2024-06-08 02:02:09 -07:00
}
2024-06-27 15:12:43 -07:00
func EnsureConnection(client http.Client) {
// https://app.huashijie.art/api/update/checkUpdate
req, err := http.NewRequest("GET", "https://app.huashijie.art/api/update/checkUpdate", nil)
if err != nil {
panic(err)
}
req.Header.Add("Referer", "https://app.huashijie.art/")
req.Header.Add("User-Agent", "Dalvik/2.1.0 (Linux; U; Android 9; MI 8 SE MIUI/V12.0.2.0.PEBCNXM)")
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
text := string(body)
fmt.Println(text)
if !strings.Contains(text, "update_ver_code") {
panic("NotImplementedError: " + text)
}
}
2024-06-08 02:02:09 -07:00
func GetWorkDetailResponse(client http.Client, work_id string) ([]byte, int) {
2024-07-04 06:34:38 -07:00
endpoint := "https://app.huashijie.art/"
if os.Getenv("HSJ_ENDPOINT") == "pandapaint" {
endpoint = "https://api.pandapaint.net/"
}
req, err := http.NewRequest("GET", endpoint+"api/work/detailV2", nil)
2024-06-08 02:02:09 -07:00
if err != nil {
panic(err)
}
q := req.URL.Query()
q.Add("visitorId", "-1")
q.Add("workId", work_id)
q.Add("cur_user_id", "-1")
q.Add("platform", "android")
os_version := rand.Intn(34-28) + 28
2024-06-08 02:02:09 -07:00
q.Add("os_version", fmt.Sprintf("%d", os_version))
2024-07-04 06:34:38 -07:00
if os.Getenv("HSJ_ENDPOINT") == "pandapaint" {
q.Add("version_code", "168")
} else {
q.Add("version_code", "241")
}
q.Add("device_brand", "xiaomi")
2024-06-08 02:02:09 -07:00
device_model := XIAOMI_MODELS[rand.Intn(len(XIAOMI_MODELS))]
q.Add("device_model", device_model)
q.Add("token", "")
2024-07-04 06:34:38 -07:00
if os.Getenv("HSJ_ENDPOINT") == "pandapaint" {
q.Add("channel", "Panda.main")
} else {
q.Add("channel", "main")
}
2024-06-08 02:02:09 -07:00
headers := map[string][]string{
2024-07-04 06:34:38 -07:00
"Referer": {endpoint},
2024-06-08 02:02:09 -07:00
"User-Agent": {"okhttp/3.12.0"},
}
for k, v := range headers {
req.Header[k] = v
}
req.URL.RawQuery = q.Encode()
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
return body, resp.StatusCode
}