逻辑错误发送到飞书

This commit is contained in:
hahwu 2025-02-12 11:41:49 +08:00
parent e7ccaf65d2
commit a1056a5556
2 changed files with 51 additions and 1 deletions

View File

@ -0,0 +1,48 @@
package GoUtil
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
const (
FEISHU_WEBHOOK = "https://open.feishu.cn/open-apis/bot/v2/hook/70e24a79-b019-434a-b4d1-4592bbf7c311"
)
func SendFeishuMsg(msg string) error {
// 创建请求体
payload := map[string]interface{}{
"msg_type": "text",
"content": map[string]string{
"text": msg,
},
}
payloadBytes, err := json.Marshal(payload)
if err != nil {
return err
}
// 创建HTTP请求
req, err := http.NewRequest("POST", FEISHU_WEBHOOK, bytes.NewBuffer(payloadBytes))
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/json")
// 发送请求
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
// 检查响应状态码
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("failed to send message, status code: %d", resp.StatusCode)
}
return nil
}

View File

@ -1,6 +1,7 @@
package game package game
import ( import (
"fmt"
"reflect" "reflect"
"server/GoUtil" "server/GoUtil"
"server/MergeConst" "server/MergeConst"
@ -159,7 +160,8 @@ func HandleClientReq(args []interface{}) {
backup := p.(*Player).BackUp() // 备份当前的 Player 值 backup := p.(*Player).BackUp() // 备份当前的 Player 值
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
log.Debug("uid : %d, func : %s, fatal : %s", p.(*Player).M_DwUin, m.GetFunc(), r) log.Error("uid : %d, func : %s, fatal : %s", p.(*Player).M_DwUin, m.GetFunc(), r)
GoUtil.SendFeishuMsg(fmt.Sprintf("uid : %d, func : %s, fatal : %s", p.(*Player).M_DwUin, m.GetFunc(), r))
p.(*Player).Recover(backup) //还原Player的数据 p.(*Player).Recover(backup) //还原Player的数据
} }
p.(*Player).lock.Unlock() //解锁 p.(*Player).lock.Unlock() //解锁