Esempio n. 1
0
func tianxingMuxResponse(reqMsg *WeixinMsg, resp *TianxingResponse) []byte {
	if resp.Code != 200 {
		var respMsg WeixinMsgTextResponse
		respMsg.ToUserName = reqMsg.FromUserName
		respMsg.FromUserName = reqMsg.ToUserName
		respMsg.CreateTime = int(util.GetCurrentSecond())
		respMsg.MsgType = "text"
		respMsg.Content = resp.Msg
		return SerialToXML(respMsg)
	}
	var respMsg WeixinMsgNewsResponse
	respMsg.ToUserName = reqMsg.FromUserName
	respMsg.FromUserName = reqMsg.ToUserName
	respMsg.CreateTime = int(util.GetCurrentSecond())
	respMsg.MsgType = "news"
	cnt := 0
	for _, v := range resp.NewsList {
		var wxnew WeixinNews
		wxnew.Title = v.Title
		wxnew.Description = v.Description
		wxnew.PicUrl = v.PicUrl
		wxnew.Url = v.Url
		respMsg.Items = append(respMsg.Items, wxnew)
		cnt++
		if cnt >= WEIXIN_MAX_NEWS_COUNT {
			break
		}
	}
	respMsg.ArticleCount = cnt
	return SerialToXML(respMsg)
}
Esempio n. 2
0
func HeweatherHttpRequest(reqMsg *WeixinMsg) []byte {
	if reqMsg.MsgType != "text" {
		return []byte("")
	}
	content := reqMsg.Content
	content = strings.TrimSuffix(content, "天气")
	content = strings.TrimSuffix(content, "天气!")
	var hwReq HeweatherRequest
	hwReq.City = content
	resp := DoHeweatherQuery(hwReq)
	if len(resp.Data) > 0 && resp.Data[0].Status == "ok" {
		var respMsg WeixinMsgTextResponse
		respMsg.ToUserName = reqMsg.FromUserName
		respMsg.FromUserName = reqMsg.ToUserName
		respMsg.CreateTime = int(util.GetCurrentSecond())
		respMsg.MsgType = "text"
		respMsg.Content = resp.ToString()
		if respMsg.Content == "" {
			return []byte("")
		}
		return SerialToXML(respMsg)
	} else {
		return []byte("")
	}
}
Esempio n. 3
0
func tulingMuxResponse(reqMsg *WeixinMsg, resp *TulingResponse) []byte {
	if resp.Code == CODE_TEXT {
		var respMsg WeixinMsgTextResponse
		respMsg.ToUserName = reqMsg.FromUserName
		respMsg.FromUserName = reqMsg.ToUserName
		respMsg.CreateTime = int(util.GetCurrentSecond())
		respMsg.MsgType = "text"
		respMsg.Content = resp.Text
		return SerialToXML(respMsg)
	}

	var respMsg WeixinMsgNewsResponse
	respMsg.ToUserName = reqMsg.FromUserName
	respMsg.FromUserName = reqMsg.ToUserName
	respMsg.CreateTime = int(util.GetCurrentSecond())
	respMsg.MsgType = "news"
	cnt := 0
	if resp.Code == CODE_LINK {
		fmt.Println("code:", resp.Code)
		var wxnew WeixinNews
		wxnew.Title = resp.Text
		wxnew.Url = resp.Url
		respMsg.Items = append(respMsg.Items, wxnew)
		cnt++
	} else if resp.Code == CODE_NEWS {
		fmt.Println("code:", resp.Code)
		for _, v := range resp.List {
			var wxnew WeixinNews
			wxnew.Title = v.Article
			wxnew.Description = v.Source
			wxnew.PicUrl = v.Icon
			wxnew.Url = v.DetailUrl
			respMsg.Items = append(respMsg.Items, wxnew)
			cnt++
			if cnt >= WEIXIN_MAX_NEWS_COUNT {
				break
			}
		}
	} else if resp.Code == CODE_TRAIN {
		fmt.Println("code:", resp.Code)
		for _, v := range resp.List {
			var wxnew WeixinNews
			desc := v.Start + "-" + v.Terminal + " " + v.TrainNum + " " + v.StartTime + "~" + v.EndTime
			wxnew.Title = desc
			wxnew.Description = desc
			wxnew.PicUrl = v.Icon
			wxnew.Url = v.DetailUrl
			respMsg.Items = append(respMsg.Items, wxnew)
			cnt++
			if cnt >= WEIXIN_MAX_NEWS_COUNT {
				break
			}
		}
	} else if resp.Code == CODE_AIR {
		fmt.Println("code:", resp.Code)
		for _, v := range resp.List {
			var wxnew WeixinNews
			desc := v.Flight + " " + v.StartTime + "~" + v.EndTime
			wxnew.Title = desc
			wxnew.Description = desc
			wxnew.PicUrl = v.Icon
			respMsg.Items = append(respMsg.Items, wxnew)
			cnt++
			if cnt >= WEIXIN_MAX_NEWS_COUNT {
				break
			}
		}
	} else if resp.Code == CODE_FOOD {
		fmt.Println("code:", resp.Code)
		for _, v := range resp.List {
			var wxnew WeixinNews
			wxnew.Title = v.Name + "\r\n" + v.Info
			wxnew.Description = v.Info
			wxnew.PicUrl = v.Icon
			wxnew.Url = v.DetailUrl
			respMsg.Items = append(respMsg.Items, wxnew)
			cnt++
			if cnt >= WEIXIN_MAX_NEWS_COUNT {
				break
			}
		}
	}
	respMsg.ArticleCount = cnt
	return SerialToXML(respMsg)
}