From 39e1f56955f7c99fc6941f27202eb5160f2d227f Mon Sep 17 00:00:00 2001 From: Doordoorjay <31199261+Doordoorjay@users.noreply.github.com> Date: Tue, 6 May 2025 19:12:41 +1000 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=96=AF=E7=8B=82=E6=98=9F=E6=9C=9F?= =?UTF-8?q?=E5=9B=9B=20API=20(#1161)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/kfccrazythursday/kfccrazythursday.go | 25 ++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/plugin/kfccrazythursday/kfccrazythursday.go b/plugin/kfccrazythursday/kfccrazythursday.go index a7c2cd26..37334039 100644 --- a/plugin/kfccrazythursday/kfccrazythursday.go +++ b/plugin/kfccrazythursday/kfccrazythursday.go @@ -2,7 +2,8 @@ package kfccrazythursday import ( - "github.com/FloatTech/floatbox/binary" + "encoding/json" + "github.com/FloatTech/floatbox/web" ctrl "github.com/FloatTech/zbpctrl" "github.com/FloatTech/zbputils/control" @@ -11,9 +12,15 @@ import ( ) const ( - crazyURL = "http://api.jixs.cc/api/wenan-fkxqs/index.php" + crazyURL = "https://api.pearktrue.cn/api/kfc/" ) +type crazyResponse struct { + Code int `json:"code"` + Msg string `json:"msg"` + Text string `json:"text"` +} + func init() { engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{ DisableOnDefault: false, @@ -26,6 +33,18 @@ func init() { ctx.SendChain(message.Text("ERROR: ", err)) return } - ctx.SendChain(message.Text(binary.BytesToString(data))) + + var resp crazyResponse + if err := json.Unmarshal(data, &resp); err != nil { + ctx.SendChain(message.Text("JSON解析失败: ", err)) + return + } + + if resp.Code != 200 { + ctx.SendChain(message.Text("API返回错误: ", resp.Msg)) + return + } + + ctx.SendChain(message.Text(resp.Text)) }) }