예제 #1
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)
}
예제 #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)
}
예제 #3
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)
}