Example #1
0
func (c *AdminWxTestController) Post() {
	beego.Debug("AdminWxTestController Post")
	op := c.Input().Get("op")
	switch op {
	case "key0":
		key0 := c.Input().Get("key0")
		beego.Debug("key0 :", key0)
		//是否存在关键字
		key_count := int32(0)
		count, err := models.GetKeywordsCount(key0)
		if err != nil {
			beego.Error(err)
		} else {
			key_count = count
		}
		beego.Debug("count :", count)
		beego.Debug("key_count :", key_count)
		if key_count > 0 {
			obj, err := models.GetOneKeywords(key0)
			if err != nil {
				beego.Error(err)
			} else {
				objs, err := models.QueryFuzzyLimitKeyobj(obj.Id, 5)
				if err != nil {
					beego.Error(err)
				}
				if len(objs) > 0 {
					beego.Debug("Keyobjs :", objs)
				} else {

				}
			}
		} else {
			//信息查询
			posts, err := models.QueryFuzzyLimitPost(key0, 5)
			if err != nil {
				beego.Error(err)
			}
			// beego.Debug(requestBody.FromUserName)
			// beego.Debug(requestBody.ToUserName)
			if len(posts) > 0 {

			} else {
			}
		}
		url := fmt.Sprintf("/admin/wxtest?key0=%s", key0)
		c.Redirect(url, 302)
		return
	}
	c.TplName = "adminwxtest.html"
}
Example #2
0
//根据类型解析消息
func responseTypeMsg(body []byte, msgType string) string {
	response_xml := ""
	switch msgType {
	//文字
	case "text":
		requestBody := &TextRequestBody{}
		err := xml.Unmarshal(body, requestBody)
		if err != nil {
			beego.Debug(err.Error())
			response_xml = responseTextMsg(requestBody.FromUserName, error_info, qax580_name)
		} else {
			requestBody := &TextRequestBody{}
			err := xml.Unmarshal(body, requestBody)
			if err != nil {
				response_xml = responseTextMsg(requestBody.FromUserName, error_info, qax580_name)
			} else if requestBody.Content == "你好" || requestBody.Content == "您好" {
				response_xml = responseTextMsg(requestBody.FromUserName, jieshao_info, qax580_name)
			} else if strings.Index(requestBody.Content, "发布") >= 0 {
				response_xml = responseTextMsg(requestBody.FromUserName, function_info, qax580_name)
			} else {
				//是否存在关键字
				key_count := int32(0)
				count, err := models.GetKeywordsCount(requestBody.Content)
				if err != nil {
					beego.Error(err)
				} else {
					key_count = count
				}
				if key_count > 0 {
					obj, err := models.GetOneKeywords(requestBody.Content)
					if err != nil {
						beego.Error(err)
					} else {
						objs, err := models.QueryFuzzyLimitKeyobj(obj.Id, 5)
						if err != nil {
							beego.Error(err)
						}
						if len(objs) > 0 {
							response_xml = responseKeyXML(requestBody.FromUserName, requestBody.Content, objs, qax580_name)
						} else {
							response_xml = responseCustomerService(requestBody.FromUserName, requestBody.ToUserName)
						}
					}
				} else {
					//信息查询
					beego.Debug(requestBody.Content)
					posts, err := models.QueryFuzzyLimitPost(requestBody.Content, 5)
					if err != nil {
						beego.Error(err)
					}
					// beego.Debug(requestBody.FromUserName)
					// beego.Debug(requestBody.ToUserName)
					if len(posts) > 0 {
						response_xml = responseImageTextXML(requestBody.FromUserName, requestBody.Content, posts, qax580_name)
					} else {
						response_xml = responseCustomerService(requestBody.FromUserName, requestBody.ToUserName)
					}
				}
			}
		}
		//音频
	case "voice":
		requestBody := &VoiceRequestBody{}
		err := xml.Unmarshal(body, requestBody)
		if err != nil {
			response_xml = responseTextMsg(requestBody.FromUserName, error_info, qax580_name)
		} else {
			beego.Debug(requestBody.Recognition)
			posts, err := models.QueryFuzzyLimitPost(requestBody.Recognition, 5)
			if err != nil {
				beego.Error(err)
			}
			response_xml = responseImageTextXML(requestBody.FromUserName, requestBody.Recognition, posts, qax580_name)

		}
		//点击
	case "event":
		requestBody := &EventResponseBody{}
		err := xml.Unmarshal(body, requestBody)
		if err != nil {
			beego.Debug(err.Error())
			response_xml = responseTextMsg(requestBody.FromUserName, error_info, qax580_name)
		} else {
			beego.Debug("qax 580 Event:", requestBody.Event, "EventKey", requestBody.EventKey)
			//自定义点击事件
			if requestBody.Event == "CLICK" {
				//推荐
				if requestBody.EventKey == "recommend" {
					// posts, err := models.QueryLimitPost(5)
					// if err != nil {
					// 	beego.Error(err)
					// }
					// response_xml = responseImageTextXML(requestBody.FromUserName, "", posts)
					index, err := models.GetQueryIndex(requestBody.FromUserName)
					if err != nil {
						beego.Error(err)
					}
					posts, err := models.QueryPagePost(index, 5)
					if err != nil {
						beego.Error(err)
					}
					beego.Debug("recommend count :", len(posts))
					if len(posts) != 0 {
						response_xml = responseImageTextXML(requestBody.FromUserName, "", posts, qax580_name)
					} else {
						response_xml = responseTextMsg(requestBody.FromUserName, "今日已无更多推荐信息", qax580_name)
					}
					//关于
				} else if requestBody.EventKey == "about" {
					response_xml = responseAbout(requestBody.FromUserName, qax580_name, about_info)
				} else if requestBody.EventKey == "today" { //今日580
					response_xml = responseToday(requestBody.FromUserName, qax580_name)
				} else {

				}
				//关注
			} else if requestBody.Event == "subscribe" {

				response_xml = responseTextMsg(requestBody.FromUserName, subscribe_info, qax580_name)
				beego.Debug("subscribe qax580")
				eventSubscribe(requestBody, qa_appid, qa_secret)
			} else {
				//其他类型
				response_xml = responseTextMsg(requestBody.FromUserName, error_info, qax580_name)
			}

		}

	default:
		beego.Debug(msgType)
	}
	beego.Debug(response_xml)
	return response_xml
}