Ejemplo n.º 1
0
        public ResponseBody <int> PostWXUser(WXUserInfoEntity wxUserInfoEntity)
        {
            var id = _IUserBLL.EditWeixinUser(wxUserInfoEntity);

            return(new ResponseBody <int> {
                Result = id, Code = "", Message = ""
            });
        }
Ejemplo n.º 2
0
        public int gettest()
        {
            var wxUser      = UserHandler.GetUserInfoByopenID("oZ0NuwPJqqT77z68HmkVXjc1g5ns");
            var weixinModel = new WXUserInfoEntity
            {
                from            = "wx",
                headimgurl      = wxUser.headimgurl,
                status          = 1,
                nickname        = wxUser.nickname,
                openid          = "oZ0NuwPJqqT77z68HmkVXjc1g5ns",
                pwd             = "",
                recommendopenid = "",
                subscribetime   = DateTime.Now
            };

            return(_IUserBLL.EditWeixinUser(weixinModel));
        }
Ejemplo n.º 3
0
 private void SaveWXUserToDB(object threadParams)
 {
     lock (thisLock)
     {
         var arrUserName     = threadParams.ToString().Split(',');
         var fromUserName    = arrUserName.Length > 0 ? arrUserName[0] : "";
         var recommendOpenID = arrUserName.Length > 1 ? arrUserName[1] : "";
         var wxUser          = UserHandler.GetUserInfoByopenID(fromUserName);
         var weixinModel     = new WXUserInfoEntity
         {
             from            = "wx",
             headimgurl      = wxUser.headimgurl,
             status          = 1,
             nickname        = wxUser.nickname,
             openid          = fromUserName,
             pwd             = "",
             recommendopenid = recommendOpenID,
             subscribetime   = DateTime.Now
         };
         _IUserBLL.EditWeixinUser(weixinModel);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 /// <param name="pTran">事务实例,可为null,如果为null,则不使用事务来更新</param>
 public void Update(WXUserInfoEntity pEntity, IDbTransaction pTran)
 {
     _currentDAO.Update(pEntity, pTran);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 创建一个新实例
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 public void Create(WXUserInfoEntity pEntity)
 {
     _currentDAO.Create(pEntity);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 分页根据实体条件查询实体
 /// </summary>
 /// <param name="pQueryEntity">以实体形式传入的参数</param>
 /// <param name="pOrderBys">排序组合</param>
 /// <returns>符合条件的实体集</returns>
 public PagedQueryResult <WXUserInfoEntity> PagedQueryByEntity(WXUserInfoEntity pQueryEntity, OrderBy[] pOrderBys, int pPageSize, int pCurrentPageIndex)
 {
     return(_currentDAO.PagedQueryByEntity(pQueryEntity, pOrderBys, pPageSize, pCurrentPageIndex));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 根据实体条件查询实体
 /// </summary>
 /// <param name="pQueryEntity">以实体形式传入的参数</param>
 /// <param name="pOrderBys">排序组合</param>
 /// <returns>符合条件的实体集</returns>
 public WXUserInfoEntity[] QueryByEntity(WXUserInfoEntity pQueryEntity, OrderBy[] pOrderBys)
 {
     return(_currentDAO.QueryByEntity(pQueryEntity, pOrderBys));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="pEntity"></param>
 public void Delete(WXUserInfoEntity pEntity)
 {
     _currentDAO.Delete(pEntity);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 public void Update(WXUserInfoEntity pEntity)
 {
     _currentDAO.Update(pEntity);
 }
Ejemplo n.º 10
0
 public int EditWeixinUser(WXUserInfoEntity wxUserInfoEntity)
 {
     return(_IUserDAL.EditWeixinUser(wxUserInfoEntity));
 }
Ejemplo n.º 11
0
        /// <summary>
        /// 微信post
        /// </summary>
        /// <param name="signature"></param>
        /// <param name="timestamp"></param>
        /// <param name="nonce"></param>
        /// <param name="echostr"></param>
        /// <returns></returns>
        public string post()
        {
            var retXML = string.Empty;
            var xmlDoc = new XmlDocument();

            try
            {
                var postStr = Request.Content.ReadAsStreamAsync().Result;
                xmlDoc.Load(postStr);
                LogHelper.Info(this, "微信参数:" + xmlDoc.OuterXml);

                var msgType      = ReadElementFromWXxml(xmlDoc, "MsgType");
                var toUserName   = ReadElementFromWXxml(xmlDoc, "ToUserName");
                var fromUserName = ReadElementFromWXxml(xmlDoc, "FromUserName");

                switch (msgType.ToLower())
                {
                case "event":     //事件
                    //菜单KEY
                    var eventType = ReadElementFromWXxml(xmlDoc, "Event");
                    switch (eventType.ToLower())
                    {
                    case "subscribe":
                        //存入数据库
                        var recommendOpenID = string.Empty;
                        var menuKey         = ReadElementFromWXxml(xmlDoc, "EventKey");
                        if (!string.IsNullOrEmpty(menuKey))
                        {
                            recommendOpenID = menuKey.Replace("qrscene_", "");
                        }
                        //var wxUser = UserHandler.GetUserInfoByopenID(fromUserName);
                        //var weixinModel = new WXUserInfoEntity
                        //{
                        //    from = "wx",
                        //    headimgurl = wxUser.headimgurl,
                        //    status = 1,
                        //    nickname = wxUser.nickname,
                        //    openid = fromUserName,
                        //    pwd = "",
                        //    recommendopenid = recommendOpenID,
                        //    subscribetime = DateTime.Now
                        //};
                        //_IUserBLL.EditWeixinUser(weixinModel);
                        var    threadParams = fromUserName + "," + recommendOpenID;
                        Thread thread       = new Thread(new ParameterizedThreadStart(SaveWXUserToDB)); //创建一个线程
                        thread.Start(threadParams);                                                     //开始一个线程
                        //推送消息
                        retXML = ReturnTextXML(toUserName, fromUserName, "欢迎关注公众号!");
                        break;

                    case "unsubscribe":
                        var un_weixinModel = new WXUserInfoEntity
                        {
                            from            = "wx",
                            headimgurl      = "",
                            status          = 0,
                            nickname        = "",
                            openid          = fromUserName,
                            pwd             = "",
                            recommendopenid = "",
                            unsubscribetime = DateTime.Now
                        };
                        _IUserBLL.EditWeixinUser(un_weixinModel);
                        //修改数据库
                        break;

                    case "click":
                        //修改数据库
                        break;

                    case "location":
                        //修改数据库
                        var latitude  = xmlDoc.SelectSingleNode("/xml/Latitude");
                        var longitude = xmlDoc.SelectSingleNode("/xml/Longitude");
                        //var baiduLatLng = BaiDuGeoCoder.GetAddressByLocation(lat, lng);
                        //if (baiduLatLng != null && baiduLatLng.addressComponent != null)
                        //{
                        //    Session["currentCity"] = baiduLatLng.addressComponent.city;
                        //}
                        break;
                    }
                    break;
                }

                return(retXML);
            }
            catch (Exception ex)
            {
                LogHelper.Error(this, "微信api出现错误!" + ex.Message);
                return("");
            }
        }
Ejemplo n.º 12
0
        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);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 增加微信会员
        /// </summary>
        /// <param name="wxUserInfoEntity"></param>
        /// <returns>返回会员id</returns>
        public int EditWeixinUser(WXUserInfoEntity wxUserInfoEntity)
        {
            using (var db = new LTHWMysqlModel())
            {
                LogHelper.Info(this, "编辑微信会员!");
                int res  = 0;
                var tran = db.Database.BeginTransaction();  //开启事务
                try
                {
                    var t_member = db.sline_member_third.FirstOrDefault(m => m.openid == wxUserInfoEntity.openid);
                    if (t_member != null && t_member.openid == wxUserInfoEntity.openid)
                    {//已添加到数据库
                        t_member.headimgurl = wxUserInfoEntity.headimgurl;
                        t_member.status     = wxUserInfoEntity.status;
                        if (t_member.status == 1)
                        {//关注时修改
                            t_member.nickname      = wxUserInfoEntity.nickname;
                            t_member.headimgurl    = wxUserInfoEntity.headimgurl;
                            t_member.subscribetime = wxUserInfoEntity.subscribetime;

                            LogHelper.Info(this, "微信会员重新关注!");
                        }
                        else
                        {//取消关注时修改
                            t_member.unsubscribetime = wxUserInfoEntity.unsubscribetime;

                            LogHelper.Info(this, "微信会员取消关注!");
                        }

                        db.SaveChanges();
                    }
                    else
                    {
                        if (wxUserInfoEntity.status == 0)
                        {//如果没加入到数据库,并且是取消关注时,直接返回
                            return(1);
                        }

                        var member = new sline_member
                        {
                            nickname  = wxUserInfoEntity.nickname,
                            pwd       = wxUserInfoEntity.pwd,
                            connectid = wxUserInfoEntity.openid,
                            from      = string.IsNullOrEmpty(wxUserInfoEntity.from) ? "wx" : wxUserInfoEntity.from,//wx
                        };
                        if (!string.IsNullOrEmpty(wxUserInfoEntity.recommendopenid))
                        {//有推荐人时,添加推荐人
                            var pusers = from u in db.sline_member
                                         from t in db.sline_member_third
                                         where u.mid == t.mid && t.openid == wxUserInfoEntity.recommendopenid
                                         select u;
                            var puser = pusers.FirstOrDefault();
                            if (puser != null)
                            {
                                member.pid = puser.mid.ToString() + (string.IsNullOrEmpty(puser.pid) ? "" : "," + puser.pid);
                            }
                        }

                        db.sline_member.Add(member);
                        db.SaveChanges();
                        res = member.mid;

                        var member_third = new sline_member_third
                        {
                            mid           = res,
                            from          = string.IsNullOrEmpty(wxUserInfoEntity.from) ? "wx" : wxUserInfoEntity.from,//wx
                            nickname      = wxUserInfoEntity.nickname,
                            openid        = wxUserInfoEntity.openid,
                            headimgurl    = wxUserInfoEntity.headimgurl,
                            status        = wxUserInfoEntity.status,
                            subscribetime = wxUserInfoEntity.subscribetime
                        };

                        db.sline_member_third.Add(member_third);
                        db.SaveChanges();

                        LogHelper.Info(this, "增加微信会员!");
                    }

                    tran.Commit();  //必须调用Commit(),不然数据不会保存
                }
                catch (Exception ex)
                {
                    tran.Rollback();    //出错就回滚
                    res = 0;
                    LogHelper.Error(this, ex.Message);
                }
                LogHelper.Info(this, "结束编辑微信会员!");
                return(res);
            }
        }