Пример #1
0
        public static int LoginSuccess(IWxUsersRepository repository, IWxFriendsRepository wxFriendsRepository,
                                       HttpResponse Response, IAuthCore authcore, string uuid, string tip, ref string url)
        {
            var status = WeiXinHelper.GetLoginStatus(uuid, tip, ref url);

            return(status);
        }
Пример #2
0
 public OpenApiController(IWxUsersRepository wxUsersRepository, IWxFriendsRepository wxFriendsRepository, IRedisHelper redisHelper, IOptions <AppConfig> appconfig)
 {
     _wxUsersRepository   = wxUsersRepository;
     _wxFriendsRepository = wxFriendsRepository;
     _redisHelper         = redisHelper;
     _appconfig           = appconfig;
 }
Пример #3
0
        /// <summary>
        /// 设置备注名称
        /// </summary>
        /// <param name="repository"></param>
        /// <param name="wxHosts"></param>
        /// <param name="wxCookie"></param>
        /// <param name="keys"></param>
        /// <param name="userName"></param>
        /// <param name="remarkName"></param>
        /// <returns></returns>
        public static bool SetRemarkName(IWxFriendsRepository repository, string wxHosts, string wxCookie, PassTicketXmlInfo keys, string userName, string remarkName)
        {
            var status = WeiXinHelper.SetRemarkName(wxHosts, wxCookie, keys, userName, remarkName);

            if (status)
            {
                var users = repository.GetByName(keys.wxuin, userName);
                if (users == null)
                {
                    throw new CustomerException("本地同步失败", -1);
                }
                users.SetRemarkName(repository, remarkName);
            }
            return(status);
        }
Пример #4
0
        public static bool SendMsgByRemarkName(IWxFriendsRepository wxFriendsRepository, IWxUsersRepository wxUsersRepository, IRedisHelper redisHelper,
                                               IOptions <AppConfig> appConfig, WebHookParam webHook)
        {
            AuthCore authCore    = new AuthCore(redisHelper);
            var      username    = authCore.GetUserName(appConfig.Value.UserUin);   //当前登录用户名称
            var      userHosts   = authCore.GetUserHosts(appConfig.Value.UserUin);  //当前登录用户操作域名
            var      userCookies = authCore.GetUserCookie(appConfig.Value.UserUin); //当前登录用户Cookies
            var      userKeys    = authCore.GetUserKeys(appConfig.Value.UserUin);   //当前登录用户秘钥


            var dbWxUser = wxUsersRepository.GetWxUsers(appConfig.Value.UserUin);//当前登录用户

            if (dbWxUser == null)
            {
                throw new CustomerException("未找到登录信息", -2);
            }
            var dbFriends = wxFriendsRepository.GetFriendByName(webHook.actor, dbWxUser.Uin);

            if (dbFriends == null)
            {
                throw new CustomerException("未找到好友信息", -1);                   //好友信息
            }
            return(WeiXinHelper.SendMsg(userHosts, webHook.text, dbFriends.UserName, dbWxUser.UserName, userKeys, userCookies));
        }
Пример #5
0
        /// <summary>
        /// 登录初始化
        /// </summary>
        /// <returns></returns>
        public static void LoginInitialization(IWxUsersRepository repository, IWxFriendsRepository wxFriendsRepository, HttpResponse Response, IAuthCore authcore, string url)
        {
            var wxCookie = String.Empty;
            var keys     = WeiXinHelper.GetUserKeys(url, ref wxCookie);

            //计算域名
            string hosts = url.IndexOf("wx.qq.com") > 0 ? "wx.qq.com" : "wx2.qq.com";

            //获取用户信息
            var userInfo = WeiXinHelper.GetWxUserInfo(hosts, keys);
            //创建用户
            var userModel = WxUsers.SetWxUserInfo(repository, userInfo.User, keys);

            //设置基础操作域名
            userModel.SetWxHosts(hosts);
            //同步好友
            var friends = WeiXinHelper.GetWxFriends(hosts, keys.skey, wxCookie);

            userModel.SyncFriends(wxFriendsRepository, friends);
            //创建状态通知
            WeiXinHelper.StartWxStatusNotify(hosts, wxCookie, keys, userModel.UserName);

            //心跳检测转到前端
            Thread thread = new Thread(m => HeartbeatWxStatus(Response, hosts, wxCookie, keys, userInfo.SyncKey));

            thread.IsBackground = true;
            thread.Start();

            //添加缓存
            AuthCore.SetUin(Response, userModel.Uin);
            authcore.SetUserName(userModel.Uin, userModel.UserName);
            authcore.SetUserHosts(userModel.Uin, hosts);
            authcore.SetUserKeys(userModel.Uin, keys);
            authcore.SetUserCookie(userModel.Uin, wxCookie);
            authcore.SetUserSyncKeys(userModel.Uin, userInfo.SyncKey);
        }
