-
Notifications
You must be signed in to change notification settings - Fork 51
/
Catchplay.go
39 lines (36 loc) · 964 Bytes
/
Catchplay.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package mediaunlocktest
import (
"context"
"encoding/json"
"io"
"net/http"
"time"
)
func Catchplay(c http.Client) Result {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
req, err := http.NewRequestWithContext(ctx, "GET", "https://sunapi.catchplay.com/geo", nil)
if err != nil {
return Result{Status: StatusNetworkErr, Err: err}
}
req.Header.Set("authorization", "Basic NTQ3MzM0NDgtYTU3Yi00MjU2LWE4MTEtMzdlYzNkNjJmM2E0Ok90QzR3elJRR2hLQ01sSDc2VEoy")
resp, err := cdo(c, req)
if err != nil {
return Result{Status: StatusNetworkErr, Err: err}
}
defer resp.Body.Close()
b, err := io.ReadAll(resp.Body)
if err != nil {
return Result{Status: StatusNetworkErr, Err: err}
}
var res struct {
Code string
}
if err := json.Unmarshal(b, &res); err != nil {
return Result{Status: StatusErr, Err: err}
}
if res.Code == "100016" {
return Result{Status: StatusNo}
}
return Result{Status: StatusOK}
}