//处理扫描带参数二维码事件 public virtual void HandlerScan(string eventKey) { var application = new WApplicationInterfaceDAO(requestParams.LoggingSessionInfo); var appEntitys = application.QueryByEntity(new WApplicationInterfaceEntity() { WeiXinID = requestParams.WeixinId }, null); if (appEntitys != null && appEntitys.Length > 0) { var entity = appEntitys.FirstOrDefault(); BaseService.WriteLogWeixin("AppID: " + entity.AppID); BaseService.WriteLogWeixin("AppSecret: " + entity.AppSecret); BaseService.WriteLogWeixin("qrcodeId: " + eventKey); //保存用户信息 // /// <param name="isShow">1: 关注 0: 取消关注</param> //这个里面处理临时二维码的信息的代码(建立员工与会员的上下级关系)** commonService.SaveUserInfo(requestParams.OpenId, requestParams.WeixinId, "1", entity.AppID, entity.AppSecret, eventKey, requestParams.LoggingSessionInfo); #region 微信扫描二维码 回复消息 update by wzq 20140731 var eventsBll = new LEventsBLL(requestParams.LoggingSessionInfo); Loggers.Debug(new DebugLogInfo() { Message = "二维码信息:" + eventKey }); string nodeMsg = string.Empty; foreach (System.Xml.XmlNode item in requestParams.XmlNode.ChildNodes) { nodeMsg += " | " + item.Name + "-" + item.Value; } //加log记录信息看下 2014-11-24 15:57:30 Loggers.Debug(new DebugLogInfo() { Message = "二维码全部信息:" + "~" + requestParams.OpenId + "~" + requestParams.WeixinId + "~" + requestParams.MsgType + "~" + requestParams.XmlNode.ToString() + nodeMsg }); #region 注释备注:扫码时始终会调用保存用户信息接口,这里已经推送了消息 //BaseService.WriteLogWeixin("开始推送消息Wzq"); //处理扫描静态二维码的事件(包含处理上下级关系和推送图文信息) int sendMessageCount = 0; eventsBll.SendQrCodeWxMessage(requestParams.LoggingSessionInfo, requestParams.LoggingSessionInfo.CurrentLoggingManager.Customer_Id, requestParams.WeixinId, eventKey, requestParams.OpenId, this.httpContext, requestParams, out sendMessageCount); //BaseService.WriteLogWeixin("推送消息成功Wzq"); #endregion #endregion } }
//用户取消关注微信号 public override void UserUnSubscribe() { var application = new WApplicationInterfaceDAO(requestParams.LoggingSessionInfo); var appEntitys = application.QueryByEntity(new WApplicationInterfaceEntity() { WeiXinID = requestParams.WeixinId }, null); if (appEntitys != null && appEntitys.Length > 0) { var entity = appEntitys.FirstOrDefault(); BaseService.WriteLogWeixin("AppID: " + entity.AppID); BaseService.WriteLogWeixin("AppSecret: " + entity.AppSecret); //保存用户信息 commonService.SaveUserInfo(requestParams.OpenId, requestParams.WeixinId, "0", entity.AppID, entity.AppSecret, string.Empty, requestParams.LoggingSessionInfo); } }
//用户关注微信号 public override void UserSubscribe() { var application = new WApplicationInterfaceDAO(requestParams.LoggingSessionInfo); var appEntitys = application.QueryByEntity(new WApplicationInterfaceEntity() { WeiXinID = requestParams.WeixinId }, null); if (appEntitys != null && appEntitys.Length > 0) { var entity = appEntitys.FirstOrDefault(); BaseService.WriteLogWeixin("AppID: " + entity.AppID); BaseService.WriteLogWeixin("AppSecret: " + entity.AppSecret); //扫描带参数二维码事件 var eventKey = requestParams.XmlNode.SelectSingleNode("//EventKey"); BaseService.WriteLogWeixin("eventKey: " + eventKey.InnerText); var qrcodeId = string.Empty; if (!string.IsNullOrEmpty(eventKey.InnerText)) { qrcodeId = eventKey.InnerText.Substring(8); } BaseService.WriteLogWeixin("qrcodeId: " + qrcodeId); //保存用户信息 commonService.SaveUserInfo(requestParams.OpenId, requestParams.WeixinId, "1", entity.AppID, entity.AppSecret, qrcodeId, requestParams.LoggingSessionInfo); } //设置关注信息 var modelDAO = new WModelDAO(requestParams.LoggingSessionInfo); var ds = modelDAO.GetMaterialByWeixinId(requestParams.WeixinId); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { string typeId = ds.Tables[0].Rows[0]["MaterialTypeId"].ToString(); //素材类型 string materialId = ds.Tables[0].Rows[0]["MaterialId"].ToString(); //素材ID BaseService.WriteLogWeixin("typeId:" + typeId); BaseService.WriteLogWeixin("materialId:" + materialId); switch (typeId) { case MaterialType.TEXT: //回复文字消息 ReplyText(materialId); break; case MaterialType.IMAGE_TEXT: //回复图文消息 ReplyNews(materialId); break; case MaterialType.OTHER: //后台处理 break; default: break; } } }
//用户关注微信号 public override void UserSubscribe() { var eventsBll = new LEventsBLL(requestParams.LoggingSessionInfo); //设置关注信息 var modelDAO = new WModelDAO(requestParams.LoggingSessionInfo); var ds = new DataSet();// /// <param name="KeyworkType">1=关键字回复 2=关注回复 3=自动回复</param> //优先处理二维码 var qrcodeId = string.Empty; var eventKey = requestParams.XmlNode.SelectSingleNode("//EventKey"); var application = new WApplicationInterfaceDAO(requestParams.LoggingSessionInfo); var appEntitys = application.QueryByEntity(new WApplicationInterfaceEntity() { WeiXinID = requestParams.WeixinId }, null); if (eventKey != null && eventKey.InnerText.Contains("qrscene_"))//如果是二维码的就之返回二维码的 { qrcodeId = eventKey.InnerText.Substring(8); } if (appEntitys != null && appEntitys.Length > 0) { var entity = appEntitys.FirstOrDefault(); BaseService.WriteLogWeixin("AppID: " + entity.AppID); BaseService.WriteLogWeixin("AppSecret: " + entity.AppSecret); //扫描带参数二维码事件 /** * BaseService.WriteLogWeixin("二维码 eventKey: " + eventKey.InnerText); * if (!string.IsNullOrEmpty(eventKey.InnerText))//这里如果是二维码扫锚,就找出了二维码的code,可以在这里推送该二维码对应的图文素材****** * { * qrcodeId = eventKey.InnerText.Substring(8); * //这个地方传得是eventKey.ToString(),,而不是上面做的qrcodeId = eventKey.InnerText.Substring(8),所以不会找到对应的二维码的真正的key,也就不会推送二维码的key对应的图文素材信息 * eventsBll.SendQrCodeWxMessage(requestParams.LoggingSessionInfo, requestParams.LoggingSessionInfo.CurrentLoggingManager.Customer_Id, requestParams.WeixinId, eventKey.ToString(), * requestParams.OpenId, this.httpContext, requestParams); * } **/ //BaseService.WriteLogWeixin("二维码 qrcodeId: " + qrcodeId); ////保存用户信息///// <param name="isShow">1: 关注 0: 取消关注</param> //这个里面处理临时二维码的信息的代码(建立员工与会员的上下级关系)** commonService.SaveUserInfo(requestParams.OpenId, requestParams.WeixinId, "1", entity.AppID, entity.AppSecret, qrcodeId, requestParams.LoggingSessionInfo); } int sendMessageCount = 0; if (eventKey != null && eventKey.InnerText.Contains("qrscene_"))//如果是二维码的就之返回二维码的 { qrcodeId = eventKey.InnerText.Substring(8); //处理扫描静态二维码的事件(包含处理上下级关系和推送图文信息) eventsBll.SendQrCodeWxMessage(requestParams.LoggingSessionInfo, requestParams.LoggingSessionInfo.CurrentLoggingManager.Customer_Id, requestParams.WeixinId, qrcodeId, requestParams.OpenId, this.httpContext, requestParams, out sendMessageCount); //保存用户信息时,有推送消息 //eventsBll.QrCodeHandlerText(qrcodeId, requestParams.LoggingSessionInfo, // requestParams.WeixinId, 4, requestParams.OpenId, httpContext, requestParams); //ds = modelDAO.GetMaterialByWeixinIdJermyn(requestParams.WeixinId, 4); } if (sendMessageCount == 0) //这种情况,就是没有eventKey,或者这个eventkey没有设置对应的关键字回复 { #region 处理关注事件的图文信息 ds = modelDAO.GetMaterialByWeixinIdJermyn(requestParams.WeixinId, 2); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { string typeId = ds.Tables[0].Rows[0]["ReplyType"].ToString(); //素材类型 1=文字2=图片3=图文4=语音5=视频6=其他 string ReplyId = ds.Tables[0].Rows[0]["ReplyId"].ToString(); //素材ID string Text = ds.Tables[0].Rows[0]["text"].ToString(); //内容 BaseService.WriteLogWeixin("自动回复: typeId:" + typeId); BaseService.WriteLogWeixin("自动回复:ReplyId:" + ReplyId); switch (typeId) { case MaterialType.TEXT: //回复文字消息 //ReplyText(materialId); ReplyTextJermyn(Text); break; case MaterialType.IMAGE_TEXT: //回复图文消息 //ReplyNews(materialId); ReplyNewsJermyn(ReplyId, 2, 1); break; case MaterialType.OTHER: //后台处理 break; default: break; } } else { UserSubscribeOld();//老版本的微信关注自动回复 Jermyn20140512 } #endregion } /** * var application = new WApplicationInterfaceDAO(requestParams.LoggingSessionInfo); * var appEntitys = application.QueryByEntity(new WApplicationInterfaceEntity() { WeiXinID = requestParams.WeixinId }, null); * if (appEntitys != null && appEntitys.Length > 0) * { * var entity = appEntitys.FirstOrDefault(); * * BaseService.WriteLogWeixin("AppID: " + entity.AppID); * BaseService.WriteLogWeixin("AppSecret: " + entity.AppSecret); * * //扫描带参数二维码事件 * * BaseService.WriteLogWeixin("二维码 eventKey: " + eventKey.InnerText); * * * if (!string.IsNullOrEmpty(eventKey.InnerText))//这里如果是二维码扫锚,就找出了二维码的code,可以在这里推送该二维码对应的图文素材****** * { * qrcodeId = eventKey.InnerText.Substring(8); * //这个地方传得是eventKey.ToString(),,而不是上面做的qrcodeId = eventKey.InnerText.Substring(8),所以不会找到对应的二维码的真正的key,也就不会推送二维码的key对应的图文素材信息 * eventsBll.SendQrCodeWxMessage(requestParams.LoggingSessionInfo, requestParams.LoggingSessionInfo.CurrentLoggingManager.Customer_Id, requestParams.WeixinId, eventKey.ToString(), * requestParams.OpenId, this.httpContext, requestParams); * } * * * //BaseService.WriteLogWeixin("二维码 qrcodeId: " + qrcodeId); * * ////保存用户信息///// <param name="isShow">1: 关注 0: 取消关注</param> * commonService.SaveUserInfo(requestParams.OpenId, requestParams.WeixinId, "1", entity.AppID, entity.AppSecret, qrcodeId, requestParams.LoggingSessionInfo); * } **/ }
/// <summary> /// 构造函数 /// </summary> public WApplicationInterfaceBLL(LoggingSessionInfo pUserInfo) { this.CurrentUserInfo = pUserInfo; this._currentDAO = new WApplicationInterfaceDAO(pUserInfo); }
public override void UserSubscribe() { BaseService.WriteLogWeixin("贱人贱人"); //设置关注信息 var modelDAO = new WModelDAO(requestParams.LoggingSessionInfo); var ds = modelDAO.GetMaterialByWeixinIdJermyn(requestParams.WeixinId, 2); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { string typeId = ds.Tables[0].Rows[0]["ReplyType"].ToString(); //素材类型 1=文字2=图片3=图文4=语音5=视频6=其他 string ReplyId = ds.Tables[0].Rows[0]["ReplyId"].ToString(); //素材ID string Text = ds.Tables[0].Rows[0]["text"].ToString(); //素材ID BaseService.WriteLogWeixin("typeId:" + typeId); BaseService.WriteLogWeixin("ReplyId:" + ReplyId); switch (typeId) { case MaterialType.TEXT: //回复文字消息 //ReplyText(materialId); ReplyTextJermyn(Text); break; case MaterialType.IMAGE_TEXT: //回复图文消息 //ReplyNews(materialId); ReplyNewsJermyn(ReplyId, 2, 1); break; case MaterialType.OTHER: //后台处理 break; default: break; } } #region Jermyn20140728 订阅号添加获取用户信息 var application = new WApplicationInterfaceDAO(requestParams.LoggingSessionInfo); var appEntitys = application.QueryByEntity(new WApplicationInterfaceEntity() { WeiXinID = requestParams.WeixinId }, null); if (appEntitys != null && appEntitys.Length > 0) { var entity = appEntitys.FirstOrDefault(); BaseService.WriteLogWeixin("AppID: " + entity.AppID); BaseService.WriteLogWeixin("AppSecret: " + entity.AppSecret); //扫描带参数二维码事件 //var eventKey = requestParams.XmlNode.SelectSingleNode("//EventKey"); //BaseService.WriteLogWeixin("eventKey: " + eventKey.InnerText); var qrcodeId = string.Empty; //if (!string.IsNullOrEmpty(eventKey.InnerText)) //{ // qrcodeId = eventKey.InnerText.Substring(8); //} //BaseService.WriteLogWeixin("qrcodeId: " + qrcodeId); //保存用户信息 commonService.SaveUserInfo(requestParams.OpenId, requestParams.WeixinId, "1", entity.AppID, entity.AppSecret, qrcodeId, requestParams.LoggingSessionInfo); BaseService.WriteLogWeixin("推送用户信息到业务系统成功. "); } #endregion }
public VipEntity GetUserIdByOpenId(LoggingSessionInfo loggingSessionInfo, string OpenId) { VipEntity vipInfo = new VipEntity(); try { string vipId = string.Empty; string status = "0"; VipBLL server = new VipBLL(loggingSessionInfo); WXUserInfoBLL wxUserInfoBLL = new WXUserInfoBLL(loggingSessionInfo); //var vipObjs = server.QueryByEntityAbsolute(new VipEntity //{ // WeiXinUserId = OpenId //}, null); var vipObjs = server.QueryByEntity(new VipEntity //先从会员表里取 { WeiXinUserId = OpenId, ClientID = loggingSessionInfo.ClientID }, null); if (vipObjs == null || vipObjs.Length == 0 || vipObjs[0] == null)//找不到会员信息 { //优先从支持多号运营的表中取 var wxUserInfo = wxUserInfoBLL.QueryByEntity(new WXUserInfoEntity() { CustomerID = loggingSessionInfo.ClientID, WeiXinUserID = OpenId }, null).FirstOrDefault(); if (wxUserInfo != null) { var vipEntity = server.QueryByEntity(new VipEntity() { ClientID = loggingSessionInfo.ClientID, UnionID = wxUserInfo.UnionID }, null).FirstOrDefault(); //从会员表里取 if (vipEntity != null) { vipId = vipEntity.VIPID; status = vipEntity.Status.ToString(); vipInfo = vipEntity; } else { vipInfo = null; } } else { //请求获取用户信息 //Jermyn20130911 从总部导入vip信息 bool bReturn = server.GetVipInfoFromApByOpenId(OpenId, null); var vipObjs1 = server.QueryByEntityAbsolute(new VipEntity { WeiXinUserId = OpenId }, null); if (vipObjs1 == null || vipObjs1.Length == 0 || vipObjs1[0] == null) { vipInfo = null; } else { vipId = vipObjs1[0].VIPID; status = vipObjs1[0].Status.ToString(); vipInfo = vipObjs1[0]; } } } else //查到会员信息了 { vipId = vipObjs[0].VIPID; status = vipObjs[0].Status.ToString(); vipInfo = vipObjs[0]; //获取UnionID if (string.IsNullOrEmpty(vipInfo.UnionID)) { var vipService = new VipBLL(loggingSessionInfo); var vipEntity = new VipEntity(); var commonBll = new CommonBLL(); var application = new WApplicationInterfaceDAO(loggingSessionInfo); var appEntity = application.QueryByEntity(new WApplicationInterfaceEntity() { WeiXinID = vipInfo.WeiXin, CustomerId = loggingSessionInfo.ClientID }, null).FirstOrDefault(); if (appEntity != null) { //获取调用微信接口的凭证(普通的获取accestoken的地方) var accessToken = commonBll.GetAccessTokenByCache(appEntity.AppID, appEntity.AppSecret, loggingSessionInfo); //通过openID获取用户信息 // (这种情况下,因为已经有会员信息了,并且已经关注了,才能获取到会员信息) var userInfo = commonBll.GetUserInfo(accessToken.access_token, vipInfo.WeiXinUserId); if (!string.IsNullOrEmpty(userInfo.unionid)) { var vipEntitys = vipService.QueryByEntity(new VipEntity { UnionID = userInfo.unionid, ClientID = loggingSessionInfo.ClientID }, null); if (vipEntitys != null && vipEntitys.Length > 0)//已经存在有UnionID的数据 { var wxUserInfo = wxUserInfoBLL.QueryByEntity(new WXUserInfoEntity() { CustomerID = loggingSessionInfo.ClientID, VipID = vipEntitys[0].VIPID, WeiXinUserID = OpenId, UnionID = userInfo.unionid }, null).FirstOrDefault(); if (wxUserInfo == null) { var wxuiEntity = new WXUserInfoEntity() { WXUserID = Guid.NewGuid(), VipID = vipEntitys[0].VIPID,//vipInfo.VIPID, WeiXin = vipInfo.WeiXin, WeiXinUserID = vipInfo.WeiXinUserId, UnionID = userInfo.unionid, CustomerID = vipInfo.ClientID, CreateBy = "auth", LastUpdateBy = "auth" }; wxUserInfoBLL.Create(wxuiEntity); } //删除冗余vip记录 vipInfo.LastUpdateBy = "auth-delete"; vipService.Delete(vipInfo); } else { //更新微信用户信息 vipInfo.VipName = userInfo.nickname; vipInfo.City = userInfo.city; vipInfo.Gender = Convert.ToInt32(userInfo.sex); vipInfo.HeadImgUrl = userInfo.headimgurl; vipInfo.UnionID = userInfo.unionid; server.Update(vipInfo); } } } } } return(vipInfo); } catch (Exception ex) { Loggers.Debug(new DebugLogInfo() { Message = string.Format("GetUserIdByOpenId用户用户信息出错: {0}", ex.ToString()) }); //Response.Write("GetUserIdByOpenId用户用户信息出错:" + ex.ToString()); return(vipInfo); } }