Files
jx-callback/controllers/weixin_callback.go
suyl 5f6cccbd0a aa
2021-09-07 17:42:00 +08:00

40 lines
996 B
Go

package controllers
import (
"git.rosy.net.cn/baseapi/utils"
"io/ioutil"
"net/http"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
"github.com/astaxie/beego/server/web"
)
type WeixinController struct {
web.Controller
}
func (c *WeixinController) Msg() {
if c.Ctx.Input.Method() == http.MethodGet {
signature := c.GetString("signature")
timestamp := c.GetString("timestamp")
nonce := c.GetString("nonce")
echostr := c.GetString("echostr")
isValid := api.WeixinAPI.ValidateWXCallbackURL(signature, timestamp, nonce)
globals.SugarLogger.Debugf("weixin URL check is:%t", isValid)
c.Ctx.WriteString(echostr)
} else {
c.Data["json"] = "ok"
c.ServeJSON()
}
}
func (c *WeixinController) WifiMsg() {
data, _ := ioutil.ReadAll(c.Ctx.Request.Body)
values, _ := utils.HTTPBody2Values(data, false)
mapData := utils.URLValues2Map(values)
globals.SugarLogger.Debugf("weixin URL check is:%v", mapData)
c.Data["json"] = "ok"
c.ServeJSON()
}