kefu/wechathook/routers/QQ.go

39 lines
757 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package routers
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/xuri/excelize/v2"
"log"
"net/url"
"strings"
"wechathook/models"
)
func QQ(c *gin.Context) {
name := c.Query("name")
name, _ = url.QueryUnescape(name)
log.Println("收到QQ信息", name)
f, err := excelize.OpenFile("database.xlsx")
if err != nil {
log.Println(err)
return
}
reply := ""
// 获取 Sheet1 上所有单元格
rows, err := f.GetRows("Sheet1")
for _, row := range rows {
if strings.Contains(row[0], name) {
reply += row[1] + "\n"
}
}
reply = strings.Trim(reply, "\n")
result := ""
replyTemplate := models.FindSetting("replyTemplate").Value
if replyTemplate != "" {
result = fmt.Sprintf(replyTemplate, reply)
}
c.String(200, result)
}