示例#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
文件: main.go 项目: kekek/test
func main() {

	messageServeMux := mp.NewMessageServeMux()

	messageServeMux.MessageHandleFunc(request.MsgTypeText, TextMessageHandler) // 注册文本处理 Handler

	//菜单事件处理
	messageServeMux.EventHandleFunc(menu.EventTypeClick, EventMessageHandler) // 注册时间处理 Handler

	//菜单跳转链接时间处理
	messageServeMux.EventHandleFunc(menu.EventTypeView, ViewMessageHandler) // 注册时间处理 Handler

	//菜单地理位置处理
	messageServeMux.EventHandleFunc(menu.EventTypeLocationSelect, LocationEventSelectMessageHandle)

	//自动上报地理位置消息
	messageServeMux.EventHandleFunc(request.EventTypeLocation, LocationEventMessageHandle)

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

	mpServerFrontend := mp.NewServerFrontend(mpServer, mp.ErrorHandlerFunc(ErrorHandler), nil)

	// 那么可以这么注册 http.Handler
	http.Handle("/index", mpServerFrontend)
	http.HandleFunc("/createMenu", CreateMenu)

	http.ListenAndServe(":80", nil)
}
示例#3
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)
}
示例#4
0
文件: main.go 项目: kekek/test
func responseText() {

	messageServeMux := mp.NewMessageServeMux()
	messageServeMux.MessageHandleFunc(request.MsgTypeText, TextMessageHandler) // 注册文本处理 Handler

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

	mpServerFrontend := mp.NewServerFrontend(mpServer, mp.ErrorHandlerFunc(ErrorHandler), nil)

	// 如果你在微信后台设置的回调地址是
	//   http://xxx.yyy.zzz/wechat
	// 那么可以这么注册 http.Handler
	http.Handle("/wechat", mpServerFrontend)
	http.ListenAndServe(":80", nil)
}