/// <summary> /// 菜单点击事件 /// </summary> /// <param name="requestMessage"></param> /// <returns></returns> public override IResponseMessageBase OnEvent_ClickRequest(RequestMessageEvent_Click requestMessage) { IResponseMessageBase reponseMessage = null; #region 注释掉 ////菜单点击,需要跟创建菜单时的Key匹配 //switch (requestMessage.EventKey) //{ // case "OneClick": // { // var strongResponseMessage = CreateResponseMessage<ResponseMessageText>(); // reponseMessage = strongResponseMessage; // strongResponseMessage.Content = "您点击了底部按钮。\r\n为了测试微信软件换行bug的应对措施,这里做了一个——\r\n换行"; // } // break; // case "SubClickRoot_Text": // { // var strongResponseMessage = CreateResponseMessage<ResponseMessageText>(); // reponseMessage = strongResponseMessage; // strongResponseMessage.Content = "您点击了子菜单按钮。"; // } // break; // case "SubClickRoot_News": // { // var strongResponseMessage = CreateResponseMessage<ResponseMessageNews>(); // reponseMessage = strongResponseMessage; // strongResponseMessage.Articles.Add(new Article() // { // Title = "您点击了子菜单图文按钮", // Description = "您点击了子菜单图文按钮,这是一条图文信息。", // PicUrl = "http://weixin.senparc.com/Images/qrcode.jpg", // Url = "http://weixin.senparc.com" // }); // } // break; // case "SubClickRoot_Music": // { // var strongResponseMessage = CreateResponseMessage<ResponseMessageMusic>(); // reponseMessage = strongResponseMessage; // strongResponseMessage.Music.MusicUrl = "http://weixin.senparc.com/Content/music1.mp3"; // } // break; // case "SubClickRoot_Agent"://代理消息 // { // //获取返回的XML // DateTime dt1 = DateTime.Now; // reponseMessage = MessageAgent.RequestResponseMessage(this, agentUrl, agentToken, RequestDocument.ToString()); // //上面的方法也可以使用扩展方法:this.RequestResponseMessage(this,agentUrl, agentToken, RequestDocument.ToString()); // DateTime dt2 = DateTime.Now; // if (reponseMessage is ResponseMessageNews) // { // (reponseMessage as ResponseMessageNews) // .Articles[0] // .Description += string.Format("\r\n\r\n代理过程总耗时:{0}毫秒", (dt2 - dt1).Milliseconds); // } // } // break; // case "Member"://托管代理会员信息 // { // //原始方法为:MessageAgent.RequestXml(this,agentUrl, agentToken, RequestDocument.ToString());//获取返回的XML // reponseMessage = this.RequestResponseMessage(agentUrl, agentToken, RequestDocument.ToString()); // } // break; // case "OAuth"://OAuth授权测试 // { // var strongResponseMessage = CreateResponseMessage<ResponseMessageNews>(); // strongResponseMessage.Articles.Add(new Article() // { // Title = "OAuth2.0测试", // Description = "点击【查看全文】进入授权页面。\r\n注意:此页面仅供测试(是专门的一个临时测试账号的授权,并非Senparc.Weixin.MP SDK官方账号,所以如果授权后出现错误页面数正常情况),测试号随时可能过期。请将此DEMO部署到您自己的服务器上,并使用自己的appid和secret。", // Url = "http://weixin.senparc.com/oauth2", // PicUrl = "http://weixin.senparc.com/Images/qrcode.jpg" // }); // reponseMessage = strongResponseMessage; // } // break; //} #endregion string keywords = requestMessage.EventKey; int apiid = wxcomm.getApiid(); string EventName = ""; if (requestMessage.Event.ToString().Trim() != "") { EventName = requestMessage.Event.ToString(); } else if (requestMessage.EventKey != null) { EventName += requestMessage.EventKey.ToString(); } if (!wxcomm.ExistApiidAndWxId(apiid, requestMessage.ToUserName)) { //验证接收方是否为我们系统配置的帐号,即验证微帐号与微信原始帐号id是否一致,如果不一致,说明【1】配置错误,【2】数据来源有问题 DAL.wxResponseBaseMgr.Add(apiid, requestMessage.FromUserName, requestMessage.MsgType.ToString(), EventName, "none", "未取到关键词对应的数据", requestMessage.ToUserName, "sdf", "dsf"); return(wxcomm.GetResponseMessageTxtByContent(requestMessage, "验证微帐号与微信原始帐号id不一致,可能原因【1】系统配置错误,【2】非法的数据来源有问题", apiid)); } int responseType = 0; string modelFunctionName = ""; int modelFunctionId = 0; int rid = rBll.GetRuleIdByKeyWords(apiid, keywords, out responseType, out modelFunctionName, out modelFunctionId); if (rid <= 0 || responseType <= 0) { // 2014-9-18 暂时性功能 针对ID为 gh_04bf23f25940的平台客户 保存发送者的ID 及 生成抽奖序号 并保存。 if (requestMessage.ToUserName == "gh_c80ca634fa2a" && requestMessage.EventKey == "wdsluckdraw20140920") { //发送纯文字 reponseMessage = wxcomm.GetResponseMessageTxt(requestMessage, apiid); return(reponseMessage); } else { // 2014-9-18原功能 DAL.wxResponseBaseMgr.Add(apiid, requestMessage.FromUserName, requestMessage.MsgType.ToString(), EventName, "none", "未取到关键词对应的数据", requestMessage.ToUserName, "sdf", "sd"); return(wxcomm.GetResponseMessageTxtByContent(requestMessage, "", apiid)); } } if (modelFunctionId > 0) { //模块功能回复 return(wxcomm.GetModuleResponse(requestMessage, modelFunctionName, modelFunctionId, apiid)); } switch (responseType) { case 1: //发送纯文字 reponseMessage = wxcomm.GetResponseMessageTxt(requestMessage, rid, apiid); break; case 2: //发送多图文 reponseMessage = wxcomm.GetResponseMessageNews(requestMessage, rid, apiid); break; case 3: //发送语音 reponseMessage = wxcomm.GetResponseMessageeMusic(requestMessage, rid, apiid); break; default: break; } return(reponseMessage); }
/// <summary> /// 菜单点击事件 /// </summary> /// <param name="requestMessage"></param> /// <returns></returns> public override IResponseMessageBase OnEvent_ClickRequest(RequestMessageEvent_Click requestMessage) { IResponseMessageBase reponseMessage = null; #region 注释掉 ////菜单点击,需要跟创建菜单时的Key匹配 //switch (requestMessage.EventKey) //{ // case "OneClick": // { // var strongResponseMessage = CreateResponseMessage<ResponseMessageText>(); // reponseMessage = strongResponseMessage; // strongResponseMessage.Content = "您点击了底部按钮。\r\n为了测试微信软件换行bug的应对措施,这里做了一个——\r\n换行"; // } // break; // case "SubClickRoot_Text": // { // var strongResponseMessage = CreateResponseMessage<ResponseMessageText>(); // reponseMessage = strongResponseMessage; // strongResponseMessage.Content = "您点击了子菜单按钮。"; // } // break; // case "SubClickRoot_News": // { // var strongResponseMessage = CreateResponseMessage<ResponseMessageNews>(); // reponseMessage = strongResponseMessage; // strongResponseMessage.Articles.Add(new Article() // { // Title = "您点击了子菜单图文按钮", // Description = "您点击了子菜单图文按钮,这是一条图文信息。", // PicUrl = "http://weixin.senparc.com/Images/qrcode.jpg", // Url = "http://weixin.senparc.com" // }); // } // break; // case "SubClickRoot_Music": // { // var strongResponseMessage = CreateResponseMessage<ResponseMessageMusic>(); // reponseMessage = strongResponseMessage; // strongResponseMessage.Music.MusicUrl = "http://weixin.senparc.com/Content/music1.mp3"; // } // break; // case "SubClickRoot_Agent"://代理消息 // { // //获取返回的XML // DateTime dt1 = DateTime.Now; // reponseMessage = MessageAgent.RequestResponseMessage(this, agentUrl, agentToken, RequestDocument.ToString()); // //上面的方法也可以使用扩展方法:this.RequestResponseMessage(this,agentUrl, agentToken, RequestDocument.ToString()); // DateTime dt2 = DateTime.Now; // if (reponseMessage is ResponseMessageNews) // { // (reponseMessage as ResponseMessageNews) // .Articles[0] // .Description += string.Format("\r\n\r\n代理过程总耗时:{0}毫秒", (dt2 - dt1).Milliseconds); // } // } // break; // case "Member"://托管代理会员信息 // { // //原始方法为:MessageAgent.RequestXml(this,agentUrl, agentToken, RequestDocument.ToString());//获取返回的XML // reponseMessage = this.RequestResponseMessage(agentUrl, agentToken, RequestDocument.ToString()); // } // break; // case "OAuth"://OAuth授权测试 // { // var strongResponseMessage = CreateResponseMessage<ResponseMessageNews>(); // strongResponseMessage.Articles.Add(new Article() // { // Title = "OAuth2.0测试", // Description = "点击【查看全文】进入授权页面。\r\n注意:此页面仅供测试(是专门的一个临时测试账号的授权,并非OneGulp.WeChat.MP SDK官方账号,所以如果授权后出现错误页面数正常情况),测试号随时可能过期。请将此DEMO部署到您自己的服务器上,并使用自己的appid和secret。", // Url = "http://weixin.senparc.com/oauth2", // PicUrl = "http://weixin.senparc.com/Images/qrcode.jpg" // }); // reponseMessage = strongResponseMessage; // } // break; //} #endregion string keywords = requestMessage.EventKey; int apiid = wxcomm.getApiid(); string EventName = ""; if (requestMessage.Event.ToString().Trim() != "") { EventName = requestMessage.Event.ToString(); } else if (requestMessage.EventKey != null) { EventName += requestMessage.EventKey.ToString(); } if (!wxcomm.ExistApiidAndWxId(apiid, requestMessage.ToUserName)) { //验证接收方是否为我们系统配置的帐号,即验证微帐号与微信原始帐号id是否一致,如果不一致,说明【1】配置错误,【2】数据来源有问题 DAL.wxResponseBaseMgr.Add(apiid, requestMessage.FromUserName, requestMessage.MsgType.ToString(), EventName, "none", "未取到关键词对应的数据", requestMessage.ToUserName); return(wxcomm.GetResponseMessageTxtByContent(requestMessage, "验证微帐号与微信原始帐号id不一致,可能原因【1】系统配置错误,【2】非法的数据来源有问题", apiid, "系统错误提醒")); } bool isExist = wxcomm.wxCodeLegal(apiid); if (!isExist) { DAL.wxResponseBaseMgr.Add(apiid, requestMessage.FromUserName, requestMessage.MsgType.ToString(), EventName, "none", "账号已过期或已被禁用", requestMessage.ToUserName); return(wxcomm.GetResponseMessageTxtByContent(requestMessage, "账号已过期或已被禁用!", apiid, "系统错误提醒")); } //------关键词钻取 微拍的文字提示 begin------- if (keywords == "人工客服" || keywords == "员工客服") { return(this.CreateResponseMessage <ResponseMessageTransfer_Customer_Service>()); } string fStr = FilterTxtRequest(apiid, keywords, requestMessage.FromUserName); if (fStr.Trim() != "") { DAL.wxResponseBaseMgr.Add(apiid, requestMessage.FromUserName, requestMessage.MsgType.ToString(), EventName, "none", fStr, requestMessage.ToUserName); return(wxcomm.GetResponseMessageTxtByContent(requestMessage, fStr, apiid, keywords)); } //------关键词钻取 微拍的文字提示 end- ------- int responseType = 0; string modelFunctionName = ""; int modelFunctionId = 0; int rid = rBll.GetRuleIdByKeyWords(apiid, keywords, out responseType, out modelFunctionName, out modelFunctionId); if (rid <= 0 || responseType <= 0) { DAL.wxResponseBaseMgr.Add(apiid, requestMessage.FromUserName, requestMessage.MsgType.ToString(), EventName, "none", "未取到关键词对应的数据", requestMessage.ToUserName); return(wxcomm.GetResponseMessageTxtByContent(requestMessage, "未找到对应的内容", apiid, "未取到关键词对应的数据")); } if (modelFunctionId > 0) { //模块功能回复 return(wxcomm.GetModuleResponse(requestMessage, modelFunctionName, modelFunctionId, apiid)); } switch (responseType) { case 1: //发送纯文字 reponseMessage = wxcomm.GetResponseMessageTxt(requestMessage, rid, apiid, keywords); break; case 2: //发送多图文 reponseMessage = wxcomm.GetResponseMessageNews(requestMessage, rid, apiid, keywords); break; case 3: //发送语音 reponseMessage = wxcomm.GetResponseMessageeMusic(requestMessage, rid, apiid, keywords); break; default: break; } return(reponseMessage); }