审核ai结果

master
dustoair 3 years ago
parent 69423e86c0
commit 79c22600d8

@ -0,0 +1,43 @@
package handle
import (
"WechatGateWay/global"
"fmt"
"github.com/jinzhu/gorm"
"log"
)
/**
@author: sre
@date: 2022/8/10 0010
@desc: RecordWechatBlockWords
**/
type WechatBlockWords struct {
gorm.Model
Content string
ContentMd5 string `sql:"unique_index:unique_index_md5"`
OpUser string
}
func RecordWechatBlockWords(text, textMd5, opUser string) {
newRecord := WechatBlockWords{
Content: text,
ContentMd5: textMd5,
OpUser: opUser,
}
result := global.DB.Create(&newRecord) // 通过数据的指针来创建
if result.RowsAffected != 1 {
log.Println(fmt.Sprintf("记录失败text: %s textMd5: %s opUser: %s", text, textMd5, opUser))
}
}
func WordsBlocked(textMd5 string) bool {
var Record WechatBlockWords
if global.DB.Where("ContentMd5 = ?", textMd5).First(&Record).RecordNotFound() {
return false
}
return true
}

@ -1,12 +0,0 @@
package handle
import "github.com/jinzhu/gorm"
type WechatLog struct {
gorm.Model
ToUsername string `xml:"ToUserName"`
FromUsername string `xml:"FromUserName"`
CreateTime uint32 `xml:"CreateTime"`
MsgType string `xml:"MsgType"`
Content string `xml:"Content"`
}

@ -3,9 +3,19 @@ package handle
import (
"WechatGateWay/global"
"fmt"
"github.com/jinzhu/gorm"
"log"
)
type WechatLog struct {
gorm.Model
ToUsername string `xml:"ToUserName"`
FromUsername string `xml:"FromUserName"`
CreateTime uint32 `xml:"CreateTime"`
MsgType string `xml:"MsgType"`
Content string `xml:"Content"`
}
func RecordWechatLog(ToUsername, FromUsername string, CreateTime uint32, MsgType, Content string) {
newRecord := WechatLog{
ToUsername: ToUsername,

@ -20,6 +20,7 @@ func replyText(msgContent MsgContent, timestamp, nonce string, w http.ResponseWr
} else if msgContent.Content == "history" {
cmdString = utils.SlicePrint(global.HistoryCmds)
} else if msgContent.Content == "删除图片" {
//通过文本消息删除上一张图片
lastImg := GetLastWechatLog(msgContent.FromUsername, "image")
err := utils.DeleteFile(lastImg.Content)
if err != nil {
@ -30,6 +31,13 @@ func replyText(msgContent MsgContent, timestamp, nonce string, w http.ResponseWr
return
}
} else if msgContent.Content == "删除文本" {
//通过文本消息删除上一条文本消息
lastText := GetLastWechatLog(msgContent.FromUsername, "text")
textMd5 := utils.Md5String(lastText.Content)
go RecordWechatBlockWords(lastText.Content, textMd5, msgContent.FromUsername)
return
} else {
cmdString = msgContent.Content
}
@ -58,6 +66,11 @@ func replyText(msgContent MsgContent, timestamp, nonce string, w http.ResponseWr
}
}
//文本消息审核
if WordsBlocked(utils.Md5String(replyContent)) {
replyContent = "***(太文明,无法显示)"
}
//构造回复消息
replyMsg, _ := xml.Marshal(ReplyTextMsg{
ToUsername: msgContent.FromUsername,

@ -67,6 +67,7 @@ func InitDB() *gorm.DB {
//自动建表
db.AutoMigrate(&handle.WechatLog{})
db.AutoMigrate(&handle.WechatBlockWords{})
global.DB = db
return db

@ -0,0 +1,18 @@
package utils
import (
"crypto/md5"
"encoding/hex"
)
/**
@author: sre
@date: 2022/8/10 0010
@desc: md5sum a string
**/
//Md5String that md5sum a string
func Md5String(s string) string {
h := md5.New()
h.Write([]byte(s))
return hex.EncodeToString(h.Sum(nil))
}

@ -0,0 +1,18 @@
package utils
import (
"fmt"
"testing"
)
/*
*
@author: sre
@date: 2022/8/10 0010
@desc: test md5String
*
*/
func TestMd5String(t *testing.T) {
s := Md5String("hello")
fmt.Println(s)
}
Loading…
Cancel
Save