Example #1
0
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)
	}
}
Example #2
0
File: main.go Project: 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) // 明文模式
}