up
This commit is contained in:
10
go.mod
Normal file
10
go.mod
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
module aliyundrive-Checkin
|
||||||
|
|
||||||
|
go 1.19
|
||||||
|
|
||||||
|
require github.com/tidwall/gjson v1.14.4
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/tidwall/match v1.1.1 // indirect
|
||||||
|
github.com/tidwall/pretty v1.2.0 // indirect
|
||||||
|
)
|
||||||
185
main.go
185
main.go
@@ -4,74 +4,159 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
func signIn(config interface{}, accessToken string, phone string) bool {
|
var (
|
||||||
url := "https://member.aliyundrive.com/v1/activity/sign_in_list"
|
refresh_Token = "d8bdfb926fec4a32b1e81964cb5b7fba"
|
||||||
|
accessToken string
|
||||||
|
updateAccesssTokenURL = "https://auth.aliyundrive.com/v2/account/token"
|
||||||
|
signinURL = "https://member.aliyundrive.com/v1/activity/sign_in_list"
|
||||||
|
)
|
||||||
|
|
||||||
reqBody, err := json.Marshal(map[string]interface{}{})
|
type aliyundrive struct {
|
||||||
|
refreshToken string
|
||||||
|
accessToken string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *aliyundrive) getAccessToken() {
|
||||||
|
body := map[string]string{
|
||||||
|
"grant_type": "refresh_token",
|
||||||
|
"refresh_token": refresh_Token,
|
||||||
|
}
|
||||||
|
b := bytes.NewBuffer(nil)
|
||||||
|
json.NewEncoder(b).Encode(body)
|
||||||
|
rsp, err := http.Post(updateAccesssTokenURL, "application/json", b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[%s] 签到失败, 错误信息: %v\n", phone, err)
|
log.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
bytersp, _ := io.ReadAll(rsp.Body)
|
||||||
|
a.accessToken = gjson.GetBytes(bytersp, "access_token").String()
|
||||||
|
a.refreshToken = gjson.GetBytes(bytersp, "refresh_token").String()
|
||||||
|
log.Printf("%#v\n", string(bytersp))
|
||||||
|
}
|
||||||
|
|
||||||
|
type refreshToken struct {
|
||||||
|
GrantType string `json:"grant_Type,omitempty"`
|
||||||
|
RefreshToken string `json:"refresh_Token,omitempty"`
|
||||||
|
Phone string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Signrsp struct {
|
||||||
|
Success bool `json:"success"`
|
||||||
|
Code interface{} `json:"code"`
|
||||||
|
Message interface{} `json:"message"`
|
||||||
|
TotalCount interface{} `json:"totalCount"`
|
||||||
|
NextToken interface{} `json:"nextToken"`
|
||||||
|
MaxResults interface{} `json:"maxResults"`
|
||||||
|
Result Result `json:"result"`
|
||||||
|
Arguments interface{} `json:"arguments"`
|
||||||
|
}
|
||||||
|
type Result struct {
|
||||||
|
Subject string `json:"subject"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
IsReward bool `json:"isReward"`
|
||||||
|
Blessing string `json:"blessing"`
|
||||||
|
SignInCount int `json:"signInCount"`
|
||||||
|
SignInCover string `json:"signInCover"`
|
||||||
|
SignInRemindCover string `json:"signInRemindCover"`
|
||||||
|
RewardCover string `json:"rewardCover"`
|
||||||
|
SignInLogs []SignInLogs `json:"signInLogs"`
|
||||||
|
}
|
||||||
|
type SignInLogs struct {
|
||||||
|
Day int `json:"day"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Icon string `json:"icon"`
|
||||||
|
Notice interface{} `json:"notice"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Themes string `json:"themes"`
|
||||||
|
CalendarChinese string `json:"calendarChinese"`
|
||||||
|
CalendarDay string `json:"calendarDay"`
|
||||||
|
CalendarMonth string `json:"calendarMonth"`
|
||||||
|
Poster Poster `json:"poster"`
|
||||||
|
Reward Reward `json:"reward"`
|
||||||
|
IsReward bool `json:"isReward"`
|
||||||
|
}
|
||||||
|
type Poster struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Reason string `json:"reason"`
|
||||||
|
Background string `json:"background"`
|
||||||
|
Color string `json:"color"`
|
||||||
|
Action string `json:"action"`
|
||||||
|
}
|
||||||
|
type Reward struct {
|
||||||
|
GoodsID int `json:"goodsId"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Background string `json:"background"`
|
||||||
|
Color string `json:"color"`
|
||||||
|
Action string `json:"action"`
|
||||||
|
Notice string `json:"notice"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a aliyundrive) signIn() bool {
|
||||||
|
req, err := http.NewRequest("POST", signinURL, strings.NewReader("{}"))
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("签到失败, 错误信息: %v\n", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", url, bytes.NewBuffer(reqBody))
|
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", a.accessToken))
|
||||||
if err != nil {
|
|
||||||
log.Printf("[%s] 签到失败, 错误信息: %v\n", phone, err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", accessToken))
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
client := &http.Client{}
|
client := http.DefaultClient
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[%s] 签到失败, 错误信息: %v\n", phone, err)
|
log.Printf("签到失败, 错误信息: %v\n", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[%s] 签到失败, 错误信息: %v\n", phone, err)
|
log.Printf("签到失败, 错误信息: %v\n", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
var data map[string]interface{}
|
log.Printf("%#v\n", string(body))
|
||||||
err = json.Unmarshal(body, &data)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("[%s] 签到失败, 错误信息: %v\n", phone, err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, ok := data["success"]; !ok {
|
|
||||||
log.Printf("[%s] 签到失败, 错误信息: %v\n", phone, data)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
var currentDay map[string]interface{}
|
|
||||||
for i, day := range data["result"].(map[string]interface{})["signInLogs"].([]interface{}) {
|
|
||||||
if day.(map[string]interface{})["status"].(string) == "miss" {
|
|
||||||
currentDay = data["result"].(map[string]interface{})["signInLogs"].([]interface{})[i-1].(map[string]interface{})
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
reward := "无奖励"
|
|
||||||
if currentDay != nil && currentDay["isReward"].(bool) {
|
|
||||||
reward = fmt.Sprintf("获得 %s %s", currentDay["reward"].(map[string]interface{})["name"].(string), currentDay["reward"].(map[string]interface{})["description"].(string))
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Printf("[%s] 签到成功, 本月累计签到 %d 天.\n", phone, int(data["result"].(map[string]interface{})["signInCount"].(float64)))
|
|
||||||
log.Printf("[%s] 本次签到 %s\n", phone, reward)
|
|
||||||
|
|
||||||
push(config, phone, reward, int(data["result"].(map[string]interface{})["signInCount"].(float64)))
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
if gjson.GetBytes(body, "success").Bool() == true {
|
||||||
|
count := gjson.GetBytes(body, "result.signInCount").Int()
|
||||||
|
idx := count - 1
|
||||||
|
fmt.Println(gjson.GetBytes(body, "result.signInLogs."))
|
||||||
|
}
|
||||||
|
// if _, ok := data["success"]; !ok {
|
||||||
|
// log.Printf("[%s] 签到失败, 错误信息: %v\n", phone, data)
|
||||||
|
// return false
|
||||||
|
// }
|
||||||
|
|
||||||
|
// var currentDay map[string]interface{}
|
||||||
|
// for i, day := range data["result"].(map[string]interface{})["signInLogs"].([]interface{}) {
|
||||||
|
// if day.(map[string]interface{})["status"].(string) == "miss" {
|
||||||
|
// currentDay = data["result"].(map[string]interface{})["signInLogs"].([]interface{})[i-1].(map[string]interface{})
|
||||||
|
// break
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// reward := "无奖励"
|
||||||
|
// if currentDay != nil && currentDay["isReward"].(bool) {
|
||||||
|
// reward = fmt.Sprintf("获得 %s %s", currentDay["reward"].(map[string]interface{})["name"].(string), currentDay["reward"].(map[string]interface{})["description"].(string))
|
||||||
|
// }
|
||||||
|
|
||||||
|
// log.Printf("[%s] 签到成功, 本月累计签到 %d 天.\n", phone, int(data["result"].(map[string]interface{})["signInCount"].(float64)))
|
||||||
|
// log.Printf("[%s] 本次签到 %s\n", phone, reward)
|
||||||
|
|
||||||
|
// push(config, phone, reward, int(data["result"].(map[string]interface{})["signInCount"].(float64)))
|
||||||
|
|
||||||
|
// return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func push(config interface{}, phone string, reward string, signInCount int) {
|
func push(config interface{}, phone string, reward string, signInCount int) {
|
||||||
@@ -80,9 +165,13 @@ func push(config interface{}, phone string, reward string, signInCount int) {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Example usage:
|
// Example usage:
|
||||||
accessToken := "your-access-token"
|
// accessToken := "your-access-token"
|
||||||
phone := "your-phone-number"
|
// phone := "your-phone-number"
|
||||||
config := map[string]interface{}{} // or ConfigObj object
|
// config := map[string]interface{}{} // or ConfigObj object
|
||||||
|
|
||||||
signIn(config, accessToken, phone)
|
// signIn(config, accessToken, phone)
|
||||||
|
|
||||||
|
a := aliyundrive{}
|
||||||
|
a.getAccessToken()
|
||||||
|
a.signIn()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user