Пример #6
0
 /// <summary>
 /// 同步好友
 /// </summary>
 /// <returns></returns>
 public void SyncFriends(IWxFriendsRepository repository, WxContact wxContact)
 {
     for (int i = 0; i < this.Friends.Count; i++)
     {
         var itemfirend = this.Friends[i];
         #region 查询
         Expression <Func <WxFriendItem, bool> > where = m => true;
         if (!String.IsNullOrEmpty(itemfirend.RemarkName))
         {
             where = m => m.RemarkName.Equals(itemfirend.RemarkName);
         }
         else if (!String.IsNullOrEmpty(itemfirend.NickName))
         {
             where = m => m.NickName.Equals(itemfirend.NickName);
         }
         else
         {
             //TODO 备注和昵称均为空
             continue;
         }
         var Friend = wxContact.MemberList.FirstOrDefault(where.Compile());
         #endregion
         if (Friend == null)
         {
             //微信端删除好友
             this.Friends.Remove(itemfirend);
         }
         else
         {
             //同步好友信息
             itemfirend.UserName   = Friend.UserName;
             itemfirend.StarFriend = Friend.StarFriend;
             itemfirend.Province   = Friend.Province;
             itemfirend.City       = Friend.City;
             itemfirend.Sex        = Friend.Sex;
             itemfirend.HeadImgUrl = Friend.HeadImgUrl;
             itemfirend.Signature  = Friend.Signature;
             itemfirend.NickName   = Friend.NickName;
             itemfirend.RemarkName = Friend.RemarkName;
             wxContact.MemberList.Remove(Friend);
         }
     }
     if (wxContact.MemberList != null)
     {
         //添加好友
         this.Friends.AddRange(wxContact.MemberList.Select(m => new WxFriends
         {
             UserUin     = this.Uin,
             Uin         = m.Uin,
             UserName    = m.UserName,
             StarFriend  = m.StarFriend,
             Province    = m.Province,
             City        = m.City,
             Sex         = m.Sex,
             HeadImgUrl  = m.HeadImgUrl,
             Signature   = m.Signature,
             ContactFlag = m.ContactFlag,
             VerifyFlag  = m.VerifyFlag,
             AttrStatus  = m.AttrStatus,
             NickName    = m.NickName,
             RemarkName  = m.RemarkName,
         }));
     }
 }
Пример #7
0
 public void BindTelephone(IWxFriendsRepository repository, string telephone)
 {
     this.Telephone = telephone;
     repository.Update(this);
 }
Пример #8
0
 /// <summary>
 /// 更换备注名
 /// </summary>
 /// <param name="repository"></param>
 /// <param name="remarkName"></param>
 public void SetRemarkName(IWxFriendsRepository repository, string remarkName)
 {
     this.RemarkName = remarkName;
     repository.Update(this);
 }
Пример #9
0
 public HomeController(IWxFriendsRepository wxFriendsRepository, IQuery <WxFriends> query)
 {
     _wxFriendsRepository = wxFriendsRepository;
     _query = query;
 }
Пример #10
0
 public LoginController(IAuthCore authcore, IWxUsersRepository repository, IWxFriendsRepository wxFriendsRepository)
 {
     _authcore            = authcore;
     _repository          = repository;
     _wxFriendsRepository = wxFriendsRepository;
 }