- 微信公众号消息相关的消息回调
This commit is contained in:
@@ -36,6 +36,9 @@ qiniuBucket = "jingxistandardlib"
|
||||
showAppID = 82806
|
||||
showAppSecret = "384f911735334bf7a150f3bd3bdf0c1e"
|
||||
|
||||
weixinMsgToken = "weixin"
|
||||
weixinMsgKey = "duyaeVYUsz8LuKBqJeQO1NX6KmoC43yfMsbJybcRJ3e"
|
||||
|
||||
weixinMiniAppID = "wx4b5930c13f8b1170"
|
||||
weixinMiniSecret = "2a57228a716ce991a52739f0ff41111d"
|
||||
|
||||
|
||||
28
controllers/weixin_callback.go
Normal file
28
controllers/weixin_callback.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
type WeixinController struct {
|
||||
beego.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()
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,9 @@ func Init() {
|
||||
if weixinToken := beego.AppConfig.DefaultString("weixinToken", ""); weixinToken != "" {
|
||||
WeixinAPI.CBSetToken(weixinToken)
|
||||
}
|
||||
if weixinMsgToken := beego.AppConfig.DefaultString("weixinMsgToken", ""); weixinMsgToken != "" {
|
||||
WeixinAPI.SetMsgTokenAndKey(weixinMsgToken, beego.AppConfig.DefaultString("weixinMsgKey", ""))
|
||||
}
|
||||
}
|
||||
WeixinMiniAPI = weixinapi.New(beego.AppConfig.String("weixinMiniAppID"), beego.AppConfig.String("weixinMiniSecret"))
|
||||
|
||||
|
||||
@@ -91,6 +91,7 @@ func init() {
|
||||
beego.AutoRouter(&controllers.EbaiController{})
|
||||
beego.AutoRouter(&controllers.MtwmController{})
|
||||
beego.AutoRouter(&controllers.WeimobController{})
|
||||
beego.AutoRouter(&controllers.WeixinController{})
|
||||
|
||||
// 如下都是用于检测存活的空接口
|
||||
beego.Any("/", func(ctx *beecontext.Context) {
|
||||
|
||||
Reference in New Issue
Block a user