逻辑错误发送到飞书

This commit is contained in:
hahwu 2025-02-12 14:56:48 +08:00
parent 862d885d21
commit 2c68486e08
2 changed files with 71 additions and 34 deletions

View File

@ -12,36 +12,21 @@ const (
FEISHU_WEBHOOK = "https://open.feishu.cn/open-apis/bot/v2/hook/70e24a79-b019-434a-b4d1-4592bbf7c311" 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{}{ payload := map[string]interface{}{
"msg_type": "post", "msg_type": "interactive",
"content": map[string]interface{}{ "card": map[string]interface{}{
"post": map[string]interface{}{ "type": "template",
"zh_cn": map[string]interface{}{ "data": map[string]interface{}{
"title": "服务器报错提醒", "template_id": "AAqFpbuPhFSEx",
"content": [][]map[string]interface{}{ "template_version_name": "1.0.0",
{ "template_variable": map[string]interface{}{
{ "appName": conf.Server.GameName,
"tag": "text", "playerId": PlayerId,
"text": fmt.Sprintf("AppName:%s", conf.Server.GameName), "funcName": FuncName,
// "style": []string{"bold", "lineThrough"}, "fatal_msg": msg,
},
},
{
{
"tag": "text",
"text": fmt.Sprintf("ServerName:%s", conf.Server.ServerName),
// "style": []string{"bold", "lineThrough"},
},
},
{
{
"tag": "text",
"text": msg,
},
},
},
}, },
}, },
}, },
@ -73,3 +58,47 @@ func SendFeishuMsg(msg string) error {
return nil 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
}

View File

@ -69,6 +69,12 @@ func HandleClientReq(args []interface{}) {
detail := &msg.ReqRegisterAccount{} detail := &msg.ReqRegisterAccount{}
proto.Unmarshal(buf, detail) proto.Unmarshal(buf, detail)
gl := G_getGameLogic() 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) { if gl.IsExsitAccount(detail.UserName) {
ResRegisterAccount := &msg.ResRegisterAccount{} ResRegisterAccount := &msg.ResRegisterAccount{}
ResRegisterAccount.ResultCode = MergeConst.Protocol_Error_Account_Exist ResRegisterAccount.ResultCode = MergeConst.Protocol_Error_Account_Exist
@ -97,14 +103,16 @@ func HandleClientReq(args []interface{}) {
data, _ := proto.Marshal(ResRegisterAccount) data, _ := proto.Marshal(ResRegisterAccount)
gl.PackResInfo(a, "ResRegisterAccount", data) gl.PackResInfo(a, "ResRegisterAccount", data)
case "ReqLogin": case "ReqLogin":
defer func() {
if r := recover(); r != nil {
log.Debug("uid : %d, func : %s, fatal : %s", 0, m.GetFunc(), r)
}
}()
detail := &msg.ReqLogin{} detail := &msg.ReqLogin{}
proto.Unmarshal(buf, detail) proto.Unmarshal(buf, detail)
accountInfo := db.GetAccountInfoFromDb(detail.UserName) 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{} ResLogin := &msg.ResLogin{}
if accountInfo != nil { if accountInfo != nil {
if accountInfo.UserPassword == detail.UserPwd { if accountInfo.UserPassword == detail.UserPwd {
@ -161,7 +169,7 @@ func HandleClientReq(args []interface{}) {
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
log.Error("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)) GoUtil.SendFeishuFatal(int(p.(*Player).M_DwUin), m.GetFunc(), r.(string))
p.(*Player).Recover(backup) //还原Player的数据 p.(*Player).Recover(backup) //还原Player的数据
} }
p.(*Player).lock.Unlock() //解锁 p.(*Player).lock.Unlock() //解锁