Skip to content

Commit 39e1f56

Browse files
authored
fix: 疯狂星期四 API (FloatTech#1161)
1 parent 4151464 commit 39e1f56

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

plugin/kfccrazythursday/kfccrazythursday.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
package kfccrazythursday
33

44
import (
5-
"github.com/FloatTech/floatbox/binary"
5+
"encoding/json"
6+
67
"github.com/FloatTech/floatbox/web"
78
ctrl "github.com/FloatTech/zbpctrl"
89
"github.com/FloatTech/zbputils/control"
@@ -11,9 +12,15 @@ import (
1112
)
1213

1314
const (
14-
crazyURL = "http://api.jixs.cc/api/wenan-fkxqs/index.php"
15+
crazyURL = "https://api.pearktrue.cn/api/kfc/"
1516
)
1617

18+
type crazyResponse struct {
19+
Code int `json:"code"`
20+
Msg string `json:"msg"`
21+
Text string `json:"text"`
22+
}
23+
1724
func init() {
1825
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
1926
DisableOnDefault: false,
@@ -26,6 +33,18 @@ func init() {
2633
ctx.SendChain(message.Text("ERROR: ", err))
2734
return
2835
}
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))
3049
})
3150
}

0 commit comments

Comments
 (0)