From a8870eb932c056291172c69ec0873a53a5af9ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=A5=E6=B5=B7?= Date: Sun, 17 Mar 2024 23:47:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=98=B2=E6=AD=A2=E5=8F=91=E9=80=81?= =?UTF-8?q?=E7=A9=BA=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wclient/client.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/wclient/client.go b/wclient/client.go index d2a0732..9f5480c 100644 --- a/wclient/client.go +++ b/wclient/client.go @@ -67,8 +67,15 @@ func Register() *wcferry.Client { // return int32 0 为成功,其他失败 func SendFlexMsg(msg, wxid, roomid string) int32 { - wxid = strings.Trim(wxid, "-") - roomid = strings.Trim(roomid, "-") + // 验证参数 + msg = strings.TrimSpace(strings.Trim(msg, "-")) + wxid = strings.TrimSpace(strings.Trim(wxid, "-")) + roomid = strings.TrimSpace(strings.Trim(roomid, "-")) + if msg == "" || (wxid == "" && roomid == "") { + return -1 + } + + // 重组参数 receiver, ater := wxid, "" if roomid != "" { receiver, ater = roomid, wxid @@ -86,16 +93,15 @@ func SendFlexMsg(msg, wxid, roomid string) int32 { // 发送卡片信息 if strings.HasPrefix(msg, "card\n") { - if args := strings.Split(msg, "\n")[1:]; len(args) >= 6 { - return wc.CmdClient.SendRichText(args[0], args[1], args[2], args[3], args[4], args[5], receiver) + if p := strings.Split(msg, "\n")[1:]; len(p) >= 6 { + return wc.CmdClient.SendRichText(p[0], p[1], p[2], p[3], p[4], p[5], receiver) } } // 发送文本信息 if ater != "" { - user := wc.CmdClient.GetInfoByWxid(ater) - if user != nil && user.Name != "" { - msg = "@" + user.Name + "\n" + msg + if u := wc.CmdClient.GetInfoByWxid(ater); u != nil && u.Name != "" { + msg = "@" + u.Name + "\n" + msg } } return wc.CmdClient.SendTxt(msg, receiver, ater)