abnormal message notification

This commit is contained in:
landaiqing
2024-09-05 23:34:46 +08:00
parent b3ae27dd20
commit c61c33880c
7 changed files with 44 additions and 200 deletions

View File

@@ -0,0 +1,40 @@
package middleware
import (
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/messages"
ginI18n "github.com/gin-contrib/i18n"
"github.com/gin-gonic/gin"
"schisandra-cloud-album/common/result"
"schisandra-cloud-album/global"
"schisandra-cloud-album/utils"
"time"
)
// ExceptionNotification 异常通知中间件
func ExceptionNotification() gin.HandlerFunc {
return func(c *gin.Context) {
defer func() {
if err := recover(); err != nil {
openID := global.CONFIG.Wechat.OpenID
content := `
系统异常通知:
请求时间:` + time.Now().Format("2006-01-02 15:04:05") + `
请求IP` + utils.GetClientIP(c) + `
请求地址:` + c.Request.URL.String() + `
请求方法:` + c.Request.Method + `
请求参数:` + c.Request.Form.Encode() + `
错误信息:` + err.(error).Error() + `
`
messages.NewRaw(`
{
"touser":"` + openID + `",
"msgtype":"text",
"text":{"content":"` + content + `"}"}
}
`)
result.FailWithMessage(ginI18n.MustGetMessage(c, "SystemError"), c)
}
}()
c.Next()
}
}