コード例 #1
0
ファイル: controller.go プロジェクト: zileyuan/hidog
// 文本消息的 Handler
func TextMessageHandler(w http.ResponseWriter, r *mp.Request) {
	// 简单起见,把用户发送过来的文本原样回复过去
	text := request.GetText(r.MixedMsg) // 可以省略...
	resp := response.NewText(text.FromUserName, text.ToUserName, text.CreateTime, text.Content)
	mp.WriteRawResponse(w, r, resp) // 明文模式
	//mp.WriteAESResponse(w, r, resp) // 安全模式
}
コード例 #2
0
ファイル: main.go プロジェクト: kekek/test
//菜单处理地理位置信息
func LocationEventSelectMessageHandle(w http.ResponseWriter, r *mp.Request) {
	location := menu.GetLocationSelectEvent(r.MixedMsg)
	fmt.Println(location)

	resp := response.NewText(location.FromUserName, location.ToUserName, location.CreateTime, location.SendLocationInfo.Label)

	mp.WriteRawResponse(w, r, resp)
	fmt.Println("LocationEventSelectMessageHandle")
}
コード例 #3
0
ファイル: main.go プロジェクト: kekek/test
func ViewMessageHandler(w http.ResponseWriter, r *mp.Request) {
	context := menu.GetViewEvent(r.MixedMsg)

	fmt.Println(context)

	content := context.MsgType

	resp := response.NewText(context.FromUserName, context.ToUserName, context.CreateTime, content)

	mp.WriteRawResponse(w, r, resp)
	fmt.Println("ViewMessageHandler")
}
コード例 #4
0
ファイル: main.go プロジェクト: kekek/test
// 文本消息的 Handler
func TextMessageHandler(w http.ResponseWriter, r *mp.Request) {

	fmt.Println("用户事件:", r.MixedMsg.Event)
	fmt.Println(r.MixedMsg.EventKey)

	fmt.Println("==用户请求==")
	fmt.Println(string(r.RawMsgXML))

	// 简单起见,把用户发送过来的文本原样回复过去
	text := request.GetText(r.MixedMsg) // 可以省略, 直接从 r.MixedMsg 取值
	resp := response.NewText(text.FromUserName, text.ToUserName, text.CreateTime, text.Content)

	mp.WriteRawResponse(w, r, resp) // 明文模式
	//	mp.WriteAESResponse(w, r, resp) // 安全模式
}
コード例 #5
0
ファイル: handler.go プロジェクト: xuebing1110/handler
func (h_pool *HandlerPool) Unmarshal(h *HandleBean, ret_i interface{}) (interface{}, error) {
	ret_type := reflect.TypeOf(ret_i).String()
	switch ret_type {
	case "string":
		resp_str, _ := ret_i.(string)
		if resp_str == "" {
			return nil, errors.New("no response")
		} else {
			return response.NewText(h.UserID, h.ServID, h.Createtime, resp_str), nil
		}
	case "*media.MediaInfo":
		media_info, _ := ret_i.(*media.MediaInfo)
		return response.NewImage(h.UserID, h.ServID, h.Createtime, media_info.MediaId), nil
	default:
		return nil, errors.New("unknown type:" + ret_type)
	}
}
コード例 #6
0
ファイル: main.go プロジェクト: kekek/test
//====自定义事件推送====
func EventMessageHandler(w http.ResponseWriter, r *mp.Request) {

	text := menu.GetClickEvent(r.MixedMsg)
	location := menu.GetLocationSelectEvent(r.MixedMsg)

	//	key := "click_count_"+text.EventKey

	var content string
	switch text.EventKey {
	case "V1001_TODAY_MUSIC":
		content = text.EventKey + "你点击了一下"
	case "V1001_GOOD":
		content = text.EventKey + "收到您的点赞,我非常高兴"
	case "V1001_IMG": //回复图片信息
		resp := response.NewImage(text.FromUserName, text.ToUserName, text.CreateTime, mediaId)
		mp.WriteRawResponse(w, r, resp)
	case "V1001_LOCATION":
		content = text.Event + "text - 地理位置上报成功"
		fmt.Println(content)
		fmt.Println(location.SendLocationInfo.Label)
		fmt.Println(location.SendLocationInfo.PoiName)

	default:
		content = text.EventKey + "oh ,what is wrong"
	}

	switch location.EventKey {
	case "V1001_LOCATION":
		fmt.Println(location.EventKey)
		content = location.Event + " location - 上报地理位置成功"
		fmt.Println(location.SendLocationInfo.Label)
		fmt.Println(location.SendLocationInfo.PoiName)
	default:
		fmt.Println(location.EventKey)
		content = "location - 上报地理位置失败"
	}
	//	Incr(key)

	resp := response.NewText(text.FromUserName, text.ToUserName, text.CreateTime, content)

	mp.WriteRawResponse(w, r, resp) // 明文模式
}