定时任务增加过期cookie推送,微信支持配置管理员

This commit is contained in:
johlanse 2022-08-18 15:39:03 +08:00
parent cdc38afc71
commit b5f25202af
15 changed files with 233 additions and 83 deletions

View File

@ -67,6 +67,7 @@ type Config struct {
LoginTempID string `json:"login_temp_id" yaml:"login_temp_id"`
NormalTempID string `json:"normal_temp_id" yaml:"normal_temp_id"`
PushLoginWarn bool `json:"push_login_warn" yaml:"push_login_warn"`
SuperOpenID string `json:"super_open_id" yaml:"super_open_id"`
} `json:"wechat" yaml:"wechat"`
// 专项答题可接受的最小值
SpecialMinScore int `json:"special_min_score" yaml:"special_min_score"`
@ -79,6 +80,9 @@ type Config struct {
AppKey string `json:"app_key" yaml:"app_key"`
} `json:"ji_guang_push" yaml:"ji_guang_push"`
SuperUser string `json:"super_user" yaml:"super_user"`
SuperPassword string `json:"super_password" yaml:"super_password"`
version string
}

View File

@ -74,6 +74,8 @@ wechat:
normal_temp_id: ""
# xxqg会每隔两小时左右检查所有用户的ck有效性若开启该选项会在检查失败时推送提醒消息
push_login_warn: false
# 微信管理员的openid,可点击关于按钮获得,配置后请重启程序
super_open_id: ""
# 登录重试配置
retry:

1
go.mod
View File

