2022-08-05 09:25:12 +00:00
|
|
|
|
package utils
|
|
|
|
|
|
|
|
|
|
import (
|
2022-08-18 07:39:03 +00:00
|
|
|
|
"net/http"
|
2022-08-05 09:25:12 +00:00
|
|
|
|
"os"
|
|
|
|
|
"os/exec"
|
2022-08-05 10:08:05 +00:00
|
|
|
|
|
2022-08-18 07:39:03 +00:00
|
|
|
|
"github.com/imroc/req/v3"
|
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
|
|
2022-08-05 10:08:05 +00:00
|
|
|
|
"github.com/johlanse/study_xxqg/conf"
|
|
|
|
|
"github.com/johlanse/study_xxqg/utils/update"
|
2022-08-05 09:25:12 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Restart
|
|
|
|
|
/* @Description:
|
|
|
|
|
*/
|
|
|
|
|
func Restart() {
|
|
|
|
|
cmd := exec.Command("./study_xxqg")
|
2022-08-10 10:17:49 +00:00
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
|
cmd.Stdin = os.Stdin
|
2022-08-05 09:25:12 +00:00
|
|
|
|
go func() {
|
|
|
|
|
cmd.Start()
|
|
|
|
|
os.Exit(3)
|
|
|
|
|
}()
|
|
|
|
|
}
|
2022-08-05 10:08:05 +00:00
|
|
|
|
|
|
|
|
|
func GetAbout() string {
|
|
|
|
|
msg := "study_xxqg\n程序版本:"
|
|
|
|
|
msg += conf.GetVersion()
|
|
|
|
|
msg += "\n" + update.CheckUpdate(conf.GetVersion())
|
|
|
|
|
return msg
|
|
|
|
|
}
|
2022-08-18 07:39:03 +00:00
|
|
|
|
|
|
|
|
|
// CheckUserCookie
|
|
|
|
|
/**
|
|
|
|
|
* @Description: 获取用户成绩
|
|
|
|
|
* @param user
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
func CheckUserCookie(cookies []*http.Cookie) bool {
|
|
|
|
|
client := req.C().DevMode()
|
|
|
|
|
response, err := client.R().SetCookies(cookies...).Get("https://pc-api.xuexi.cn/open/api/score/get")
|
|
|
|
|
if err != nil {
|
|
|
|
|
logrus.Errorln("获取用户总分错误" + err.Error())
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if !gjson.GetBytes(response.Bytes(), "ok").Bool() {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|