예제 #1
0
        public static bool CheckStatus(HttpResponse httpResponse, string wxHosts, string wxCookie, PassTicketXmlInfo keys, SyncKey syncKey)
        {
            var status = WeiXinHelper.GetWxStatus(wxHosts, wxCookie, keys, syncKey);

            if (!status)
            {
                AuthCore.DeleteUin(httpResponse);
                throw new CustomerException("登录过期,请重新登录", -2);
            }
            return(status);
        }
예제 #2
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));
        }
예제 #3
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);
        }