@ -30,6 +30,7 @@ require (
)
require (
github.com/Luoxin/go-pushdeer-sdk v0.0.0-20220308071956-e50d1ec38c98 // indirect
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.13.0 // indirect

6
go.sum
View File

@ -1,5 +1,7 @@
github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f h1:2dk3eOnYllh+wUOuDhOoC2vUVoJF/5z478ryJ+wzEII=
github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f/go.mod h1:4a58ifQTEe2uwwsaqbh3i2un5/CBPg+At/qHpt18Tmk=
github.com/Luoxin/go-pushdeer-sdk v0.0.0-20220308071956-e50d1ec38c98 h1:88VEoycHG8Fecaf8h/Tq5FSP5Jjl1+yodHiPAJawDe0=
github.com/Luoxin/go-pushdeer-sdk v0.0.0-20220308071956-e50d1ec38c98/go.mod h1:ZO6lLdHMY7Hj7VDqvy+k+s5AQdkxK0KV08GU9CUuqR0=
github.com/codegangsta/negroni v1.0.0/go.mod h1:v0y3T5G7Y1UlFfyxFn/QLRU4a2EuNau2iZY63YTKWo0=
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 h1:y5HC9v93H5EPKqaS1UYVg1uYah5Xf51mBfIoWehClUQ=
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964/go.mod h1:Xd9hchkHSWYkEqJwUGisez3G1QY8Ryz0sdWrLPMGjLk=
@ -22,6 +24,7 @@ github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/go-playground/validator/v10 v10.5.0 h1:X9rflw/KmpACwT8zdrm1upefpvdy6ur8d1kWyq6sg3E=
github.com/go-playground/validator/v10 v10.5.0/go.mod h1:xm76BBt941f7yWdGnI2DVPFFg1UK3YY04qifoXU3lOk=
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw=
github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.4.0-beta.0 h1:mbEDV1g6RBzKd4sFjOWuyZdxItw4CWu5Kq4KaBAJbHM=
@ -109,6 +112,7 @@ github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qq
github.com/robfig/cron/v3 v3.0.0 h1:kQ6Cb7aHOHTSzNVNEhmp8EcWKLb4CbiMW9h9VyIhO4E=
github.com/robfig/cron/v3 v3.0.0/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
@ -150,6 +154,7 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220111093109-d55c255bac03 h1:0FB83qp0AzVJm+0wcIlauAjJ+tNdh7jLuacRYCIVv7s=
golang.org/x/net v0.0.0-20220111093109-d55c255bac03/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
@ -158,6 +163,7 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

View File

@ -1,6 +1,7 @@
package lib
import (
"encoding/base64"
"errors"
"fmt"
"image"
@ -149,6 +150,10 @@ func (c *Core) GenerateCode(pushID string) (string, string, error) {
} else {
log.Infoln("二维码已生成到目录下的qrcode.png")
}
if conf.GetConfig().QrCOde {
data, _ := os.ReadFile("qrcode.png")
c.Push(pushID, "image", base64.StdEncoding.EncodeToString(data))
}
qrCodeString := qrcodeTerminal.New2(qrcodeTerminal.ConsoleColors.BrightBlack, qrcodeTerminal.ConsoleColors.BrightWhite, qrcodeTerminal.QRCodeRecoveryLevels.Low).Get(codeURL)
qrCodeString.Print()

View File

@ -352,9 +352,7 @@ func (c *Core) RespondDaily(user *model.User, model string) {
// 填空题
switch {
case strings.Contains(categoryText, "填空题"):
if len(tips) < 1 {
tips = append(tips, "不知道")
}
// 填充填空题
err := FillBlank(page, tips)
if err != nil {
@ -576,11 +574,10 @@ func getTips(data string) []string {
func FillBlank(page playwright.Page, tips []string) error {
video := false
var answer []string
for _, tip := range tips {
if tip == "请观看视频" {
if len(tips) < 1 {
log.Warningln("检测到未获取到提示信息")
video = true
}
}
if video {
answer = append(answer, "不知道")
} else {
@ -591,7 +588,7 @@ func FillBlank(page playwright.Page, tips []string) error {
log.Errorln("获取输入框错误" + err.Error())
return err
}
log.Debugln("获取到", len(inouts), "个填空")
log.Infoln("获取到", len(inouts), "个填空")
if len(inouts) == 1 && len(tips) > 1 {
temp := ""
for _, tip := range tips {
@ -600,16 +597,22 @@ func FillBlank(page playwright.Page, tips []string) error {
answer = strings.Split(temp, ",")
log.Infoln("答案已合并处理")
}
var ans string
for i := 0; i < len(inouts); i++ {
err := inouts[i].Fill(answer[i])
if video {
ans = "不知道"
} else {
ans = answer[i]
}
err := inouts[i].Fill(ans)
if err != nil {
log.Errorln("填充答案失败" + err.Error())
continue
}
r := rand2.Intn(5)
r := rand2.Intn(4) + 1
time.Sleep(time.Duration(r) * time.Second)
}
r := rand2.Intn(2)
r := rand2.Intn(1) + 1
time.Sleep(time.Duration(r) * time.Second)
checkNextBotton(page)
return nil

View File

@ -272,7 +272,7 @@ func (c *Core) LearnVideo(user *model.User) {
c.Push(user.PushId, "text", "正在观看视频:"+links[n].Title)
log.Infoln("视频发布时间:" + links[n].PublishTime)
log.Infoln("视频学习链接:" + links[n].Url)
learnTime := 60 + rand.Intn(10) + 5
learnTime := 60 + rand.Intn(10)
for i := 0; i < learnTime; i++ {
if c.IsQuit() {
return

View File

@ -168,6 +168,7 @@ func main() {
}
getPush := push.GetPush(config)
getPush("", "flush", "学习强国助手已上线")
model.SetPush(getPush)
if !config.TG.Enable && config.Cron == "" && !config.Wechat.Enable {
log.Infoln("已采用普通学习模式")
do("normal")
@ -194,6 +195,10 @@ func do(m string) {
getPush := push.GetPush(config)
getPush("", "flush", "学习强国助手已上线")
failUser, _ := model.QueryFailUser()
for _, user := range failUser {
getPush(user.PushId, "flush", user.Nick+"的cookie已过期")
}
core := &lib.Core{ShowBrowser: config.ShowBrowser, Push: getPush}
defer core.Quit()
core.Init()

View File

@ -30,6 +30,9 @@ func init() {
login_time integer not null,
push_id TEXT
);
`)
_, _ = db.Exec(`alter table user
add status integer default 1;
`)
}

View File

@ -3,19 +3,20 @@
package model
import (
"database/sql"
"fmt"
"math/rand"
"net/http"
"sync"
"time"
"github.com/guonaihong/gout"
"github.com/imroc/req/v3"
"github.com/playwright-community/playwright-go"
log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
"github.com/johlanse/study_xxqg/conf"
"github.com/johlanse/study_xxqg/utils"
)
var (
lock sync.RWMutex
)
func init() {
@ -23,11 +24,11 @@ func init() {
}
var (
wechatPush func(id, message string)
pushFunc func(id, kind, message string)
)
func SetPush(push func(id, message string)) {
wechatPush = push
func SetPush(push func(id, kind, message string)) {
pushFunc = push
}
// User
@ -40,80 +41,119 @@ type User struct {
Token string `json:"token"`
LoginTime int64 `json:"login_time"`
PushId string `json:"push_id"`
Status int `json:"status"`
}
// Query
/**
* @Description:
* @Description: 查询所有未掉线的用户
* @return []*User
* @return error
*/
func Query() ([]*User, error) {
var users []*User
ping()
lock.Lock()
defer lock.Unlock()
results, err := db.Query("select * from user")
if err != nil {
return nil, err
}
defer func(results *sql.Rows) {
err := results.Close()
if err != nil {
log.Errorln("关闭results失败" + err.Error())
}
}(results)
var failusers []*User
for results.Next() {
u := new(User)
err := results.Scan(&u.Nick, &u.UID, &u.Token, &u.LoginTime, &u.PushId)
err := results.Scan(&u.Nick, &u.UID, &u.Token, &u.LoginTime, &u.PushId, &u.Status)
if err != nil {
_ = results.Close()
return nil, err
}
if u.Status != 0 {
if utils.CheckUserCookie(u.ToCookies()) {
users = append(users, u)
} else {
log.Warningln(u.Nick + "的cookie已失效")
failusers = append(failusers, u)
if pushFunc != nil {
pushFunc(u.PushId, "flush", u.Nick+"的cookie已失效")
}
}
}
}
_ = results.Close()
for _, failuser := range failusers {
changeStatus(failuser.UID, 0)
}
return users, err
}
func changeStatus(uid string, status int) {
ping()
_, err := db.Exec("update user set status = ? where uid = ?", status, uid)
if err != nil {
log.Errorln("改变status失败" + err.Error())
return
}
}
func QueryFailUser() ([]*User, error) {
var users []*User
ping()
lock.Lock()
defer lock.Unlock()
results, err := db.Query("select * from user where status = 0")
if err != nil {
return nil, err
}
if CheckUserCookie(u) {
for results.Next() {
u := new(User)
err := results.Scan(&u.Nick, &u.UID, &u.Token, &u.LoginTime, &u.PushId, &u.Status)
if err != nil {
_ = results.Close()
return nil, err
}
users = append(users, u)
} else {
log.Infoln("用户" + u.Nick + "cookie已失效")
//_ = push.PushMessage("", "用户"+u.UID+"已失效,请登录", "login", u.PushId)
if conf.GetConfig().Wechat.PushLoginWarn {
wechatPush(u.PushId, fmt.Sprintf("用户%v已失效", u.Nick))
}
_ = DeleteUser(u.UID)
}
}
_ = results.Close()
return users, err
}
// QueryByPushID
/**
* @Description:
* @Description: 根据推送平台的key查询用户
* @return []*User
* @return error
*/
func QueryByPushID(pushID string) ([]*User, error) {
lock.Lock()
defer lock.Unlock()
var users []*User
ping()
results, err := db.Query("select * from user where push_id = ?", pushID)
if err != nil {
return users, err
}
defer func(results *sql.Rows) {
err := results.Close()
if err != nil {
log.Errorln("关闭results失败" + err.Error())
}
}(results)
var failusers []*User
for results.Next() {
u := new(User)
err := results.Scan(&u.Nick, &u.UID, &u.Token, &u.LoginTime, &u.PushId)
err := results.Scan(&u.Nick, &u.UID, &u.Token, &u.LoginTime, &u.PushId, &u.Status)
if err != nil {
_ = results.Close()
return users, err
}
if CheckUserCookie(u) {
if u.Status != 0 {
if utils.CheckUserCookie(u.ToCookies()) {
users = append(users, u)
} else {
log.Infoln("用户" + u.Nick + "cookie已失效")
//_ = push.PushMessage("", "用户"+u.UID+"已失效,请登录", "login", u.PushId)
_ = DeleteUser(u.UID)
log.Warningln(u.Nick + "的cookie已失效")
failusers = append(failusers, u)
}
}
}
_ = results.Close()
for _, failuser := range failusers {
changeStatus(failuser.UID, 0)
}
return users, err
}
@ -125,7 +165,7 @@ func QueryByPushID(pushID string) ([]*User, error) {
*/
func Find(uid string) *User {
u := new(User)
err := db.QueryRow("select * from user where uid=?;", uid).Scan(&u.Nick, &u.UID, &u.Token, &u.LoginTime, &u.PushId)
err := db.QueryRow("select * from user where uid=?;", uid).Scan(&u.Nick, &u.UID, &u.Token, &u.LoginTime, &u.PushId, &u.Status)
if err != nil {
return nil
}
@ -139,6 +179,8 @@ func Find(uid string) *User {
* @return error
*/
func AddUser(user *User) error {
lock.Lock()
defer lock.Unlock()
ping()
count := UserCount(user.UID)
if count < 1 {
@ -164,8 +206,10 @@ func AddUser(user *User) error {
* @return error
*/
func UpdateUser(user *User) error {
lock.Lock()
defer lock.Unlock()
ping()
_, err := db.Exec("update user set token=?,login_time=?,push_id=? where uid = ?", user.Token, user.LoginTime, user.PushId, user.UID)
_, err := db.Exec("update user set token=?,login_time=?,push_id=?,status=1 where uid = ?", user.Token, user.LoginTime, user.PushId, user.UID)
if err != nil {
log.Errorln("更新数据失败")
log.Errorln(err.Error())
@ -252,28 +296,6 @@ func (u *User) ToBrowserCookies() []playwright.BrowserContextAddCookiesOptionsCo
return []playwright.BrowserContextAddCookiesOptionsCookies{cookie}
}
// CheckUserCookie
/**
* @Description: 获取用户成绩
* @param user
* @return bool
*/
func CheckUserCookie(user *User) bool {
var resp []byte
err := gout.GET("https://pc-api.xuexi.cn/open/api/score/get").SetCookies(user.ToCookies()...).SetHeader(gout.H{
"Cache-Control": "no-cache",
}).BindBody(&resp).Do()
if err != nil {
log.Errorln("获取用户总分错误" + err.Error())
return false
}
if !gjson.GetBytes(resp, "ok").Bool() {
return false
}
return true
}
func check() {
defer func() {
err := recover()

View File

@ -45,6 +45,11 @@ func GetPush(config conf.Config) func(id string, kind string, message string) {
log.Infoln("一配置tg推送")
pushs = append(pushs, tgPush)
}
if config.JiGuangPush.Enable {
pushs = append(pushs, func(id, kind, message string) {
_ = PushMessage("", message, message, id)
})
}
pushs = append(pushs, func(id, kind, message string) {
log.Debugln(fmt.Sprintf("消息id: %v消息类型%v,消息内容:%v", id, kind, message))
})

View File

@ -51,6 +51,9 @@ func TgInit() {
}
if kind == "flush" {
telegram.SendMsg(chatId, strings.ReplaceAll(message, "</br>", "\n"))
} else if kind == "image" {
bytes, _ := base64.StdEncoding.DecodeString(message)
telegram.SendPhoto(chatId, bytes)
} else {
if log.GetLevel() == log.DebugLevel {
telegram.SendMsg(chatId, message)

View File

@ -35,6 +35,7 @@ const (
checkUpdate = "check_update"
updateBtn = "updateBtn"
restart = "restart"
getOpenID = "get_open_id"
)
type WechatHandler func(id string)
@ -58,6 +59,10 @@ func initWechat() {
return
}
if config.Wechat.SuperOpenID == "" {
log.Warningln("你还未配置super_open_id选项")
}
// 注册插件
RegisterHandler(loginBtn, handleLogin)
RegisterHandler(StartStudy, handleStartStudy)
@ -66,6 +71,7 @@ func initWechat() {
RegisterHandler(checkUpdate, handleCheckUpdate)
RegisterHandler(updateBtn, handleUpdate)
RegisterHandler(restart, handleRestart)
RegisterHandler(getOpenID, handleGetOpenID)
wx = mp.New(config.Wechat.Token, config.Wechat.AppID, config.Wechat.Secret, "123", "123")
err := wx.CreateMenu(&mp.Menu{Buttons: []mp.MenuButton{
@ -120,6 +126,11 @@ func initWechat() {
Type: "click",
Key: updateBtn,
},
{
Name: "获取open_id",
Type: "click",
Key: getOpenID,
},
},
},
}})
@ -127,9 +138,6 @@ func initWechat() {
log.Errorln("设置自定义菜单出现异常" + err.Error())
return
}
if conf.GetConfig().Wechat.PushLoginWarn {
model.SetPush(sendMsg)
}
wx.HandleFunc("eventCLICK", func(wx *mp.WeiXin, w http.ResponseWriter, r *request.WeiXinRequest, timestamp, nonce string) {
if lastNonce == nonce {
return
@ -153,22 +161,55 @@ func initWechat() {
})
}
func handleGetOpenID(id string) {
sendMsg(id, "你的open_id为"+id)
}
//
// handleCheckUpdate
// @Description: 检查更新
// @param id
//
func handleCheckUpdate(id string) {
about := utils.GetAbout()
sendMsg(id, about)
}
//
// handleUpdate
// @Description: 开始更新
// @param id
//
func handleUpdate(id string) {
if conf.GetConfig().Wechat.SuperOpenID != id {
sendMsg(id, "请联系管理员处理!")
return
}
update.SelfUpdate("", conf.GetVersion())
sendMsg(id, "检查更新已完成,即将重启程序")
utils.Restart()
}
//
// handleRestart
// @Description: 重启程序
// @param id
//
func handleRestart(id string) {
if conf.GetConfig().Wechat.SuperOpenID != id {
sendMsg(id, "请联系管理员处理!")
return
}
sendMsg(id, "即将重启程序")
utils.Restart()
}
//
// sendMsg
// @Description: 发送消息
// @param id
// @param message
//
func sendMsg(id, message string) {
m := map[string]interface{}{
"data": map[string]string{
@ -192,7 +233,7 @@ func sendMsg(id, message string) {
}
// HandleWechat
/* @Description:
/* @Description:处理wechat的请求接口
* @param rep
* @param req
*/
@ -203,6 +244,11 @@ func HandleWechat(rep http.ResponseWriter, req *http.Request) {
wx.ServeHTTP(rep, req)
}
//
// handleLogin
// @Description: 用户登录
// @param id
//
func handleLogin(id string) {
core := &lib.Core{Push: func(id1 string, kind, message string) {
if kind == "flush" && strings.HasPrefix(message, "登录链接") {
@ -227,6 +273,11 @@ func handleLogin(id string) {
sendMsg(id, "登录成功")
}
//
// handleStartStudy
// @Description: 开始学习
// @param id
//
func handleStartStudy(id string) {
users, err := model.QueryByPushID(id)
if err != nil {
@ -272,11 +323,19 @@ func handleGetUser(id string) {
return
}
message := ""
config := conf.GetConfig()
for _, user := range users {
message += fmt.Sprintf("%v ==> %v", user.Nick, time.Unix(user.LoginTime, 0).Format("2006-01-02 15:04:05"))
if config.Wechat.SuperOpenID == id {
message += fmt.Sprintf("%v ==> %v", user.Nick, time.Unix(user.LoginTime, 0).Format("2006-01-02"))
if user.PushId == id {
message += "(已绑定)\n"
message += "(已绑定)\r\n"
}
} else {
if user.PushId == id {
message += fmt.Sprintf("%v ==> %v", user.Nick, time.Unix(user.LoginTime, 0).Format("2006-01-02"))
}
}
}
sendMsg(id, message)
}
@ -291,8 +350,16 @@ func handleScore(id string) {
sendMsg(id, "你还没有已登陆的用户,请点击下方登录按钮登录!")
return
}
config := conf.GetConfig()
for _, user := range users {
score, _ := lib.GetUserScore(user.ToCookies())
if config.Wechat.SuperOpenID == id {
sendMsg(id, "用户:"+user.Nick+"\n"+lib.FormatScore(score))
} else {
if user.PushId == id {
sendMsg(id, "用户:"+user.Nick+"\n"+lib.FormatScore(score))
}
}
}
}

View File

@ -14,7 +14,7 @@ func init() {
client.SetProxy(http.ProxyFromEnvironment)
if log.GetLevel() == log.DebugLevel {
client.DebugLog = true
client = client.DevMode().EnableDumpAll().EnableDebugLog()
client = client.DevMode()
}
client.SetLogger(&myLog{})
client.SetCommonHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36")

View File

@ -1,9 +1,14 @@
package utils
import (
"net/http"
"os"
"os/exec"
"github.com/imroc/req/v3"
"github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
"github.com/johlanse/study_xxqg/conf"
"github.com/johlanse/study_xxqg/utils/update"
)
@ -28,3 +33,22 @@ func GetAbout() string {
msg += "\n" + update.CheckUpdate(conf.GetVersion())
return msg
}
// 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
}