示例#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)
}