/// <summary> /// 用户关注 /// </summary> /// <param name="sender"></param> /// <returns></returns> public ReplayMsgBase ProcessSubscribeEvent2(GYWx.Receive.EventMsg.SubscribeEvent2 sender) { // LogBase.LogHzLkt.LogInfo(string.Format("更新微信关注状态{0} ", sender.FromUserName), GYLog.DataAccess.Define.ELogType.Info); #region 关注 if (sender.Event == "subscribe") { bool isNewSub = false; string param = ""; UpdateSubLazy(sender.FromUserName, (int)EnumWxSubscribe.Subscribe); #region 扫描二维码关注 if (!string.IsNullOrEmpty(sender.EventKey) && sender.EventKey.StartsWith("qrscene_")) { param = sender.EventKey.Substring("qrscene_".Length); Dictionary <string, object> dict = new Dictionary <string, object>(); dict.Add(Dict_Fct_MemSubscribe.QrScene, param); dict.Add(Dict_Fct_MemSubscribe.WxOpenId, sender.FromUserName); ThreadPool.QueueUserWorkItem(_CreateMemSubscribe, dict); //标记为第一次扫二维码关注 isNewSub = true; ////发送模板 //string templeId = "mAsbg-aH9UpHgVbFUY9TH3PUBZNRd923fcxQVefWU6k"; //string json = null; //string token = GetWXToken(); //var input = new SendTempletInput(); //input.template_id = templeId; //input.touser = sender.FromUserName; //input.topcolor = "#FF0000"; //input.url = "http://weixin.qq.com/download"; //input.data = new PaySuccessedMsgCls() //{ // first = new TempletMsgTextCls() { value = "测试数据微信扫二维码关注", color = "#FF0000" }, // keyword1 = new TempletMsgTextCls() { value = "参数:" + param, color = "#FF0000" }, // keyword2 = new TempletMsgTextCls() { value = "连接Url(测试:<a href=\"www.baidu.com\">测试</a>) :" + input.url, color = "#FF0000" }, // keyword3 = new TempletMsgTextCls() { value = "发送目标微信号:" + sender.FromUserName, color = "#FF0000" }, // remark = new TempletMsgTextCls() { value = "发送时间:" + sender.CreateTime, color = "#FF0000" }, //}; //var result = WxGetMethod.SendTempletMsg(input, token, ref json); } #endregion #region 特殊推送(提货卡用户或者小龙虾分期付款用户) //int id = 0; //string memo = ""; //string msg0Url = ""; //string msg0PicUrl = ""; ////TODO 用户关注 ////string strSendSpecailMsg = LogicWx.GetSubscribeMsg(sender.FromUserName, out id, out memo, out msg0Url, out msg0PicUrl); //string strSendSpecailMsg = ""; //if (!string.IsNullOrEmpty(strSendSpecailMsg) && id > 0) //{ // //小龙虾分期付款客户关注后推送图文消息 // if ("分期付款活动".Equals(memo)) // { // //更新消息状态 // UpdateSendMsgStateLazy(id); // } // else //提货卡用户关注后推送文本消息 // { // //发送文本消息 // Replytext text = new Replytext(); // text.FromUserName = sender.ToUserName; // text.ToUserName = sender.FromUserName; // text.CreateTime = sender.CreateTime; // text.Content = HttpUtility.HtmlEncode(strSendSpecailMsg); // // System.Web.HttpContext.Current.Server.HtmlEncode(strSendSpecailMsg); // //更新消息状态 // UpdateSendMsgStateLazy(id); // return text; // } //} #endregion //获取图文消息 //DataTable dt = DalWXMsgCommon.GetDefaultWXMsg(); DataTable dt = null; //没有图文消息 使用默认的文本推送 if (dt == null || dt.Rows.Count == 0) { #region 默认的文本推送 Replytext text = new Replytext(); text.FromUserName = sender.ToUserName; text.ToUserName = sender.FromUserName; text.CreateTime = sender.CreateTime; string strSend = WxHelloWorld;// ConfigurationManager.AppSettings["WXHellowWorld"]; if (string.IsNullOrEmpty(strSend)) { strSend = @"感谢关注“浩泽净水科技”官方微信,<a href='http://www.oznerwater.com/wapnew/airport/LotteryCoupon.aspx'>点击链接</a>注册成为浩泽会员,万只智能杯任性送"; } else { strSend = strSend.Replace("[", "<").Replace("]", ">"); } text.Content = HttpUtility.HtmlEncode(strSend); //System.Web.HttpContext.Current.Server.HtmlEncode(strSend); // LogBase.LogHzLkt.LogInfo(string.Format("更新微信关注状态{0} ", sender.FromUserName), GYLog.DataAccess.Define.ELogType.Info); return(text); #endregion } else { #region 推送图文消息 WxMsgModel msgModel = GYLib.Base.Utils.ModelUtils <WxMsgModel> .GetModel(dt); if (!string.IsNullOrEmpty(msgModel.Content)) { //int paramucode = ConvertUtils.ConvertToInt(param); //if (paramucode <= 0) //{ // //凭微信openid获取代理商推荐码 // DataTable dtMember = DalMemberCommon.GetMemberInfoByWeiXinOpenId(sender.FromUserName); // if (dtMember != null && dtMember.Rows.Count > 0) // { // paramucode = ConvertUtils.ConvertToInt(dtMember.Rows[0][Dict_Fct_Member.ParentCode]); // } //} ////获取H5渠道商定制化的图片路径 //DataTable dtShare = DalAgentMember.QueryAgentAtvByParentUcodeKeyValue(paramucode, (int)EnumAgentAtvKeyEnum.WXSubMsgFristBgText); //if (dtShare == null || dtShare.Rows.Count == 0) //{ // dtShare = DalAgentMember.QueryAgentAtvByWxOpenIdKeyValue(sender.FromUserName, (int)EnumAgentAtvKeyEnum.WXSubMsgFristBgText); //} ContentModel content = new ContentModel(); XmlHelper.LoadFromXml(msgModel.Content, content); msgModel.ContentModel = content; if (content != null && content.News != null) { List <NewsCls> news = new List <NewsCls>(); for (int index = 0; index < content.News.Length; index++) { NewsModel model = content.News[index]; //如果有强制跳转则以强制跳转为准 if (!string.IsNullOrWhiteSpace(model.ForcedUrl)) { model.Url = model.ForcedUrl; } NewsModel newcls = model; if (!string.IsNullOrWhiteSpace(newcls.Title)) { //图文消息第一个图片的链接 if (index == 0) { //小龙虾分期付款客户的图片和跳转地址 //if ("分期付款活动".Equals(memo)) //{ // newcls.Title = strSendSpecailMsg; // newcls.Url = msg0Url; // newcls.PicUrl = msg0PicUrl; //} //else if (dtShare != null && dtShare.Rows.Count > 0) //H5渠道商定制的图片路径(跳转地址为领取水探头页面.固定) //{ // //string url = ConvertUtils.ConvertToString(dtShare.Rows[0][Dict_Fct_AgentAtv.AtvContent]); // //newcls.PicUrl = ConfigurationManager.AppSettings["WXWebAddress"] + ".." + url; //} //else //{ // newcls.PicUrl = ConfigurationManager.AppSettings["WXWebAddress"] + ".." + newcls.PicUrl; //} } else { newcls.PicUrl = WXWebAddress + ".." + newcls.PicUrl; //ConfigurationManager.AppSettings["WXWebAddress"] + ".." + newcls.PicUrl; } //由于数据关键字 和XML序列化的问题 //移除所有字段的左括号和右括号 //newcls.Title = LogicGrougPickUp.RemoveSqlSpecial(newcls.Title); //newcls.Url = LogicGrougPickUp.RemoveSqlSpecial(newcls.Url); //newcls.PicUrl = LogicGrougPickUp.RemoveSqlSpecial(newcls.PicUrl); //newcls.Description = LogicGrougPickUp.RemoveSqlSpecial(newcls.Description); //newcls.ForcedUrl = LogicGrougPickUp.RemoveSqlSpecial(newcls.ForcedUrl); //对URL加密 newcls.Url = HttpUtility.HtmlEncode(newcls.Url); newcls.PicUrl = HttpUtility.HtmlEncode(newcls.PicUrl); newcls.ForcedUrl = HttpUtility.HtmlEncode(newcls.ForcedUrl); news.Add(newcls); } } if (news.Count > 0) { //推送图文 GYWx.Reply.NormalReply.Replynews arictil = new Replynews(); arictil.FromUserName = sender.ToUserName; arictil.ToUserName = sender.FromUserName; arictil.CreateTime = sender.CreateTime; arictil.MsgType = "news"; arictil.ArticleCount = news.Count + ""; arictil.Articles = new ArticleCls() { item = news.ToArray() }; return(arictil); } } } #endregion } } #endregion #region 取消关注 //取消订阅 if (sender.Event == "unsubscribe") { //int result = DalWXMsgCommon.UpdateMemberSubscribe(sender.FromUserName, (int)EnumWxSubscribe.UnSubscribe); UpdateSubLazy(sender.FromUserName, (int)EnumWxSubscribe.UnSubscribe); //if (result < 0) //{ // LogBase.LogHzLkt.LogInfo(string.Format("更新微信取消关注状态失败{0} {1}", sender.FromUserName, result), GYLog.DataAccess.Define.ELogType.Info); //} //NormalReply.Replytext text = new Replytext(); //text.FromUserName = sender.ToUserName; //text.ToUserName = sender.FromUserName; //text.CreateTime = sender.CreateTime; //text.Content = "Hello World"; //if (!string.IsNullOrEmpty(sender.EventKey) && sender.EventKey.StartsWith("qrscene_")) //{ // string param = sender.EventKey.Substring("qrscene_".Length); // ///扫描二维码关注 // /// // text.Content = "Hello World(取消关注)"; // //发送模板 // string templeId = "mAsbg-aH9UpHgVbFUY9TH3PUBZNRd923fcxQVefWU6k"; // string json = null; // string token = GetWXToken(); // var input = new SendTempletInput(); // input.template_id = templeId; // input.touser = sender.FromUserName; // input.topcolor = "#FF0000"; // input.url = "http://weixin.qq.com/download"; // input.data = new PaySuccessedMsgCls() // { // first = new TempletMsgTextCls() { value = "测试取消关注", color = "#FF0000" }, // keyword1 = new TempletMsgTextCls() { value = "参数:" + param, color = "#FF0000" }, // keyword2 = new TempletMsgTextCls() { value = "连接Url(测试:<a href=\"www.baidu.com\">测试</a>) :" + input.url, color = "#FF0000" }, // keyword3 = new TempletMsgTextCls() { value = "发送目标微信号:" + sender.FromUserName, color = "#FF0000" }, // remark = new TempletMsgTextCls() { value = "发送时间:" + sender.CreateTime, color = "#FF0000" }, // }; // var result = WxGetMethod.SendTempletMsg(input, token, ref json); //} //return text; } #endregion #region 关注后再扫描 //扫描二维码 if (sender.EventKey == "SCAN") { } #endregion return(null); }
/// <summary> /// 用户与菜单交互 /// </summary> /// <param name="sender"></param> /// <returns></returns> public ReplayMsgBase ProcessMenuEvent(GYWx.Receive.EventMsg.MenuEvent sender) { ReplayMsgBase msg = null; //测试 if (sender.Event.ToLower() == "click") { //string json = null; //string token = GetWXToken(); //var input = new ReplyBMsgUserText(); //input.touser = new string[] { sender.FromUserName }; //input.text = new GYWx.Post.JsonModel.Cls.ContentCls() { content = "测试发送模板素材" }; //input.msgtype = "text"; //var result = WxGetMethod.SendBatchMsgByOpenID(input, token, ref json); if (sender.EventKey == "V1001_jbwz") { GYWx.Reply.NormalReply.Replynews arictil = new Replynews(); arictil.FromUserName = sender.ToUserName; arictil.ToUserName = sender.FromUserName; arictil.CreateTime = sender.CreateTime; arictil.MsgType = "news"; arictil.ArticleCount = "4"; arictil.Articles = new ArticleCls() { item = new NewsCls[] { new NewsCls() { Url = "http://www.oznerwater.com/lktnew/wap/wxshareoauth.aspx?gourl=http://www.oznerwater.com/lktnew/wx/wxhtml/A1.html", Title = "我和健康有个约惠", Description = "我和健康有个约惠", PicUrl = "http://www.oznerwater.com/lktnew/upload/wxts/0.jpg" }, new NewsCls() { Url = "http://www.oznerwater.com/lktnew/wap/wxshareoauth.aspx?gourl=http://www.oznerwater.com/lktnew/wx/wxhtml/A2.html", Title = "第一次跟他接吻快亲上去的时候他突然", Description = "", PicUrl = "http://www.oznerwater.com/lktnew/upload/wxts/1.jpg" }, new NewsCls() { Url = "http://www.oznerwater.com/lktnew/wap/wxshareoauth.aspx?gourl=http://www.oznerwater.com/lktnew/wx/wxhtml/A3.html", Title = "彭麻麻最近拍了一个广告片,震惊国人!", Description = "", PicUrl = "http://www.oznerwater.com/lktnew/upload/wxts/2.jpg" }, new NewsCls() { Url = "http://www.oznerwater.com/lktnew/wap/wxshareoauth.aspx?gourl=http://www.oznerwater.com/lktnew/wx/wxhtml/A4.html", Title = "惊呆了!震动是吃哪补哪!养生达人私藏集锦!", Description = "", PicUrl = "http://www.oznerwater.com/lktnew/upload/wxts/3.jpg" } } }; return(arictil); } else { GYWx.Reply.NormalReply.Replytext text = new Replytext(); text.FromUserName = sender.ToUserName; text.ToUserName = sender.FromUserName; text.CreateTime = sender.CreateTime; text.Content = "点击clike测试:"; return(text); } } else { return(msg); } }