22package quan
33
44import (
5- "fmt "
5+ "encoding/json "
66 "strconv"
77 "strings"
88
@@ -11,13 +11,18 @@ import (
1111 "github.com/FloatTech/zbputils/control"
1212 zero "github.com/wdvxdr1123/ZeroBot"
1313 "github.com/wdvxdr1123/ZeroBot/message"
14- "github.com/wdvxdr1123/ZeroBot/utils/helper"
1514)
1615
1716const (
18- quan = "http://tc.tfkapi. top/API/qqqz.php?qq=%v " // api
17+ quan = "http://tfapi. top/API/qqqz.php?type=json& qq=" // api
1918)
2019
20+ type result struct {
21+ Code int `json:"code"`
22+ Msg string `json:"msg"`
23+ Qz string `json:"qz"`
24+ }
25+
2126func init () { // 主函数
2227 en := control .Register ("quan" , & ctrl.Options [* zero.Ctx ]{
2328 DisableOnDefault : false ,
@@ -31,28 +36,25 @@ func init() { // 主函数
3136 if str == "" { // user
3237 str = strconv .FormatInt (ctx .Event .UserID , 10 )
3338 }
34- es , err := web .GetData (fmt . Sprintf ( quan , str ) ) // 将网站返回结果赋值
39+ es , err := web .GetData (quan + str ) // 将网站返回结果赋值
3540 if err != nil {
36- ctx .SendChain (message .Text ("出现错误捏:" , err ))
37- return
38- }
39- if len (helper .BytesToString (es )) <= 24 {
40- ctx .SendChain (message .Text ("网站维护中" )) // 输出结果
41+ ctx .SendChain (message .Text ("出现错误捏: " , err ))
4142 return
4243 }
43- f := helper . BytesToString ( es )[ 24 :]
44- _ , err = strconv . Atoi ( f )
44+ var data result
45+ err = json . Unmarshal ( es , & data )
4546 if err != nil {
46- ctx .SendChain (message .Text ("网站维护中" )) // 输出结果
47+ ctx .SendChain (message .Text ("解析json错误: " , err ))
4748 return
4849 }
4950 var msg strings.Builder
50- msg .WriteString ("查询账号:" )
51+ msg .WriteString ("查询账号: " )
5152 msg .WriteString (str )
5253 msg .WriteString ("\n " )
53- msg .WriteString ("查询状态:成功\n " )
54- msg .WriteString ("您的权重为:" )
55- msg .WriteString (f )
54+ msg .WriteString ("查询状态: " )
55+ msg .WriteString (data .Msg )
56+ msg .WriteString ("\n 您的权重为: " )
57+ msg .WriteString (data .Qz )
5658 ctx .SendChain (message .Text (msg .String ())) // 输出结果
5759 })
5860}
0 commit comments