From 3b2c0555ed92b0dd3150c3701879cc50b82c7270 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 26 Feb 2019 15:28:51 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E5=BE=AE=E4=BF=A1=E5=85=AC=E4=BC=97?= =?UTF-8?q?=E5=8F=B7=E6=B6=88=E6=81=AF=E7=9B=B8=E5=85=B3=E7=9A=84=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/app.conf | 3 +++ controllers/weixin_callback.go | 28 ++++++++++++++++++++++++++++ globals/api/api.go | 3 +++ routers/router.go | 1 + 4 files changed, 35 insertions(+) create mode 100644 controllers/weixin_callback.go diff --git a/conf/app.conf b/conf/app.conf index 5c9b94ef3..569ddc4f7 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -36,6 +36,9 @@ qiniuBucket = "jingxistandardlib" showAppID = 82806 showAppSecret = "384f911735334bf7a150f3bd3bdf0c1e" +weixinMsgToken = "weixin" +weixinMsgKey = "duyaeVYUsz8LuKBqJeQO1NX6KmoC43yfMsbJybcRJ3e" + weixinMiniAppID = "wx4b5930c13f8b1170" weixinMiniSecret = "2a57228a716ce991a52739f0ff41111d" diff --git a/controllers/weixin_callback.go b/controllers/weixin_callback.go new file mode 100644 index 000000000..65933f7ee --- /dev/null +++ b/controllers/weixin_callback.go @@ -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() + } +} diff --git a/globals/api/api.go b/globals/api/api.go index 923cad0d2..8c1413693 100644 --- a/globals/api/api.go +++ b/globals/api/api.go @@ -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")) diff --git a/routers/router.go b/routers/router.go index 30128cdb0..0330fb400 100644 --- a/routers/router.go +++ b/routers/router.go @@ -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) {