/// <summary> /// 处理请求消息 /// </summary> /// <returns>处理结果</returns> public ResponseMessage HandlerRequestMessage() { Dictionary <string, object> bugobj = new Dictionary <string, object>(); bugobj.Add("message", this.message); var request = new RequestClickEventMessage(this.message.Element); /// 返回消息类型 MsgType msgtype = MsgType.Text; // 返回消息 string result = string.Empty; //GetB2CProductInfo getB2CProductInfo = null; try { if (request != null) { // 点击菜单事件推送处理 bugobj.Add("request", request); switch (request.EventKey) { case "V1001_GOOD": result += "感谢您的支持!"; msgtype = MsgType.Text; break; case "V1001_HOT": msgtype = MsgType.Text; MQiushibaike qiushibaike = JsonConvert.DeserializeObject <MQiushibaike>(QiushibaikeHelper.GetJokesByRandom()); result = qiushibaike.JokeContent; break; default: break; } } switch (msgtype) { case MsgType.Text: return(new ResponseTextMessage(request) { CreateTime = DateTime.Now.Ticks, Content = result, }); case MsgType.Image: break; case MsgType.Voice: break; case MsgType.Video: break; case MsgType.Location: break; case MsgType.Link: break; case MsgType.Event: return(new NormalMenuEventMessage(request) { CreateTime = DateTime.Now.Ticks, }); case MsgType.News: case MsgType.Music: break; case MsgType.ShortVideo: break; case MsgType.transfer_customer_service: break; default: break; } } catch (Exception ex) { TxtLogHelper.WriteLog_Day(new TxtLogInfoObject() { LogType = EnumLogType.Error, LogMessage = string.Format("错误信息{0};堆栈信息{1}", ex.Message, ex.StackTrace), }); } finally { TxtLogHelper.WriteDebugLog(bugobj); } return(null); }
public ResponseMessage HandlerRequestMessage() { var request = this.msghander.RequestMessage as RequestTextMessage; var responseText = new ResponseTextMessage(request); Dictionary <string, object> bugobj = new Dictionary <string, object>(); try { bugobj.Add("文字处理!", "文字处理"); if (request != null) { if (!String.IsNullOrEmpty(request.Content)) { if (!string.IsNullOrEmpty(request.FromUserName)) { // 关键字搜索 bugobj.Add("关键字搜索", request.Content); if (request.Content.Contains("笑话")) { List <MQiushibaike> qiushibaikelist = JsonConvert.DeserializeObject <List <MQiushibaike> >(QiushibaikeHelper.GetJokesByRandom()); bugobj.Add("笑话", qiushibaikelist); if (qiushibaikelist != null) { int index = 0; foreach (var item in qiushibaikelist) { if (index == qiushibaikelist.Count - 1) { responseText.Content += string.Format(" {0} ---来源:@糗事百科 {1}", item.JokeContent, item.JokerName); } else { responseText.Content += string.Format(" {0} ---来源:@糗事百科 {1} {2}", item.JokeContent, item.JokerName, "-----我是分割线-----"); } index++; } } else { responseText.Content = "你在逗我?"; } } } else { responseText.Content = "你在逗我?"; } } else { responseText.Content = "你在逗我?"; } } else { responseText.Content = "你在逗我?"; } } catch (Exception ex) { TxtLogHelper.WriteLog_Day(new TxtLogInfoObject() { LogType = EnumLogType.Error, LogMessage = string.Format("错误信息{0};堆栈信息{1}", ex.Message, ex.StackTrace), }); } finally { TxtLogHelper.WriteDebugLog(bugobj); } if (!string.IsNullOrEmpty(this.Message)) { responseText.Content = this.Message; } return(responseText); }