示例#1
0
func (c *MainController) Post() {

	Log.Info("Post Request")
	aesKey, err := util.AESKeyDecode("6c0p5ooqHpxLm8tDQo2yFN0lPl8FiunHz6s3uwBHMyj") // 这里 encodedAESKey 改成你自己的参数
	if err != nil {
		panic(err)
	}

	messageServeMux := mp.NewMessageServeMux()
	messageServeMux.MessageHandleFunc(request.MsgTypeText, TextMessageHandler)

	invalidRequesthandler := mp.InvalidRequestHandlerFunc(ErrorHandler)

	// 下面函数的几个参数设置成你自己的参数: oriId, token, appId
	mpServer := mp.NewDefaultServer("gh_d1ccedd04e4b", "maihaoguo", "wx8657df9e66c8277d", aesKey, messageServeMux)
	mpServerFrontend := mp.NewServerFrontend(mpServer, invalidRequesthandler, nil)

	// queryValues, err := url.ParseQuery(c.Ctx.Request.URL.RawQuery)
	// if err != nil {
	// 	Log.Info("错误暂不处理")
	// 	//frontend.invalidRequestHandler.ServeInvalidRequest(w, r, err)
	// 	return
	// }

	// // if interceptor := frontend.interceptor; interceptor != nil && !interceptor.Intercept(w, r, queryValues) {
	// // 	return
	// // }

	// mp.ServeHTTP(c.Ctx.ResponseWriter, c.Ctx.Request, queryValues, mpServer, nil)

	mpServerFrontend.ServeHTTP(c.Ctx.ResponseWriter, c.Ctx.Request)
}
示例#2
0
func AnyValidate(ctx *macaron.Context) {
	aesKey, err := util.AESKeyDecode(AESKEY)
	if err != nil {
		panic(err)
	}

	messageServeMux := mp.NewMessageServeMux()
	messageServeMux.MessageHandleFunc(request.MsgTypeText, TextMessageHandler) // 注册文本处理 Handler
	wechatServer := mp.NewDefaultServer(ORIID, TOKEN, APPID, aesKey, messageServeMux)
	wechatServerFrontend := mp.NewServerFrontend(wechatServer, mp.ErrorHandlerFunc(ErrorHandler), nil)
	wechatServerFrontend.ServeHTTP(ctx.Resp, ctx.Req.Request)
}