File tree Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change 2
2
package kfccrazythursday
3
3
4
4
import (
5
- "github.com/FloatTech/floatbox/binary"
5
+ "encoding/json"
6
+
6
7
"github.com/FloatTech/floatbox/web"
7
8
ctrl "github.com/FloatTech/zbpctrl"
8
9
"github.com/FloatTech/zbputils/control"
@@ -11,9 +12,15 @@ import (
11
12
)
12
13
13
14
const (
14
- crazyURL = "http ://api.jixs.cc /api/wenan-fkxqs/index.php "
15
+ crazyURL = "https ://api.pearktrue.cn /api/kfc/ "
15
16
)
16
17
18
+ type crazyResponse struct {
19
+ Code int `json:"code"`
20
+ Msg string `json:"msg"`
21
+ Text string `json:"text"`
22
+ }
23
+
17
24
func init () {
18
25
engine := control .AutoRegister (& ctrl.Options [* zero.Ctx ]{
19
26
DisableOnDefault : false ,
@@ -26,6 +33,18 @@ func init() {
26
33
ctx .SendChain (message .Text ("ERROR: " , err ))
27
34
return
28
35
}
29
- ctx .SendChain (message .Text (binary .BytesToString (data )))
36
+
37
+ var resp crazyResponse
38
+ if err := json .Unmarshal (data , & resp ); err != nil {
39
+ ctx .SendChain (message .Text ("JSON解析失败: " , err ))
40
+ return
41
+ }
42
+
43
+ if resp .Code != 200 {
44
+ ctx .SendChain (message .Text ("API返回错误: " , resp .Msg ))
45
+ return
46
+ }
47
+
48
+ ctx .SendChain (message .Text (resp .Text ))
30
49
})
31
50
}
You can’t perform that action at this time.
0 commit comments