修复微信公众号通过普通用户的问题
This commit is contained in:
johlanse 2022-11-12 19:56:05 +08:00
parent eb53688bf6
commit b4803e41f5
8 changed files with 145 additions and 24 deletions

View File

@ -27,6 +27,7 @@ func RunCli() {
app.AddCommand(getUser()) app.AddCommand(getUser())
app.AddCommand(addUser()) app.AddCommand(addUser())
app.AddCommand(study()) app.AddCommand(study())
app.AddCommand(score())
grumble.Main(app) grumble.Main(app)
} }
@ -70,6 +71,30 @@ func study() *grumble.Command {
} }
} }
func score() *grumble.Command {
return &grumble.Command{
Name: "get score",
Aliases: []string{"score"},
Help: "get score",
LongHelp: "查询用户积分",
Run: func(c *grumble.Context) error {
users, err := model.Query()
if err != nil {
return err
}
for _, user := range users {
score, err := lib.GetUserScore(user.ToCookies())
if err != nil {
return err
}
_, _ = c.App.Println(user.Nick + "\n" + lib.FormatScore(score) + "\n\n")
}
return err
},
}
}
func addUser() *grumble.Command { func addUser() *grumble.Command {
return &grumble.Command{ return &grumble.Command{
Name: "add user", Name: "add user",

8
go.mod
View File

@ -9,6 +9,7 @@ require (
github.com/desertbit/grumble v1.1.3 github.com/desertbit/grumble v1.1.3
github.com/dustin/go-humanize v1.0.0 github.com/dustin/go-humanize v1.0.0
github.com/fsnotify/fsnotify v1.5.4 github.com/fsnotify/fsnotify v1.5.4
github.com/getlantern/systray v1.2.1
github.com/gin-contrib/gzip v0.0.6 github.com/gin-contrib/gzip v0.0.6
github.com/gin-gonic/gin v1.8.1 github.com/gin-gonic/gin v1.8.1
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.4.0-beta.0 github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.4.0-beta.0
@ -38,6 +39,12 @@ require (
github.com/desertbit/go-shlex v0.1.1 // indirect github.com/desertbit/go-shlex v0.1.1 // indirect
github.com/desertbit/readline v1.5.1 // indirect github.com/desertbit/readline v1.5.1 // indirect
github.com/fatih/color v1.13.0 // indirect github.com/fatih/color v1.13.0 // indirect
github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 // indirect
github.com/getlantern/errors v0.0.0-20190325191628-abdb3e3e36f7 // indirect
github.com/getlantern/golog v0.0.0-20190830074920-4ef2e798c2d7 // indirect
github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7 // indirect
github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55 // indirect
github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f // indirect
github.com/gin-contrib/sse v0.1.0 // indirect github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.0 // indirect github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect
@ -58,6 +65,7 @@ require (
github.com/mattn/go-isatty v0.0.16 // indirect github.com/mattn/go-isatty v0.0.16 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
github.com/pelletier/go-toml v1.9.5 // indirect github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/pkg/errors v0.9.1 // indirect github.com/pkg/errors v0.9.1 // indirect

16
go.sum
View File

@ -136,6 +136,20 @@ github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 h1:NRUJuo3v3WGC/g5YiyF790gut6oQr5f3FBI88Wv0dx4=
github.com/getlantern/context v0.0.0-20190109183933-c447772a6520/go.mod h1:L+mq6/vvYHKjCX2oez0CgEAJmbq1fbb/oNJIWQkBybY=
github.com/getlantern/errors v0.0.0-20190325191628-abdb3e3e36f7 h1:6uJ+sZ/e03gkbqZ0kUG6mfKoqDb4XMAzMIwlajq19So=
github.com/getlantern/errors v0.0.0-20190325191628-abdb3e3e36f7/go.mod h1:l+xpFBrCtDLpK9qNjxs+cHU6+BAdlBaxHqikB6Lku3A=
github.com/getlantern/golog v0.0.0-20190830074920-4ef2e798c2d7 h1:guBYzEaLz0Vfc/jv0czrr2z7qyzTOGC9hiQ0VC+hKjk=
github.com/getlantern/golog v0.0.0-20190830074920-4ef2e798c2d7/go.mod h1:zx/1xUUeYPy3Pcmet8OSXLbF47l+3y6hIPpyLWoR9oc=
github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7 h1:micT5vkcr9tOVk1FiH8SWKID8ultN44Z+yzd2y/Vyb0=
github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7/go.mod h1:dD3CgOrwlzca8ed61CsZouQS5h5jIzkK9ZWrTcf0s+o=
github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55 h1:XYzSdCbkzOC0FDNrgJqGRo8PCMFOBFL9py72DRs7bmc=
github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55/go.mod h1:6mmzY2kW1TOOrVy+r41Za2MxXM+hhqTtY3oBKd2AgFA=
github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f h1:wrYrQttPS8FHIRSlsrcuKazukx/xqO/PpLZzZXsF+EA=
github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f/go.mod h1:D5ao98qkA6pxftxoqzibIBBrLSUli+kYnJqrgBf9cIA=
github.com/getlantern/systray v1.2.1 h1:udsC2k98v2hN359VTFShuQW6GGprRprw6kD6539JikI=
github.com/getlantern/systray v1.2.1/go.mod h1:AecygODWIsBquJCJFop8MEQcJbWFfw/1yWbVabNgpCM=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4= github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4=
github.com/gin-contrib/gzip v0.0.6/go.mod h1:QOJlmV2xmayAjkNS2Y8NQsMneuRShOU/kjovCXNuzzk= github.com/gin-contrib/gzip v0.0.6/go.mod h1:QOJlmV2xmayAjkNS2Y8NQsMneuRShOU/kjovCXNuzzk=
@ -465,6 +479,8 @@ github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5/go.mod h1:/wsWhb9smxS
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM=
github.com/panjf2000/ants/v2 v2.5.0 h1:1rWGWSnxCsQBga+nQbA4/iY6VMeNoOIAM0ZWh9u3q2Q= github.com/panjf2000/ants/v2 v2.5.0 h1:1rWGWSnxCsQBga+nQbA4/iY6VMeNoOIAM0ZWh9u3q2Q=
github.com/panjf2000/ants/v2 v2.5.0/go.mod h1:cU93usDlihJZ5CfRGNDYsiBYvoilLvBF5Qp/BT2GNRE= github.com/panjf2000/ants/v2 v2.5.0/go.mod h1:cU93usDlihJZ5CfRGNDYsiBYvoilLvBF5Qp/BT2GNRE=

10
main.go
View File

@ -3,6 +3,7 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"github.com/johlanse/study_xxqg/utils/stop"
"io" "io"
"math/rand" "math/rand"
"net/http" "net/http"
@ -24,7 +25,6 @@ import (
nested "github.com/Lyrics-you/sail-logrus-formatter/sailor" nested "github.com/Lyrics-you/sail-logrus-formatter/sailor"
"github.com/huoxue1/xdaemon" "github.com/huoxue1/xdaemon"
"github.com/johlanse/study_xxqg/cli"
"github.com/johlanse/study_xxqg/conf" "github.com/johlanse/study_xxqg/conf"
"github.com/johlanse/study_xxqg/lib/state" "github.com/johlanse/study_xxqg/lib/state"
"github.com/johlanse/study_xxqg/utils" "github.com/johlanse/study_xxqg/utils"
@ -46,7 +46,9 @@ var (
var VERSION = "unknown" var VERSION = "unknown"
func init() { func init() {
if runtime.GOOS != "windows" {
runBack() runBack()
}
fmt.Printf("\033[1;31;40m%s\033[0m\n\n", "******************************************************************") fmt.Printf("\033[1;31;40m%s\033[0m\n\n", "******************************************************************")
fmt.Printf("\033[1;31;40m%s\033[0m\n\n", "软件仅可用户学习和个人使用,禁止用于任何商业活动!!!!") fmt.Printf("\033[1;31;40m%s\033[0m\n\n", "软件仅可用户学习和个人使用,禁止用于任何商业活动!!!!")
@ -221,11 +223,7 @@ func main() {
if now { if now {
do() do()
} }
if runtime.GOOS == "windows" { stop.Stop()
cli.RunCli()
} else {
select {}
}
} }

View File

@ -26,7 +26,7 @@ func UpdateWechatUser(user *WechatUser) error {
return err return err
} }
} else { } else {
_, err := engine.Table(new(WechatUser)).Update(user) _, err := engine.Where("open_id=?", user.OpenId).Update(user)
if err != nil { if err != nil {
return err return err
} }

View File

@ -1,7 +1,6 @@
package push package push
import ( import (
"database/sql"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
@ -275,8 +274,8 @@ func handleTextPass(id, msg string) {
*/ */
func handleEventUseRequest(id, msg string) { func handleEventUseRequest(id, msg string) {
user, err := model.FindWechatUser(id) user, err := model.FindWechatUser(id)
if err != nil { if user.OpenId == "" {
if err == sql.ErrNoRows {
err := model.AddWechatUser(&model.WechatUser{ err := model.AddWechatUser(&model.WechatUser{
OpenId: id, OpenId: id,
Remark: "", Remark: "",
@ -288,10 +287,6 @@ func handleEventUseRequest(id, msg string) {
return return
} }
sendMsg(conf.GetConfig().Wechat.SuperOpenID, fmt.Sprintf("用户%v申请使用测试号通过则回复信息\n通过 %v\n\n拒绝则回复:\n拒绝 %v", id, id, id)) sendMsg(conf.GetConfig().Wechat.SuperOpenID, fmt.Sprintf("用户%v申请使用测试号通过则回复信息\n通过 %v\n\n拒绝则回复:\n拒绝 %v", id, id, id))
} else {
log.Errorln("查询用户出现未知错误" + err.Error())
return
}
} else { } else {
if err != nil { if err != nil {
@ -627,6 +622,11 @@ func handleGetUser(id string, msg string) {
} }
} }
if message == "" {
log.Warningln("还未存在绑定的用户登录")
sendMsg(id, "你还没有已登陆的用户,请点击下方登录按钮登录!")
return
}
sendMsg(id, message) sendMsg(id, message)
} }

8
utils/stop/stop_other.go Normal file
View File

@ -0,0 +1,8 @@
//go:build !windows
// +build !windows
package stop
func Stop() {
select {}
}

View File

@ -0,0 +1,66 @@
//go:build windows
package stop
import (
"fmt"
"github.com/getlantern/systray"
"github.com/johlanse/study_xxqg/cli"
"os"
"syscall"
)
func Stop() {
cli.RunCli()
// systray.Run(onReady, onExit)
}
func onReady() {
icon, _ := os.ReadFile("study.ico")
systray.SetIcon(icon)
systray.SetTitle("study xxqg")
systray.SetTooltip("study_xxqg")
mShow := systray.AddMenuItem("显示", "显示窗口")
mHide := systray.AddMenuItem("隐藏", "隐藏窗口")
systray.AddSeparator()
mQuit := systray.AddMenuItem("退出", "退出程序")
kernel32 := syscall.NewLazyDLL("kernel32.dll")
user32 := syscall.NewLazyDLL("user32.dll")
// https://docs.microsoft.com/en-us/windows/console/getconsolewindow
getConsoleWindows := kernel32.NewProc("GetConsoleWindow")
// https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindowasync
showWindowAsync := user32.NewProc("ShowWindowAsync")
consoleHandle, r2, err := getConsoleWindows.Call()
if consoleHandle == 0 {
fmt.Println("Error call GetConsoleWindow: ", consoleHandle, r2, err)
}
go func() {
for {
select {
case <-mShow.ClickedCh:
mShow.Disable()
mHide.Enable()
r1, r2, err := showWindowAsync.Call(consoleHandle, 5)
if r1 != 1 {
fmt.Println("Error call ShowWindow @SW_SHOW: ", r1, r2, err)
}
case <-mHide.ClickedCh:
mHide.Disable()
mShow.Enable()
r1, r2, err := showWindowAsync.Call(consoleHandle, 0)
if r1 != 1 {
fmt.Println("Error call ShowWindow @SW_HIDE: ", r1, r2, err)
}
case <-mQuit.ClickedCh:
systray.Quit()
}
}
}()
}
func onExit() {
// clean up here
}