diff --git a/src/server/GoUtil/feishu.go b/src/server/GoUtil/feishu.go index c3b8aec4..62f000e8 100644 --- a/src/server/GoUtil/feishu.go +++ b/src/server/GoUtil/feishu.go @@ -12,36 +12,21 @@ const ( FEISHU_WEBHOOK = "https://open.feishu.cn/open-apis/bot/v2/hook/70e24a79-b019-434a-b4d1-4592bbf7c311" ) -func SendFeishuMsg(msg string) error { +// AAqFpbuPhFSEx +func SendFeishuFatal(PlayerId int, FuncName string, msg string) error { // 创建请求体 payload := map[string]interface{}{ - "msg_type": "post", - "content": map[string]interface{}{ - "post": map[string]interface{}{ - "zh_cn": map[string]interface{}{ - "title": "服务器报错提醒", - "content": [][]map[string]interface{}{ - { - { - "tag": "text", - "text": fmt.Sprintf("AppName:%s", conf.Server.GameName), - // "style": []string{"bold", "lineThrough"}, - }, - }, - { - { - "tag": "text", - "text": fmt.Sprintf("ServerName:%s", conf.Server.ServerName), - // "style": []string{"bold", "lineThrough"}, - }, - }, - { - { - "tag": "text", - "text": msg, - }, - }, - }, + "msg_type": "interactive", + "card": map[string]interface{}{ + "type": "template", + "data": map[string]interface{}{ + "template_id": "AAqFpbuPhFSEx", + "template_version_name": "1.0.0", + "template_variable": map[string]interface{}{ + "appName": conf.Server.GameName, + "playerId": PlayerId, + "funcName": FuncName, + "fatal_msg": msg, }, }, }, @@ -73,3 +58,47 @@ func SendFeishuMsg(msg string) error { return nil } + +func SendFeishuMsg2(msg string) error { + // 创建请求体 + payload := map[string]interface{}{ + "msg_type": "interactive", + "card": map[string]interface{}{ + "type": "template", + "data": map[string]interface{}{ + "template_id": "AAqFpLD2XfySR", + "template_version_name": "1.0.1", + "template_variable": map[string]interface{}{ + "appName": conf.Server.GameName, + }, + }, + }, + } + + 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 +} diff --git a/src/server/game/external.go b/src/server/game/external.go index d6d28051..824143ce 100644 --- a/src/server/game/external.go +++ b/src/server/game/external.go @@ -69,6 +69,12 @@ func HandleClientReq(args []interface{}) { detail := &msg.ReqRegisterAccount{} proto.Unmarshal(buf, detail) gl := G_getGameLogic() + defer func() { + if r := recover(); r != nil { + GoUtil.SendFeishuFatal(0, m.GetFunc(), fmt.Sprintf("username: %s, fatal: %s", detail.UserName, r)) + log.Debug("uid : %d, func : %s, fatal : %s", 0, m.GetFunc(), r) + } + }() if gl.IsExsitAccount(detail.UserName) { ResRegisterAccount := &msg.ResRegisterAccount{} ResRegisterAccount.ResultCode = MergeConst.Protocol_Error_Account_Exist @@ -97,14 +103,16 @@ func HandleClientReq(args []interface{}) { data, _ := proto.Marshal(ResRegisterAccount) gl.PackResInfo(a, "ResRegisterAccount", data) case "ReqLogin": - defer func() { - if r := recover(); r != nil { - log.Debug("uid : %d, func : %s, fatal : %s", 0, m.GetFunc(), r) - } - }() + detail := &msg.ReqLogin{} proto.Unmarshal(buf, detail) accountInfo := db.GetAccountInfoFromDb(detail.UserName) + defer func() { + if r := recover(); r != nil { + GoUtil.SendFeishuFatal(0, m.GetFunc(), fmt.Sprintf("username: %s, fatal: %s", detail.UserName, r)) + log.Debug("uid : %d, func : %s, fatal : %s", 0, m.GetFunc(), r) + } + }() ResLogin := &msg.ResLogin{} if accountInfo != nil { if accountInfo.UserPassword == detail.UserPwd { @@ -161,7 +169,7 @@ func HandleClientReq(args []interface{}) { defer func() { if r := recover(); r != nil { 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)) + GoUtil.SendFeishuFatal(int(p.(*Player).M_DwUin), m.GetFunc(), r.(string)) p.(*Player).Recover(backup) //还原Player的数据 } p.(*Player).lock.Unlock() //解锁