微信添加权限管理,日志进行统一,发送消息采用客服消息发送
This commit is contained in:
parent
60d86cdb06
commit
56c3721dc9
|
@ -1,5 +1,20 @@
|
|||
## 常见问题<!-- {docsify-ignore} -->
|
||||
|
||||
|
||||
+ ### 遇到问题的常用解决办法
|
||||
|
||||
```yaml
|
||||
首先将日志项中的日志等级调整为debug
|
||||
|
||||
复现出现的错误,在issue中查找错误日志的关键字
|
||||
|
||||
通过搜索引擎查找问题
|
||||
|
||||
在群聊中查找聊天记录,查找置顶信息
|
||||
|
||||
若无解决方案,可附上关键日志和相关配置文件,在群聊中提出问题或者在github提出issue
|
||||
```
|
||||
|
||||
+ ### windows打开**study_xxqg.exe**出现直接闪退
|
||||
```yaml
|
||||
在文件路径栏输入**cmd**,然后再黑色命令窗口中输入```./study_xxqg.exe```,
|
||||
|
|
13
go.mod
13
go.mod
|
@ -6,32 +6,36 @@ replace github.com/willf/bitset v1.2.1 => github.com/bits-and-blooms/bitset v1.2
|
|||
|
||||
require (
|
||||
github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f
|
||||
github.com/DaRealFreak/colored-nested-formatter v1.0.0
|
||||
github.com/dustin/go-humanize v1.0.0
|
||||
github.com/fsnotify/fsnotify v1.5.4
|
||||
github.com/gin-gonic/gin v1.7.1
|
||||
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.4.0-beta.0
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/guonaihong/gout v0.2.9
|
||||
github.com/imroc/req/v3 v3.8.2
|
||||
github.com/johlanse/wechat v0.0.0-20220731103216-3c9e7b56434f
|
||||
github.com/johlanse/wechat v0.0.0-20220909140933-49a96a4c0412
|
||||
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
|
||||
github.com/klauspost/compress v1.15.5
|
||||
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
|
||||
github.com/makiuchi-d/gozxing v0.1.1
|
||||
github.com/mitchellh/mapstructure v1.5.0
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||
github.com/playwright-community/playwright-go v0.2000.1
|
||||
github.com/robfig/cron/v3 v3.0.0
|
||||
github.com/sirupsen/logrus v1.9.0
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||
github.com/spf13/viper v1.12.0
|
||||
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
|
||||
github.com/tidwall/gjson v1.12.1
|
||||
golang.org/x/image v0.0.0-20211028202545-6944b10bf410
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
modernc.org/sqlite v1.15.2
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/Lyrics-you/sail-logrus-formatter v1.3.1 // indirect
|
||||
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // indirect
|
||||
github.com/fsnotify/fsnotify v1.5.4 // indirect
|
||||
github.com/fatih/color v1.13.0 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/go-playground/locales v0.13.0 // indirect
|
||||
github.com/go-playground/universal-translator v0.17.0 // indirect
|
||||
|
@ -49,7 +53,7 @@ require (
|
|||
github.com/magiconair/properties v1.8.6 // indirect
|
||||
github.com/mattn/go-colorable v0.1.12 // indirect
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
||||
|
@ -76,7 +80,6 @@ require (
|
|||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
|
||||
gopkg.in/ini.v1 v1.66.4 // indirect
|
||||
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0 // indirect
|
||||
lukechampine.com/uint128 v1.1.1 // indirect
|
||||
modernc.org/cc/v3 v3.35.24 // indirect
|
||||
|
|
26
go.sum
26
go.sum
|
@ -40,6 +40,10 @@ github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f h
|
|||
github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f/go.mod h1:4a58ifQTEe2uwwsaqbh3i2un5/CBPg+At/qHpt18Tmk=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/DaRealFreak/colored-nested-formatter v1.0.0 h1:dRYicQ6uBWQmBXthjsAL3/gXz4o2NQwlogT+EouaOig=
|
||||
github.com/DaRealFreak/colored-nested-formatter v1.0.0/go.mod h1:+cI6EWRl6zwYjeCygEdcEtdOErfNS6iIhrvxMf0oJWQ=
|
||||
github.com/Lyrics-you/sail-logrus-formatter v1.3.1 h1:y/9QraPbDwfccHa4QFZ9g2zNiPoSoQnE5MYizWLiYwY=
|
||||
github.com/Lyrics-you/sail-logrus-formatter v1.3.1/go.mod h1:e9FX8+3MxwQGGkK+8ne3kRpu0gaBc9QTE7jtP+zP070=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
|
@ -61,6 +65,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
|
|||
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
|
||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
|
||||
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
|
||||
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
|
||||
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
|
||||
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
|
||||
|
@ -167,6 +173,16 @@ github.com/imroc/req/v3 v3.8.2 h1:wFZ7B0dclCQyjClP5GwXRboUGIek5l0mCpodrGgT01c=
|
|||
github.com/imroc/req/v3 v3.8.2/go.mod h1:3JIicOKEDHfCSYYNLb/ObZNpx64EV5y40VlHMwhUCzU=
|
||||
github.com/johlanse/wechat v0.0.0-20220731103216-3c9e7b56434f h1:wpe87qm/nBbQ8BT+mrYvEHnXRbn11+2iSYpjrj62QAQ=
|
||||
github.com/johlanse/wechat v0.0.0-20220731103216-3c9e7b56434f/go.mod h1:dLGDxcVd4CFRQInD2S2aMm4CGobWAFixOEgFxXZJ6Sw=
|
||||
github.com/johlanse/wechat v0.0.0-20220909121200-69a75314f7e5 h1:dLOrE5Kf1xejywO0JK1/t7Iw0Vs4D1kxPaJUIB0p8Ic=
|
||||
github.com/johlanse/wechat v0.0.0-20220909121200-69a75314f7e5/go.mod h1:dLGDxcVd4CFRQInD2S2aMm4CGobWAFixOEgFxXZJ6Sw=
|
||||
github.com/johlanse/wechat v0.0.0-20220909121712-dd14c70a7fe1 h1:nnP8qGcGwjfbDWCd429U6bpUs4lNxM6/a8wyqsvcuUw=
|
||||
github.com/johlanse/wechat v0.0.0-20220909121712-dd14c70a7fe1/go.mod h1:dLGDxcVd4CFRQInD2S2aMm4CGobWAFixOEgFxXZJ6Sw=
|
||||
github.com/johlanse/wechat v0.0.0-20220909122403-89657f9c72a2 h1:O1ikc6+wPqzRsXbubbdcYMNgjY1DKWgz6ckNGJaUAgo=
|
||||
github.com/johlanse/wechat v0.0.0-20220909122403-89657f9c72a2/go.mod h1:dLGDxcVd4CFRQInD2S2aMm4CGobWAFixOEgFxXZJ6Sw=
|
||||
github.com/johlanse/wechat v0.0.0-20220909135230-09ab236be025 h1:r/t9htBAueb197wTieytGk0yXnIML+6KvNl70xo/lXs=
|
||||
github.com/johlanse/wechat v0.0.0-20220909135230-09ab236be025/go.mod h1:dLGDxcVd4CFRQInD2S2aMm4CGobWAFixOEgFxXZJ6Sw=
|
||||
github.com/johlanse/wechat v0.0.0-20220909140933-49a96a4c0412 h1:DFz1bW80xkuMFicYwHMfi9U7RSSpOOvWyVWDZsDlRQg=
|
||||
github.com/johlanse/wechat v0.0.0-20220909140933-49a96a4c0412/go.mod h1:dLGDxcVd4CFRQInD2S2aMm4CGobWAFixOEgFxXZJ6Sw=
|
||||
github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ=
|
||||
github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
|
||||
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
|
@ -201,13 +217,19 @@ github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamh
|
|||
github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
|
||||
github.com/makiuchi-d/gozxing v0.1.1 h1:xxqijhoedi+/lZlhINteGbywIrewVdVv2wl9r5O9S1I=
|
||||
github.com/makiuchi-d/gozxing v0.1.1/go.mod h1:eRIHbOjX7QWxLIDJoQuMLhuXg9LAuw6znsUtRkNw9DU=
|
||||
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
|
||||
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/mattn/go-sqlite3 v1.14.10 h1:MLn+5bFRlWMGoSRmJour3CL1w/qL96mvipqpwQW/Sfk=
|
||||
github.com/mattn/go-sqlite3 v1.14.10/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
|
||||
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
|
@ -266,8 +288,6 @@ github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMT
|
|||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/subosito/gotenv v1.3.0 h1:mjC+YW8QpAdXibNi+vNWgzmgBH4+5l5dCXv8cNysBLI=
|
||||
github.com/subosito/gotenv v1.3.0/go.mod h1:YzJjq/33h7nrwdY+iHMhEOEEbW0ovIz0tB6t6PwAXzs=
|
||||
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 h1:J6v8awz+me+xeb/cUTotKgceAYouhIB3pjzgRd6IlGk=
|
||||
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816/go.mod h1:tzym/CEb5jnFI+Q0k4Qq3+LvRF4gO3E2pxS8fHP8jcA=
|
||||
github.com/tidwall/gjson v1.12.1 h1:ikuZsLdhr8Ws0IdROXUS1Gi4v9Z4pGqpX/CvJkxvfpo=
|
||||
github.com/tidwall/gjson v1.12.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
||||
|
@ -389,6 +409,7 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
|
|||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
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=
|
||||
|
@ -398,6 +419,7 @@ golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
|
45
main.go
45
main.go
|
@ -15,11 +15,11 @@ import (
|
|||
rotates "github.com/lestrrat-go/file-rotatelogs"
|
||||
"github.com/robfig/cron/v3"
|
||||
log "github.com/sirupsen/logrus"
|
||||
easy "github.com/t-tomalak/logrus-easy-formatter"
|
||||
|
||||
nested "github.com/Lyrics-you/sail-logrus-formatter/sailor"
|
||||
|
||||
"github.com/johlanse/study_xxqg/conf"
|
||||
"github.com/johlanse/study_xxqg/utils"
|
||||
|
||||
// "github.com/johlanse/study_xxqg/gui"
|
||||
"github.com/johlanse/study_xxqg/lib"
|
||||
"github.com/johlanse/study_xxqg/model"
|
||||
|
@ -37,6 +37,18 @@ var (
|
|||
var VERSION = "unknown"
|
||||
|
||||
func init() {
|
||||
|
||||
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", "软件仅可用户学习和个人使用,禁止用于任何商业活动!!!!")
|
||||
|
||||
fmt.Printf("\033[1;31;40m%s\033[0m\n\n", "******************************************************************")
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
flag.BoolVar(&u, "u", false, "更新应用")
|
||||
flag.BoolVar(&i, "init", false, "init the app")
|
||||
flag.StringVar(&configPath, "config", "./config/config.yml", "设置配置文件路径")
|
||||
|
@ -44,23 +56,40 @@ func init() {
|
|||
// 初始化配置文件
|
||||
conf.InitConfig(configPath, utils.Restart)
|
||||
config = conf.GetConfig()
|
||||
logFormatter := &easy.Formatter{
|
||||
TimestampFormat: "2006-01-02 15:04:05",
|
||||
LogFormat: "[%time%] [%lvl%]: %msg% \n",
|
||||
}
|
||||
w, err := rotates.New(path.Join("config", "logs", "%Y-%m-%d.log"), rotates.WithRotationTime(time.Hour*24))
|
||||
if err != nil {
|
||||
log.Errorf("rotates init err: %v", err)
|
||||
panic(err)
|
||||
}
|
||||
gin.DefaultWriter = io.MultiWriter(w, os.Stdout)
|
||||
gin.DefaultWriter = io.MultiWriter(w, &utils.LogWriter{})
|
||||
log.SetOutput(io.MultiWriter(w, os.Stdout))
|
||||
log.SetFormatter(logFormatter)
|
||||
|
||||
level, err := log.ParseLevel(config.LogLevel)
|
||||
if err != nil {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
}
|
||||
log.SetLevel(level)
|
||||
|
||||
showPosition := false
|
||||
|
||||
if level == log.DebugLevel {
|
||||
showPosition = true
|
||||
}
|
||||
log.SetFormatter(&nested.Formatter{
|
||||
FieldsOrder: nil,
|
||||
TimeStampFormat: "2006-01-02 15:04:05",
|
||||
CharStampFormat: "",
|
||||
HideKeys: false,
|
||||
Position: showPosition,
|
||||
Colors: true,
|
||||
FieldsColors: true,
|
||||
FieldsSpace: true,
|
||||
ShowFullLevel: false,
|
||||
LowerCaseLevel: true,
|
||||
TrimMessages: true,
|
||||
CallerFirst: false,
|
||||
CustomCallerFormatter: nil,
|
||||
})
|
||||
if !utils.CheckQuestionDB() {
|
||||
utils.DownloadDbFile()
|
||||
log.Errorln("题库文件不存在或已损坏,请手动前往 https://github.com/johlanse/study_xxqg/blob/main/conf/QuestionBank.db 下载并放入程序根目录")
|
||||
|
|
|
@ -33,6 +33,15 @@ func init() {
|
|||
login_time integer not null,
|
||||
push_id TEXT
|
||||
);
|
||||
`)
|
||||
|
||||
_, _ = db.Exec(`
|
||||
create table wechat_user(
|
||||
open_id TEXT not null constraint user_pk primary key,
|
||||
remark TEXT default '',
|
||||
status INTEGER default 0,
|
||||
last_request_time INTEGER not null
|
||||
)
|
||||
`)
|
||||
_, _ = db.Exec(`alter table user
|
||||
add status integer default 1;
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
package model
|
||||
|
||||
type WechatUser struct {
|
||||
OpenID string `json:"open_id"`
|
||||
Remark string `json:"remark"`
|
||||
Status int `json:"status"`
|
||||
LastRequestTime int64 `json:"last_request_time"`
|
||||
}
|
||||
|
||||
func AddWechatUser(user *WechatUser) error {
|
||||
ping()
|
||||
_, err := db.Exec(`insert into wechat_user (open_id, remark, status, last_request_time) VALUES (?,?,?,?)`, user.OpenID, user.Remark, user.Status, user.LastRequestTime)
|
||||
return err
|
||||
}
|
||||
|
||||
func WechatUserCount(openID string) int {
|
||||
ping()
|
||||
var count int
|
||||
err := db.QueryRow("select count(*) from wechat_user where open_id = ?", openID).Scan(&count)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func UpdateWechatUser(user *WechatUser) error {
|
||||
ping()
|
||||
_, err := db.Exec(`update wechat_user set remark=?,status=?,last_request_time=? where open_id=?;`, user.Remark, user.Status, user.LastRequestTime, user.OpenID)
|
||||
return err
|
||||
}
|
||||
|
||||
func FindWechatUser(openID string) (*WechatUser, error) {
|
||||
ping()
|
||||
w := new(WechatUser)
|
||||
err := db.QueryRow(`select * from wechat_user where open_id=?;`, openID).Scan(&w.OpenID, &w.Remark, &w.Status, &w.LastRequestTime)
|
||||
return w, err
|
||||
}
|
||||
|
||||
func QueryWechatByCondition(condition string) ([]*WechatUser, error) {
|
||||
var users []*WechatUser
|
||||
if condition == "" {
|
||||
condition = "1=1"
|
||||
}
|
||||
ping()
|
||||
results, err := db.Query("select * from wechat_user where ?", condition)
|
||||
if err != nil {
|
||||
return users, err
|
||||
}
|
||||
|
||||
for results.Next() {
|
||||
w := new(WechatUser)
|
||||
err := results.Scan(&w.OpenID, &w.Remark, &w.Status, &w.LastRequestTime)
|
||||
if err != nil {
|
||||
_ = results.Close()
|
||||
return users, err
|
||||
}
|
||||
users = append(users, w)
|
||||
}
|
||||
return users, err
|
||||
}
|
||||
|
||||
func DeleteWechatUser(openID string) error {
|
||||
ping()
|
||||
_, err := db.Exec(`delete from wechat_user where open_id=?;`, openID)
|
||||
return err
|
||||
}
|
|
@ -178,7 +178,7 @@ func (t *Telegram) Init() {
|
|||
}
|
||||
}
|
||||
if !inWhiteList {
|
||||
log.Infoln("已过滤非白名单的消息")
|
||||
log.Warningln("已过滤非白名单的消息,若需允许用户使用,请将user_id添加到配置文件white_list中")
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
883
push/wx.go
883
push/wx.go
|
@ -36,9 +36,11 @@ const (
|
|||
updateBtn = "updateBtn"
|
||||
restart = "restart"
|
||||
getOpenID = "get_open_id"
|
||||
|
||||
useRequest = "use_request"
|
||||
)
|
||||
|
||||
type WechatHandler func(id string)
|
||||
type WechatHandler func(id string, msg string)
|
||||
|
||||
var (
|
||||
handlers sync.Map
|
||||
|
@ -72,9 +74,579 @@ func initWechat() {
|
|||
RegisterHandler(updateBtn, handleUpdate)
|
||||
RegisterHandler(restart, handleRestart)
|
||||
RegisterHandler(getOpenID, handleGetOpenID)
|
||||
RegisterHandler(useRequest, handleEventUseRequest)
|
||||
|
||||
RegisterHandler("发送", handleTextSendMsg)
|
||||
|
||||
RegisterHandler("申请使用", handleEventUseRequest)
|
||||
RegisterHandler("通过", handleTextPass)
|
||||
RegisterHandler("拒绝", handleTextReject)
|
||||
RegisterHandler("使用用户列表", handleTextUserList)
|
||||
|
||||
// 发送”/remark test即可添加备注信息”
|
||||
RegisterHandler("/remark", handleTextRemark)
|
||||
|
||||
wx = mp.New(config.Wechat.Token, config.Wechat.AppID, config.Wechat.Secret, "123", "123")
|
||||
err := wx.CreateMenu(&mp.Menu{Buttons: []mp.MenuButton{
|
||||
err := wx.CreateMenu(mean)
|
||||
if err != nil {
|
||||
log.Errorln("设置自定义菜单出现异常" + err.Error())
|
||||
return
|
||||
}
|
||||
list, err := wx.GetKFList()
|
||||
if err != nil {
|
||||
log.Errorln("获取客服列表错误" + err.Error())
|
||||
return
|
||||
}
|
||||
if len(list.KF_list) < 1 {
|
||||
err := wx.AddKFAccount("xxqg@xxqg", "xxqg", utils.StrMd5("123"))
|
||||
if err != nil {
|
||||
log.Errorln("添加客服失败" + err.Error())
|
||||
return
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
wx.HandleFunc("eventCLICK", func(wx *mp.WeiXin, w http.ResponseWriter, r *request.WeiXinRequest, timestamp, nonce string) {
|
||||
if lastNonce == nonce {
|
||||
return
|
||||
}
|
||||
log.Infoln("收到微信点击事件:" + r.EventKey)
|
||||
lastNonce = nonce
|
||||
|
||||
if !checkPermission(r.FromUserName, r.EventKey) {
|
||||
log.Infoln("未通过权限检测的用户事件!")
|
||||
return
|
||||
}
|
||||
|
||||
value, ok := handlers.Load(r.EventKey)
|
||||
if !ok {
|
||||
log.Warningln("未注册key为" + r.EventKey + "的调用方法")
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
defer func() {
|
||||
err := recover()
|
||||
if err != nil {
|
||||
log.Errorln("处理微信事件错误")
|
||||
log.Errorln(err)
|
||||
}
|
||||
}()
|
||||
(value.(WechatHandler))(r.FromUserName, "")
|
||||
}()
|
||||
})
|
||||
|
||||
wx.HandleFunc(mp.GenHttpRouteKey(mp.MsgTypeEvent, mp.EventSubscribe), func(wx *mp.WeiXin, w http.ResponseWriter, r *request.WeiXinRequest, timestamp, nonce string) {
|
||||
sendMsg(r.FromUserName, "你已关注该公众号,请发送申请使用向管理员申请权限吧!")
|
||||
})
|
||||
|
||||
wx.HandleFunc("text", func(wx *mp.WeiXin, w http.ResponseWriter, r *request.WeiXinRequest, timestamp, nonce string) {
|
||||
log.Infoln(fmt.Sprintf("收到了来自用户%v的文本消息:%v", r.FromUserName, r.Content))
|
||||
key := strings.Split(r.Content, " ")[0]
|
||||
|
||||
if !checkPermission(r.FromUserName, key) {
|
||||
log.Infoln("未通过权限检测的用户事件!")
|
||||
return
|
||||
}
|
||||
|
||||
value, ok := handlers.Load(key)
|
||||
if !ok {
|
||||
log.Warningln("未注册key为" + r.EventKey + "的调用方法")
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
defer func() {
|
||||
err := recover()
|
||||
if err != nil {
|
||||
log.Errorln("处理微信事件错误")
|
||||
log.Errorln(err)
|
||||
}
|
||||
}()
|
||||
(value.(WechatHandler))(r.FromUserName, r.Content)
|
||||
}()
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func checkPermission(id string, key string) bool {
|
||||
|
||||
// 这三个不检查权限
|
||||
keys := []string{"use_request", "get_open_id", "/remark"}
|
||||
|
||||
// 通过管理员所有权限
|
||||
if conf.GetConfig().Wechat.SuperOpenID == id {
|
||||
return true
|
||||
}
|
||||
for _, k := range keys {
|
||||
if k == key {
|
||||
return true
|
||||
}
|
||||
}
|
||||
user, err := model.FindWechatUser(id)
|
||||
if err != nil {
|
||||
log.Errorln("获取用户出现错误" + err.Error())
|
||||
sendMsg(id, "请发送申请使用向管理员申请权限!")
|
||||
return false
|
||||
}
|
||||
if user == nil {
|
||||
log.Errorln("不存在该用户!")
|
||||
sendMsg(id, "请发送申请使用向管理员申请权限!")
|
||||
return false
|
||||
}
|
||||
if user.Status != 1 {
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// handleTextUserList
|
||||
/* @Description: 获取当前使用用户列表的处理器
|
||||
* @param id
|
||||
* @param msg
|
||||
*/
|
||||
func handleTextUserList(id, msg string) {
|
||||
|
||||
if id != conf.GetConfig().Wechat.SuperOpenID {
|
||||
return
|
||||
}
|
||||
|
||||
users, err := model.QueryWechatByCondition("")
|
||||
if err != nil {
|
||||
log.Errorln("获取用户列表出现错误" + err.Error())
|
||||
return
|
||||
}
|
||||
message := ""
|
||||
for _, user := range users {
|
||||
message += fmt.Sprintf("open_id:%v\n\n备注:%v\n\n状态:%d", user.OpenID, user.Remark, user.Status)
|
||||
}
|
||||
sendMsg(id, message)
|
||||
}
|
||||
|
||||
func handleTextReject(id, msg string) {
|
||||
|
||||
if id != conf.GetConfig().Wechat.SuperOpenID {
|
||||
return
|
||||
}
|
||||
|
||||
openID := strings.Split(msg, " ")[1]
|
||||
user, err := model.FindWechatUser(openID)
|
||||
if err != nil {
|
||||
log.Errorln("查询wechat用户出现错误" + err.Error())
|
||||
return
|
||||
}
|
||||
user.Status = -1
|
||||
err = model.UpdateWechatUser(user)
|
||||
if err != nil {
|
||||
log.Errorln("更新用户信息出现错误" + err.Error())
|
||||
return
|
||||
}
|
||||
sendMsg(user.OpenID, "管理员已拒绝了你的使用申请!")
|
||||
sendMsg(id, fmt.Sprintf("已拒绝用户(%v)%v使用", user.Remark, user.OpenID))
|
||||
}
|
||||
|
||||
func handleTextPass(id, msg string) {
|
||||
|
||||
if id != conf.GetConfig().Wechat.SuperOpenID {
|
||||
return
|
||||
}
|
||||
|
||||
openID := strings.Split(msg, " ")[1]
|
||||
user, err := model.FindWechatUser(openID)
|
||||
if err != nil {
|
||||
log.Errorln("查询wechat用户出现错误" + err.Error())
|
||||
return
|
||||
}
|
||||
user.Status = 1
|
||||
err = model.UpdateWechatUser(user)
|
||||
if err != nil {
|
||||
log.Errorln("更新用户信息出现错误" + err.Error())
|
||||
return
|
||||
}
|
||||
sendMsg(user.OpenID, "管理员已通过了你的使用申请!")
|
||||
sendMsg(id, fmt.Sprintf("已允许用户(%v)%v使用", user.Remark, user.OpenID))
|
||||
}
|
||||
|
||||
// handleEventUseRequest
|
||||
/* @Description: 处理申请使用的点击事件
|
||||
* @param id
|
||||
* @param msg
|
||||
*/
|
||||
func handleEventUseRequest(id, msg string) {
|
||||
count := model.WechatUserCount(id)
|
||||
if count < 0 {
|
||||
err := model.AddWechatUser(&model.WechatUser{
|
||||
OpenID: id,
|
||||
Remark: "",
|
||||
Status: 0,
|
||||
LastRequestTime: time.Now().Unix(),
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorln("添加用户出现错误" + err.Error())
|
||||
return
|
||||
}
|
||||
sendMsg(conf.GetConfig().Wechat.SuperOpenID, fmt.Sprintf("用户%v申请使用测试号,通过则回复信息:\n通过 %v\n\n拒绝则回复:\n拒绝 %v", id, id, id))
|
||||
} else {
|
||||
user, err := model.FindWechatUser(id)
|
||||
if err != nil {
|
||||
log.Errorln("查询wechat用户错误" + err.Error())
|
||||
return
|
||||
}
|
||||
if user.Status == 1 {
|
||||
sendMsg(id, "你已拥有使用权!")
|
||||
return
|
||||
} else if user.Status == -1 {
|
||||
sendMsg(id, "你已被拉黑,请联系管理员!")
|
||||
return
|
||||
}
|
||||
|
||||
if (time.Now().Unix()-user.LastRequestTime)/3600 < 1 {
|
||||
sendMsg(id, fmt.Sprintf("你已在%v申请过使用权了,请一个小时后再申请!", time.Unix(user.LastRequestTime, 0).Format("2006-01-02 15:04:05")))
|
||||
return
|
||||
}
|
||||
|
||||
if user.LastRequestTime == 0 {
|
||||
user.LastRequestTime = time.Now().Unix()
|
||||
err := model.UpdateWechatUser(user)
|
||||
if err != nil {
|
||||
log.Errorln("更新信息出现错误" + err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
sendMsg(conf.GetConfig().Wechat.SuperOpenID, fmt.Sprintf("用户(%v)%v申请使用测试号,通过则回复信息:\n通过 %v\n\n拒绝则回复:\n拒绝 %v", user.Remark, id, id, id))
|
||||
}
|
||||
}
|
||||
|
||||
// handleTextRemark
|
||||
/* @Description: 添加备注信息
|
||||
* @param id
|
||||
* @param msg
|
||||
*/
|
||||
func handleTextRemark(id, msg string) {
|
||||
data := strings.Split(msg, " ")[1]
|
||||
count := model.WechatUserCount(id)
|
||||
if count < 1 {
|
||||
err := model.AddWechatUser(&model.WechatUser{
|
||||
OpenID: id,
|
||||
Remark: data,
|
||||
Status: 0,
|
||||
LastRequestTime: 0,
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorln("remark出现错误" + err.Error())
|
||||
return
|
||||
}
|
||||
} else {
|
||||
user, err := model.FindWechatUser(id)
|
||||
if err != nil {
|
||||
log.Errorln("查找用户失败" + err.Error())
|
||||
return
|
||||
}
|
||||
user.Remark = data
|
||||
err = model.UpdateWechatUser(user)
|
||||
if err != nil {
|
||||
log.Errorln("remark出现错误" + err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
sendMsg(id, "添加备注信息成功!")
|
||||
}
|
||||
|
||||
// handleTextSendMsg
|
||||
/* @Description: 自定义发送消息
|
||||
* @param id
|
||||
* @param content
|
||||
*/
|
||||
func handleTextSendMsg(id string, content string) {
|
||||
if conf.GetConfig().Wechat.SuperOpenID != id {
|
||||
return
|
||||
}
|
||||
msg := strings.SplitN(content, " ", 3)
|
||||
if len(msg) < 3 {
|
||||
return
|
||||
} else {
|
||||
if msg[0] == "发送" {
|
||||
if msg[1] == "all" || msg[1] == "所有" {
|
||||
sendMsg("all", msg[2])
|
||||
} else {
|
||||
sendMsg(msg[1], msg[2])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func handleGetOpenID(id string, msg string) {
|
||||
sendMsg(id, "你的open_id为"+id)
|
||||
}
|
||||
|
||||
//
|
||||
// handleCheckUpdate
|
||||
// @Description: 检查更新
|
||||
// @param id
|
||||
//
|
||||
func handleCheckUpdate(id string, msg string) {
|
||||
about := utils.GetAbout()
|
||||
sendMsg(id, about)
|
||||
}
|
||||
|
||||
//
|
||||
// handleUpdate
|
||||
// @Description: 开始更新
|
||||
// @param id
|
||||
//
|
||||
func handleUpdate(id string, msg 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, msg 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) {
|
||||
|
||||
if wx == nil {
|
||||
initWx()
|
||||
}
|
||||
|
||||
if id == "all" {
|
||||
userList, err := wx.GetUserList("")
|
||||
if err != nil {
|
||||
log.Errorln("获取关注列表错误")
|
||||
return
|
||||
}
|
||||
url := ""
|
||||
color := ""
|
||||
if strings.Contains(message, "$$$") {
|
||||
splits := strings.Split(message, "$$$")
|
||||
message = splits[0]
|
||||
url = splits[1]
|
||||
if len(splits) == 3 {
|
||||
color = splits[2]
|
||||
}
|
||||
}
|
||||
for _, user := range userList.Data.OpenId {
|
||||
m := map[string]interface{}{
|
||||
"data": map[string]string{
|
||||
"value": message,
|
||||
},
|
||||
}
|
||||
data, _ := json.Marshal(m)
|
||||
|
||||
_, err = wx.SendTemplateMessage(&mp.TemplateMessage{
|
||||
ToUser: user,
|
||||
TemplateId: conf.GetConfig().Wechat.NormalTempID,
|
||||
URL: url,
|
||||
TopColor: color,
|
||||
RawJSONData: data,
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorln("向用户" + user + "推送消息错误")
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if id == "" {
|
||||
id = conf.GetConfig().Wechat.SuperOpenID
|
||||
}
|
||||
|
||||
// 登录消息单独采用模板发送
|
||||
if strings.Contains(message, "login.xuexi.cn") {
|
||||
_, err := wx.SendTemplateMessage(&mp.TemplateMessage{
|
||||
ToUser: id,
|
||||
TemplateId: conf.GetConfig().Wechat.LoginTempID,
|
||||
URL: message,
|
||||
TopColor: "",
|
||||
RawJSONData: nil,
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorln(err.Error())
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
err := wx.PostText(id, message, "xxqg@xxqg")
|
||||
if err != nil {
|
||||
log.Errorln("发送客服消息错误" + err.Error())
|
||||
log.Warningln("开始尝试使用模板消息发送")
|
||||
m := map[string]interface{}{
|
||||
"data": map[string]string{
|
||||
"value": message,
|
||||
},
|
||||
}
|
||||
data, _ := json.Marshal(m)
|
||||
|
||||
_, err = wx.SendTemplateMessage(&mp.TemplateMessage{
|
||||
ToUser: id,
|
||||
TemplateId: conf.GetConfig().Wechat.NormalTempID,
|
||||
URL: "",
|
||||
TopColor: "",
|
||||
RawJSONData: data,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// HandleWechat
|
||||
/* @Description:处理wechat的请求接口
|
||||
* @param rep
|
||||
* @param req
|
||||
*/
|
||||
func HandleWechat(rep http.ResponseWriter, req *http.Request) {
|
||||
if wx == nil {
|
||||
initWx()
|
||||
}
|
||||
wx.ServeHTTP(rep, req)
|
||||
}
|
||||
|
||||
//
|
||||
// handleLogin
|
||||
// @Description: 用户登录
|
||||
// @param id
|
||||
//
|
||||
func handleLogin(id string, msg string) {
|
||||
core := &lib.Core{Push: func(id1 string, kind, message string) {
|
||||
if kind == "flush" && strings.Contains(message, "login.xuexi.cn") {
|
||||
_, err := wx.SendTemplateMessage(&mp.TemplateMessage{
|
||||
ToUser: id,
|
||||
TemplateId: conf.GetConfig().Wechat.LoginTempID,
|
||||
URL: message,
|
||||
TopColor: "",
|
||||
RawJSONData: nil,
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorln(err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
}}
|
||||
_, err := core.L(0, id)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
sendMsg(id, "登录成功")
|
||||
}
|
||||
|
||||
//
|
||||
// handleStartStudy
|
||||
// @Description: 开始学习
|
||||
// @param id
|
||||
//
|
||||
func handleStartStudy(id string, msg string) {
|
||||
users, err := model.QueryByPushID(id)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if users == nil {
|
||||
log.Warningln("还未存在绑定的用户登录")
|
||||
sendMsg(id, "你还没有已登陆的用户,请点击下方登录按钮登录!")
|
||||
return
|
||||
}
|
||||
core := &lib.Core{ShowBrowser: conf.GetConfig().ShowBrowser, Push: func(id1 string, kind, msg string) {
|
||||
}}
|
||||
core.Init()
|
||||
defer core.Quit()
|
||||
for i, user := range users {
|
||||
_, ok := datas1.Load(user.UID)
|
||||
if ok {
|
||||
log.Warningln("用户" + user.Nick + "已经在学习中了,跳过该用户")
|
||||
continue
|
||||
} else {
|
||||
datas1.Store(user.UID, "")
|
||||
}
|
||||
sendMsg(id, fmt.Sprintf("开始学习第%d个用户,用户名:%v", i+1, user.Nick))
|
||||
core.LearnArticle(user)
|
||||
core.LearnVideo(user)
|
||||
core.RespondDaily(user, "daily")
|
||||
core.RespondDaily(user, "weekly")
|
||||
core.RespondDaily(user, "special")
|
||||
datas1.Delete(user.UID)
|
||||
score, _ := lib.GetUserScore(user.ToCookies())
|
||||
sendMsg(id, fmt.Sprintf("第%d个用户%v学习完成,学习积分\n%v", i+1, user.Nick, lib.FormatScore(score)))
|
||||
}
|
||||
}
|
||||
|
||||
func handleGetUser(id string, msg string) {
|
||||
users, err := model.Query()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if users == nil {
|
||||
log.Warningln("还未存在绑定的用户登录")
|
||||
sendMsg(id, "你还没有已登陆的用户,请点击下方登录按钮登录!")
|
||||
return
|
||||
}
|
||||
message := ""
|
||||
config := conf.GetConfig()
|
||||
for _, user := range users {
|
||||
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 += "(已绑定)\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)
|
||||
}
|
||||
|
||||
func handleScore(id string, msg string) {
|
||||
users, err := model.Query()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if users == nil {
|
||||
log.Warningln("还未存在绑定的用户登录")
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
mean = &mp.Menu{Buttons: []mp.MenuButton{
|
||||
{
|
||||
Name: "登录",
|
||||
Type: "click",
|
||||
|
@ -131,309 +703,12 @@ func initWechat() {
|
|||
Type: "click",
|
||||
Key: getOpenID,
|
||||
},
|
||||
{
|
||||
Name: "申请使用",
|
||||
Type: "click",
|
||||
Key: useRequest,
|
||||
},
|
||||
},
|
||||
}})
|
||||
if err != nil {
|
||||
log.Errorln("设置自定义菜单出现异常" + err.Error())
|
||||
return
|
||||
}
|
||||
wx.HandleFunc("eventCLICK", func(wx *mp.WeiXin, w http.ResponseWriter, r *request.WeiXinRequest, timestamp, nonce string) {
|
||||
if lastNonce == nonce {
|
||||
return
|
||||
}
|
||||
lastNonce = nonce
|
||||
value, ok := handlers.Load(r.EventKey)
|
||||
if !ok {
|
||||
log.Warningln("未注册key为" + r.EventKey + "的调用方法")
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
defer func() {
|
||||
err := recover()
|
||||
if err != nil {
|
||||
log.Errorln("处理微信事件错误")
|
||||
log.Errorln(err)
|
||||
}
|
||||
}()
|
||||
(value.(WechatHandler))(r.FromUserName)
|
||||
}()
|
||||
})
|
||||
wx.HandleFunc("text", func(wx *mp.WeiXin, w http.ResponseWriter, r *request.WeiXinRequest, timestamp, nonce string) {
|
||||
|
||||
if r.FromUserName != conf.GetConfig().Wechat.SuperOpenID {
|
||||
log.Infoln("收到了微信文本消息,但不是管理员")
|
||||
return
|
||||
}
|
||||
|
||||
msg := strings.SplitN(r.Content, " ", 3)
|
||||
if len(msg) < 3 {
|
||||
return
|
||||
} else {
|
||||
if msg[0] == "发送" {
|
||||
if msg[1] == "all" || msg[1] == "所有" {
|
||||
sendMsg("all", msg[2])
|
||||
} else {
|
||||
sendMsg(msg[1], msg[2])
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
if id == "all" {
|
||||
userList, err := wx.GetUserList("")
|
||||
if err != nil {
|
||||
log.Errorln("获取关注列表错误")
|
||||
return
|
||||
}
|
||||
url := ""
|
||||
color := ""
|
||||
if strings.Contains(message, "$$$") {
|
||||
splits := strings.Split(message, "$$$")
|
||||
message = splits[0]
|
||||
url = splits[1]
|
||||
if len(splits) == 3 {
|
||||
color = splits[2]
|
||||
}
|
||||
}
|
||||
for _, user := range userList.Data.OpenId {
|
||||
m := map[string]interface{}{
|
||||
"data": map[string]string{
|
||||
"value": message,
|
||||
},
|
||||
}
|
||||
data, _ := json.Marshal(m)
|
||||
|
||||
_, err = wx.SendTemplateMessage(&mp.TemplateMessage{
|
||||
ToUser: user,
|
||||
TemplateId: conf.GetConfig().Wechat.NormalTempID,
|
||||
URL: url,
|
||||
TopColor: color,
|
||||
RawJSONData: data,
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorln("向用户" + user + "推送消息错误")
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 登录消息单独采用模板发送
|
||||
if strings.Contains(message, "login.xuexi.cn") {
|
||||
_, err := wx.SendTemplateMessage(&mp.TemplateMessage{
|
||||
ToUser: id,
|
||||
TemplateId: conf.GetConfig().Wechat.LoginTempID,
|
||||
URL: message,
|
||||
TopColor: "",
|
||||
RawJSONData: nil,
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorln(err.Error())
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
m := map[string]interface{}{
|
||||
"data": map[string]string{
|
||||
"value": message,
|
||||
},
|
||||
}
|
||||
data, _ := json.Marshal(m)
|
||||
if wx == nil {
|
||||
initWx()
|
||||
}
|
||||
_, err := wx.SendTemplateMessage(&mp.TemplateMessage{
|
||||
ToUser: id,
|
||||
TemplateId: conf.GetConfig().Wechat.NormalTempID,
|
||||
URL: "",
|
||||
TopColor: "",
|
||||
RawJSONData: data,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// HandleWechat
|
||||
/* @Description:处理wechat的请求接口
|
||||
* @param rep
|
||||
* @param req
|
||||
*/
|
||||
func HandleWechat(rep http.ResponseWriter, req *http.Request) {
|
||||
if wx == nil {
|
||||
initWx()
|
||||
}
|
||||
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.Contains(message, "login.xuexi.cn") {
|
||||
_, err := wx.SendTemplateMessage(&mp.TemplateMessage{
|
||||
ToUser: id,
|
||||
TemplateId: conf.GetConfig().Wechat.LoginTempID,
|
||||
URL: message,
|
||||
TopColor: "",
|
||||
RawJSONData: nil,
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorln(err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
}}
|
||||
_, err := core.L(0, id)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
sendMsg(id, "登录成功")
|
||||
}
|
||||
|
||||
//
|
||||
// handleStartStudy
|
||||
// @Description: 开始学习
|
||||
// @param id
|
||||
//
|
||||
func handleStartStudy(id string) {
|
||||
users, err := model.QueryByPushID(id)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if users == nil {
|
||||
log.Warningln("还未存在绑定的用户登录")
|
||||
sendMsg(id, "你还没有已登陆的用户,请点击下方登录按钮登录!")
|
||||
return
|
||||
}
|
||||
core := &lib.Core{ShowBrowser: conf.GetConfig().ShowBrowser, Push: func(id1 string, kind, msg string) {
|
||||
}}
|
||||
core.Init()
|
||||
defer core.Quit()
|
||||
for i, user := range users {
|
||||
_, ok := datas1.Load(user.UID)
|
||||
if ok {
|
||||
log.Warningln("用户" + user.Nick + "已经在学习中了,跳过该用户")
|
||||
continue
|
||||
} else {
|
||||
datas1.Store(user.UID, "")
|
||||
}
|
||||
sendMsg(id, fmt.Sprintf("开始学习第%d个用户,用户名:%v", i+1, user.Nick))
|
||||
core.LearnArticle(user)
|
||||
core.LearnVideo(user)
|
||||
core.RespondDaily(user, "daily")
|
||||
core.RespondDaily(user, "weekly")
|
||||
core.RespondDaily(user, "special")
|
||||
datas1.Delete(user.UID)
|
||||
score, _ := lib.GetUserScore(user.ToCookies())
|
||||
sendMsg(id, fmt.Sprintf("第%d个用户%v学习完成,学习积分\n%v", i+1, user.Nick, lib.FormatScore(score)))
|
||||
}
|
||||
}
|
||||
|
||||
func handleGetUser(id string) {
|
||||
users, err := model.Query()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if users == nil {
|
||||
log.Warningln("还未存在绑定的用户登录")
|
||||
sendMsg(id, "你还没有已登陆的用户,请点击下方登录按钮登录!")
|
||||
return
|
||||
}
|
||||
message := ""
|
||||
config := conf.GetConfig()
|
||||
for _, user := range users {
|
||||
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 += "(已绑定)\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)
|
||||
}
|
||||
|
||||
func handleScore(id string) {
|
||||
users, err := model.Query()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if users == nil {
|
||||
log.Warningln("还未存在绑定的用户登录")
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
|
@ -15,9 +15,7 @@ func init() {
|
|||
if log.GetLevel() == log.DebugLevel {
|
||||
client.DebugLog = true
|
||||
client = client.DevMode()
|
||||
|
||||
}
|
||||
client.EnableForceHTTP1()
|
||||
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")
|
||||
}
|
||||
|
@ -40,3 +38,11 @@ func (m myLog) Warnf(format string, v ...interface{}) {
|
|||
func (m myLog) Debugf(format string, v ...interface{}) {
|
||||
log.Debugf(format, v)
|
||||
}
|
||||
|
||||
type LogWriter struct {
|
||||
}
|
||||
|
||||
func (l *LogWriter) Write(p []byte) (n int, err error) {
|
||||
log.Debugln(string(p))
|
||||
return len(p), nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
package utils
|
|
@ -10,7 +10,6 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/imroc/req/v3"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
|
@ -49,7 +48,7 @@ func GetAbout() string {
|
|||
* @return bool
|
||||
*/
|
||||
func CheckUserCookie(cookies []*http.Cookie) (bool, error) {
|
||||
client := req.C().DevMode()
|
||||
client := GetClient()
|
||||
response, err := client.R().SetCookies(cookies...).Get("https://pc-api.xuexi.cn/open/api/score/get")
|
||||
if err != nil {
|
||||
log.Errorln("获取用户总分错误" + err.Error())
|
||||
|
@ -99,7 +98,6 @@ func CheckQuestionDB() bool {
|
|||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
func DownloadDbFile() {
|
||||
|
|
Loading…
Reference in New Issue