Esempio n. 1
0
        /**
         * {@inheritDoc}
         *
         * 登录接口
         */
        public AbstractActionFuture login(QQStatus status, QQActionListener.OnActionEvent listener)
        {
            //检查客户端状态,是否允许登陆
            if (session.getState() == QQWpfApplication1.action.QQSession.State.ONLINE)
            {
                throw new ApplicationException("client is aready online !!!");
            }

            getAccount().setStatus(status);
            session.setState(QQSession.State.LOGINING);
            ProcModule procModule = (ProcModule)getModule(AbstractModule.Type.PROC);

            return(procModule.login(listener));
        }
Esempio n. 2
0
        /** {@inheritDoc} */
        public override void onHttpStatusOK(QQHttpResponse response)
        {
            //{"retcode":0,"result":{"uin":236557647,"cip":1991953329,"index":1075,"port":51494,"status":"online","vfwebqq":"41778677efd86bae2ed575eea02349046a36f3f53298a34b97d75297ec1e67f6ee5226429daa6aa7","psessionid":"8368046764001d636f6e6e7365727665725f77656271714031302e3133332e342e31373200005b9200000549016e04004f95190e6d0000000a4052347371696a62724f6d0000002841778677efd86bae2ed575eea02349046a36f3f53298a34b97d75297ec1e67f6ee5226429daa6aa7","user_state":0,"f":0}}
            JSONObject json    = new JSONObject(new JSONTokener(new StringReader(response.getResponseMessage())));
            QQSession  session = getContext().getSession();
            QQAccount  account = (QQAccount)getContext().getAccount();

            if (json.getInt("retcode") == 0)
            {
                JSONObject ret = json.getJSONObject("result");
                account.setUin(ret.getLong("uin"));
                account.setQQ(ret.getLong("uin"));
                session.setSessionId(ret.getString("psessionid"));
                session.setVfwebqq(ret.getString("vfwebqq"));
                account.setStatus(QQStatus.ONLINE);
                session.setState(QQSession.State.ONLINE);
                session.setIndex(ret.getInt("index"));
                session.setPort(ret.getInt("port"));
                notifyActionEvent(QQActionEvent.Type.EVT_OK, null);
            }
            else
            {
                notifyActionEvent(QQActionEvent.Type.EVT_ERROR, new QQException(QQWpfApplication1.action.QQException.QQErrorCode.INVALID_RESPONSE));            //TODO ..
            }
        }
Esempio n. 3
0
        /**
         * <p>doPollMsg.</p>
         */
        public void doPollMsg()
        {
            LoginModule login = (LoginModule)getContext().getModule(AbstractModule.Type.LOGIN);

            login.pollMsg(delegate(QQActionEvent evt) {
                // 回调通知事件函数
                if (evt.getType() == QQActionEvent.Type.EVT_OK)
                {
                    List <QQNotifyEvent> evts = (List <QQNotifyEvent>)evt.getTarget();
                    foreach (QQNotifyEvent e in evts)
                    {
                        getContext().fireNotify(e);
                    }

                    // 准备提交下次poll请求
                    QQSession session = getContext().getSession();
                    if (session.getState() == QQSession.State.ONLINE)
                    {
                        doPollMsg();
                    }
                    else if (session.getState() != QQSession.State.KICKED)
                    {
                        relogin();
                    }
                }
                else if (evt.getType() == QQActionEvent.Type.EVT_ERROR)
                {
                    QQSession session = getContext().getSession();
                    QQAccount account = (QQAccount)getContext().getAccount();
                    session.setState(QQSession.State.OFFLINE);
                    account.setStatus(QQStatus.OFFLINE);
                    //因为自带了错误重试机制,如果出现了错误回调,表明已经超时多次均失败,这里直接返回网络错误的异常
                    QQException ex = (QQException)evt.getTarget();
                    QQWpfApplication1.action.QQException.QQErrorCode code = ex.getError();
                    if (code == QQWpfApplication1.action.QQException.QQErrorCode.INVALID_LOGIN_AUTH)
                    {
                        relogin();
                    }
                    else if (code == QQWpfApplication1.action.QQException.QQErrorCode.IO_ERROR || code == QQWpfApplication1.action.QQException.QQErrorCode.IO_TIMEOUT)
                    {
                        //粗线了IO异常,直接报网络错误
                        getContext().fireNotify(new QQNotifyEvent(QQNotifyEvent.Type.NET_ERROR, ex));
                    }
                    else
                    {
                        relogin();
                        doPollMsg();
                    }
                }
                else if (evt.getType() == QQActionEvent.Type.EVT_RETRY)
                {
                }
            });
        }