Exemplo n.º 1
0
        private void doWebLogin(String verifyCode, AbstractActionFuture future)
        {
            LoginModule login   = (LoginModule)getContext().getModule(AbstractModule.Type.LOGIN);
            QQAccount   account = (QQAccount)getContext().getAccount();

            login.webLogin(account.getUsername(), account.getPassword(),
                           account.getUin(), verifyCode, delegate(QQActionEvent evt) {
                if (evt.getType() == QQActionEvent.Type.EVT_OK)
                {
                    doCheckLoginSig((String)evt.getTarget(), future);
                }
                else if (evt.getType() == QQActionEvent.Type.EVT_ERROR)
                {
                    QQException ex = (QQException)(evt.getTarget());
                    if (ex.getError() == QQWpfApplication1.action.QQException.QQErrorCode.WRONG_CAPTCHA)
                    {
                        doGetVerify(ex.Message, future);
                    }
                    else
                    {
                        future.notifyActionEvent(
                            QQActionEvent.Type.EVT_ERROR,
                            (QQException)evt.getTarget());
                    }
                }
            });
        }
Exemplo n.º 2
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)
                {
                }
            });
        }
Exemplo n.º 3
0
        /** {@inheritDoc} */
        public override void onHttpStatusOK(QQHttpResponse response)
        {
            QQStore store = getContext().getStore();
            List <QQNotifyEvent> notifyEvents = new List <QQNotifyEvent>();
            JSONObject           json         = new JSONObject(new JSONTokener(new StringReader(response.getResponseString())));
            int retcode = json.getInt("retcode");

            if (retcode == 0)
            {
                // 有可能为 {"retcode"in0,"result"in"ok"}
                if (!json.isNull("result") && json.get("result") is JSONArray)
                {
                    JSONArray results = json.getJSONArray("result");
                    // 消息下载来的列表中是倒过来的,那我直接倒过来取,编位回来
                    for (int i = results.length() - 1; i >= 0; i--)
                    {
                        JSONObject poll     = results.getJSONObject(i);
                        String     pollType = poll.getString("poll_type");
                        JSONObject pollData = poll.getJSONObject("value");
                        if (pollType.Equals("input_notify"))
                        {
                            long    fromUin = pollData.getLong("from_uin");
                            QQBuddy buddy   = store.getBuddyByUin(fromUin);
                            notifyEvents.Add(new QQNotifyEvent(QQNotifyEvent.Type.BUDDY_INPUT, buddy));
                        }
                        else if (pollType.Equals("message"))
                        {
                            // 好友消息
                            notifyEvents.Add(processBuddyMsg(pollData));
                        }
                        else if (pollType.Equals("group_message"))
                        {
                            // 群消息
                            // 被管理员禁言10分钟{"retcode"in0,"result"in[{"poll_type"in"group_message","value"in{"msg_id"in20986,"from_uin"in848492696,"to_uin"in1002053815,"msg_id2"in128032,"msg_type"in43,"reply_ip"in176756755,"group_code"in2227416282,"send_uin"in1900986400,"seq"in221,"time"in1419225537,"info_seq"in126658727,"content"in[["font",{"size"in10,"color"in"000000","style"in[0,0,0],"name"in"\u5B8B\u4F53"}],"\u674E\u519B(1002053815) \u88AB\u7BA1\u7406\u5458\u7981\u8A0010\u5206\u949F "]}}]}
                            // 被管理员禁言1小时
                            // {"retcode"in0,"result"in[{"poll_type"in"group_message","value"in{"msg_id"in49336,"from_uin"in848492696,"to_uin"in1002053815,"msg_id2"in198014,"msg_type"in43,"reply_ip"in176756884,"group_code"in2227416282,"send_uin"in1900986400,"seq"in224,"time"in1419225732,"info_seq"in126658727,"content"in[["font",{"size"in10,"color"in"000000","style"in[0,0,0],"name"in"\u5B8B\u4F53"}],"\u674E\u519B(1002053815) \u88AB\u7BA1\u7406\u5458\u7981\u8A001\u5C0F\u65F6 "]}}]}
                            // 被管理员禁言解除
                            // {"retcode"in0,"result"in[{"poll_type"in"group_message","value"in{"msg_id"in60841,"from_uin"in848492696,"to_uin"in1002053815,"msg_id2"in340248,"msg_type"in43,"reply_ip"in176498277,"group_code"in2227416282,"send_uin"in1900986400,"seq"in223,"time"in1419225681,"info_seq"in126658727,"content"in[["font",{"size"in10,"color"in"000000","style"in[0,0,0],"name"in"\u5B8B\u4F53"}],"\u674E\u519B(1002053815) \u88AB\u7BA1\u7406\u5458\u89E3\u9664\u7981\u8A00 "]}}]}
                            // 群单纯图片消息
                            // {"retcode"in0,"result"in[{"poll_type"in"group_message","value"in{"msg_id"in14154,"from_uin"in848492696,"to_uin"in1002053815,"msg_id2"in483355,"msg_type"in43,"reply_ip"in176489607,"group_code"in2227416282,"send_uin"in2388435354,"seq"in226,"time"in1419225894,"info_seq"in126658727,"content"in[["font",{"size"in10,"color"in"000000","style"in[0,0,0],"name"in"\u5FAE\u8F6F\u96C5\u9ED1"}],["cface",{"name"in"{99820253-D7C7-8EDC-3F1E-53B08AE5C390}.jpg","file_id"in2610173877,"key"in"                ","server"in"183.60.50.34in80"}]," "]}}]}
                            // 群文字与表情消息
                            // {"retcode"in0,"result"in[{"poll_type"in"group_message","value"in{"msg_id"in14155,"from_uin"in848492696,"to_uin"in1002053815,"msg_id2"in279741,"msg_type"in43,"reply_ip"in176886363,"group_code"in2227416282,"send_uin"in2388435354,"seq"in227,"time"in1419226485,"info_seq"in126658727,"content"in[["font",{"size"in10,"color"in"000000","style"in[0,0,0],"name"in"\u5FAE\u8F6F\u96C5\u9ED1"}],"aa",["face",14]," "]}}]}
                            // 超级表情
                            // {"retcode"in0,"result"in[{"poll_type"in"group_message","value"in{"msg_id"in57841,"from_uin"in2901943685,"to_uin"in1002053815,"msg_id2"in683745,"msg_type"in32,"reply_ip"in179898740,"group_code"in1226655265,"t_gcode"in260334785,"send_uin"in569398403,"seq"in19,"time"in1425015233,"info_seq"in37,"content"in[""]}}]}

                            notifyEvents.Add(processGroupMsg(pollData));
                        }
                        else if (pollType.Equals("discu_message"))
                        {
                            // 讨论组消息
                            notifyEvents.Add(processDiscuzMsg(pollData));
                        }
                        else if (pollType.Equals("sess_message"))
                        {
                            // 临时会话消息
                            notifyEvents.Add(processSessionMsg(pollData));
                        }
                        else if (pollType.Equals("shake_message"))
                        {
                            // 窗口震动
                            long   fromUin = pollData.getLong("from_uin");
                            QQUser user    = getContext().getStore().getBuddyByUin(fromUin);
                            notifyEvents.Add(new QQNotifyEvent(QQNotifyEvent.Type.SHAKE_WINDOW, user));
                        }
                        else if (pollType.Equals("kick_message"))
                        {
                            // 被踢下线
                            getContext().getAccount().setStatus(QQStatus.OFFLINE);
                            getContext().getSession().setState(QQSession.State.KICKED);
                            notifyEvents.Add(new QQNotifyEvent(QQNotifyEvent.Type.KICK_OFFLINE, pollData.getString("reason")));
                        }
                        else if (pollType.Equals("buddies_status_change"))
                        {
                            notifyEvents.Add(processBuddyStatusChange(pollData));
                        }
                        else if (pollType.Equals("group_web_message"))
                        {
                            // 点歌
                            // {"retcode"in0,"result"in[{"poll_type"in"group_web_message","value"in{"msg_id"in65528,"from_uin"in2901943685,"to_uin"in1002053815,"msg_id2"in751439,"msg_type"in45,"reply_ip"in176886319,"group_code"in1226655265,"group_type"in1,"ver"in1,"send_uin"in3706930015,"xml"in"\u0001\u0000\u0001 \u0000\t\u00D4 \u0000\u000F\u00C9\u00CB\u00D0\u00C4\u032B\u01BD\u00D1\u00F3-\u00C0\u00D7\u00E6\u00C3\u0000\u00EDtencentin//miniplayer/?cmd=1\u0026fuin=569398403\u0026frienduin=569398403\u0026groupid=4150334785\u0026groupcode=260334785\u0026action=\u0027accept\u0027\u0026mdlurl=\u0027httpin//scenecgi.chatshow.qq.com/fcgi-bin/gm_qry_music_info.fcg?songcount=1\u0026songidlist=644128\u0026version=207\u0026cmd=1\u0027\u0000\u00EDtencentin//miniplayer/?cmd=1\u0026fuin=569398403\u0026frienduin=569398403\u0026groupid=4150334785\u0026groupcode=260334785\u0026action=\u0027refuse\u0027\u0026mdlurl=\u0027httpin//scenecgi.chatshow.qq.com/fcgi-bin/gm_qry_music_info.fcg?songcount=1\u0026songidlist=644128\u0026version=207\u0026cmd=1\u0027"}}]}
                        }
                        else if (pollType.Equals("system_message"))
                        {
                            // 其他人 添加你为好友
                            // {"retcode"in0,"result"in[{"poll_type"in"system_message","value"in{"seq"in49219,"type"in"Added_buddy_sig","uiuin"in"","from_uin"in2388435354,"account"in569398403,"sig"in"Ub\u008A\u00B8\u00D4\u0001\u008B\u0092Q\u001D\"*W\u00F6b\u00EA\u001E\u00F0\u009A\u0016gqb\u00C7","stat"in20}}]}
                        }
                        else if (pollType.Equals("sys_g_msg"))
                        {
                            // 设置你为群管理员
                            // {"retcode"in0,"result"in[{"poll_type"in"sys_g_msg","value"in{"msg_id"in58825,"from_uin"in848492696,"to_uin"in1002053815,"msg_id2"in584526,"msg_type"in44,"reply_ip"in180061855,"type"in"group_admin_op","gcode"in2227416282,"t_gcode"in126658727,"op_type"in1,"uin"in1002053815,"t_uin"in1002053815,"uin_flag"in1}}]}
                            // 取消你为群管理员
                            // {"retcode"in0,"result"in[{"poll_type"in"sys_g_msg","value"in{"msg_id"in9211,"from_uin"in848492696,"to_uin"in1002053815,"msg_id2"in265670,"msg_type"in44,"reply_ip"in176757008,"type"in"group_admin_op","gcode"in2227416282,"t_gcode"in126658727,"op_type"in0,"uin"in1002053815,"t_uin"in1002053815,"uin_flag"in0}}]}
                            // 设置群成员为群管理员
                            // {"retcode"in0,"result"in[{"poll_type"in"sys_g_msg","value"in{"msg_id"in40322,"from_uin"in848492696,"to_uin"in1002053815,"msg_id2"in183897,"msg_type"in44,"reply_ip"in179406747,"type"in"group_admin_op","gcode"in2227416282,"t_gcode"in126658727,"op_type"in1,"uin"in3904214993,"t_uin"in2564781987,"uin_flag"in1}}]}
                            // 取消群成员为群管理员
//						{"retcode"in0,"result"in[{"poll_type"in"sys_g_msg","value"in{"msg_id"in13045,"from_uin"in848492696,"to_uin"in1002053815,"msg_id2"in15288,"msg_type"in44,"reply_ip"in176756443,"type"in"group_admin_op","gcode"in2227416282,"t_gcode"in126658727,"op_type"in0,"uin"in3904214993,"t_uin"in2564781987,"uin_flag"in0}}]}

                            // 你已经被移除群
                            // {"retcode"in0,"result"in[{"poll_type"in"sys_g_msg","value"in{"msg_id"in5515,"from_uin"in848492696,"to_uin"in1002053815,"msg_id2"in634857,"msg_type"in34,"reply_ip"in176488602,"type"in"group_leave","gcode"in2227416282,"t_gcode"in126658727,"op_type"in3,"old_member"in1002053815,"t_old_member"in"","admin_uin"in2388435354,"t_admin_uin"in"","admin_nick"in"\u521B\u5EFA\u8005"}}]}
                            // 某人申请加入群
                            // {"retcode"in0,"result"in[{"poll_type"in"sys_g_msg","value"in{"msg_id"in9564,"from_uin"in848492696,"to_uin"in1002053815,"msg_id2"in366710,"msg_type"in35,"reply_ip"in176884836,"type"in"group_request_join","gcode"in2227416282,"t_gcode"in126658727,"request_uin"in3904214993,"t_request_uin"in"","msg"in"gggggg"}}]}
                        }
                        else
                        {
                        }
                    }
                }
                // end recode == 0
            }
            else if (retcode == 102)
            {
                // 接连正常,没有消息到达 {"retcode"in102,"errmsg"in""}
                // 继续进行下一个消息请求
            }
            else if (retcode == 110 || retcode == 109)         // 客户端主动退出
            {
                getContext().getSession().setState(QQSession.State.OFFLINE);
            }
            else if (retcode == 116)
            {
                // 需要更新Ptwebqq值,暂时不知道干嘛用的
                // {"retcode"in116,"p"in"2c0d8375e6c09f2af3ce60c6e081bdf4db271a14d0d85060"}
                // if (a.retcode === 116) alloy.portal.setPtwebqq(a.p)
                getContext().getSession().setPtwebqq(json.getString("p"));
            }
            else if (retcode == 121 || retcode == 120 || retcode == 100)         // 121,120
            // in
            // ReLinkFailure
            // 100
            // in
            // NotReLogin
            // 服务器需求重新认证
            // {"retcode"in121,"t"in"0"}
            {
                getContext().getSession().setState(QQSession.State.OFFLINE);
                QQException ex = new QQException(QQException.QQErrorCode.INVALID_LOGIN_AUTH);
                notifyActionEvent(QQActionEvent.Type.EVT_ERROR, ex);
                return;
                // notifyEvents.Add(new
                // QQNotifyEvent(QQNotifyEvent.Type.NEED_REAUTH, null));
            }
            else
            {
                // 返回错误,核心遇到未知recode
                // getCxt().getSession().setState(QQSession.State.ERROR);
                notifyEvents.Add(new QQNotifyEvent(QQNotifyEvent.Type.UNKNOWN_ERROR, json));
            }
            notifyActionEvent(QQActionEvent.Type.EVT_OK, notifyEvents);
        }