kefu/wechathook/http.go

89 lines
2.8 KiB
Go
Raw Normal View History

2024-12-10 02:50:12 +00:00
package main
import (
"bytes"
"github.com/gin-gonic/gin"
"io/ioutil"
"log"
"net/http"
"wechathook/models"
"wechathook/routers"
)
func main() {
router := gin.Default()
router.Use(CrossSite)
router.Delims("<{", "}>")
//客服系统消息回调
router.POST("/kefuCallback", routers.PostKefuCallback)
router.GET("/getSetting", routers.GetSetting)
router.POST("/postSetting", routers.PostSetting)
router.POST("/postSettingByKey", routers.PostSettingByKey)
//查询
router.GET("/search", routers.GetSearch)
//查询excel
router.GET("/qq", routers.QQ)
//当前登录信息
router.GET("/wechatInfo", routers.GetWechatInfo)
router.POST("/wechat", routers.Wechat)
router.POST("/wechat39581", routers.Wechat39581)
router.POST("/wechat39825", routers.Wechat39825)
router.POST("/wechatAIStatus", routers.WechatAIStatus)
//微信hook
router.GET("/wechat39825Hook", routers.Wechat39825Hook)
//微信联系人
router.GET("/wechat39825Contacts", routers.Wechat39825Contacts)
//微信联系人
router.POST("/douyin", routers.PostDouyin)
router.LoadHTMLGlob("templates/*")
router.Static("/static", "./static")
router.GET("/", func(c *gin.Context) {
c.HTML(200, "index.html", gin.H{
"title": "Main website",
})
})
//设置页面
router.GET("/setting", func(c *gin.Context) {
c.HTML(200, "setting.html", gin.H{})
})
//设置微信页面
router.GET("/setting_wechat", func(c *gin.Context) {
c.HTML(200, "setting_wechat.html", gin.H{})
})
//设置QQ页面
router.GET("/setting_qq", func(c *gin.Context) {
c.HTML(200, "setting_qq.html", gin.H{})
})
//设置抖音页面
router.GET("/setting_douyin", func(c *gin.Context) {
c.HTML(200, "setting_douyin.html", gin.H{})
})
//初始化数据库
models.InitDB()
log.Println("请使用浏览器打开:http://127.0.0.1:8089")
router.Run(":8089")
}
func CrossSite(c *gin.Context) {
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
//服务器支持的所有跨域请求的方法
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE,UPDATE")
//允许跨域设置可以返回其他子段,可以自定义字段
c.Header("Access-Control-Allow-Headers", "x-requested-with,Content-Type,Authorization,Content-Length,X-CSRF-Token,Token,session")
// 允许浏览器(客户端)可以解析的头部 (重要)
c.Header("Access-Control-Expose-Headers", "Content-Length,Access-Control-Allow-Origin,Access-Control-Allow-Headers")
c.Header("X-Content-Type-Options", "nosniff")
//允许客户端传递校验信息比如 cookie (重要)
c.Header("Access-Control-Allow-Credentials", "true")
if c.Request.Method == "OPTIONS" {
c.JSON(http.StatusOK, "Options Request!")
c.Abort()
}
data, err := c.GetRawData()
if err != nil {
log.Println(err.Error())
}
c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(data)) // 关键点
c.Next()
}