コード例 #1
0
ファイル: WebQQClient.cs プロジェクト: zjxbetter/iQQ.Net
        /// <summary>
        /// 退出验证码输入
        /// </summary>
        /// <param name="verifyEvent"></param>
        public void CancelVerify(QQNotifyEvent verifyEvent)
        {
            var verify =
                (QQNotifyEventArgs.ImageVerify)verifyEvent.Target;

            verify.Future.Cancel();
        }
コード例 #2
0
        protected override async Task <ActionEvent> NotifyActionEventAsync(ActionEvent actionEvent)
        {
            var type     = actionEvent.Type;
            var typeName = type.GetDescription();
            var target   = actionEvent.Target;

            switch (type)
            {
            case ActionEventType.EvtError:
            {
                var ex = (QQException)target;
                Logger.LogError($"[Action={ActionName}, Result={typeName}, {ex}");
                await _context.FireNotifyAsync(QQNotifyEvent.CreateEvent(QQNotifyEventType.Error, ex));

                break;
            }

            case ActionEventType.EvtRetry:
            {
                var ex = (QQException)target;
                Logger.LogWarning($"[Action={ActionName}, Result={typeName}, RetryTimes={RetryTimes}][{ex.ToSimpleString()}]");
                break;
            }

            case ActionEventType.EvtCanceled:
                Logger.LogWarning($"[Action={ActionName}, Result={typeName}, Target={target}]");
                break;

            default:
                Logger.LogDebug($"[Action={ActionName}, Result={typeName}]");
                break;
            }
            return(await base.NotifyActionEventAsync(actionEvent));
        }
コード例 #3
0
ファイル: PollMsgAction.cs プロジェクト: jjg0519/WebQQWeChat
        private void HandleMessage(JToken resultValue, List <QQNotifyEvent> events)
        {
            /*
             *  {
             *      "result": [
             *          {
             *              "poll_type": "message",
             *              "value": {
             *                  "content": [
             *                      [
             *                          "font",
             *                          {
             *                              "color": "000000",
             *                              "name": "微软雅黑",
             *                              "size": 10,
             *                              "style": [
             *                                  0,
             *                                  0,
             *                                  0
             *                              ]
             *                          }
             *                      ],
             *                      [
             *                          "face",
             *                          107
             *                      ],
             *                      "xxx",
             *                      [
             *                          "face",
             *                          107
             *                      ]
             *                  ],
             *                  "from_uin": 3219658576,
             *                  "msg_id": 1019,
             *                  "msg_type": 0,
             *                  "time": 1479178662,
             *                  "to_uin": 89009143
             *              }
             *          }
             *      ],
             *      "retcode": 0
             *  }
             */
            var msg = resultValue.ToObject <FriendMessage>();

            msg.Friend = Store.GetOrAddFriendByUin(msg.FromUin, u =>
            {
                events.Add(QQNotifyEvent.CreateEvent(QQNotifyEventType.NeedUpdateFriends));
                return(new QQFriend()
                {
                    Uin = u
                });
            });
            msg.Contents = ContentFatory.ParseContents(resultValue["content"].ToJArray());

            events.Add(QQNotifyEvent.CreateEvent(QQNotifyEventType.ChatMsg, msg));
        }
コード例 #4
0
        private Task <ActionEvent> HandlePollMsg(JToken result)
        {
            var array        = result as JArray;
            var notifyEvents = new List <QQNotifyEvent>();

            if (array != null)
            {
                foreach (var item in array)
                {
                    var type  = item["poll_type"].ToObject <PollType>();
                    var value = item["value"];
                    switch (type)
                    {
                    case PollType.InputNotify:
                        break;

                    case PollType.Message:
                        notifyEvents.Add(QQNotifyEvent.CreateEvent(QQNotifyEventType.ChatMsg, HandleMessage(value)));
                        break;

                    case PollType.GroupMessage:
                        notifyEvents.Add(QQNotifyEvent.CreateEvent(QQNotifyEventType.GroupMsg, HandleGroupMessage(value)));
                        break;

                    case PollType.DiscussionMessage:
                        break;

                    case PollType.SessionMessage:
                        break;

                    case PollType.ShakeMessage:
                        break;

                    case PollType.KickMessage:
                        break;

                    case PollType.BuddiesStatusChange:
                        break;

                    case PollType.SystemMessage:
                        break;

                    case PollType.GroupWebMessage:
                        break;

                    case PollType.SysGroupMsg:
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }

            return(NotifyActionEventAsync(ActionEventType.EvtOK, notifyEvents));
        }
コード例 #5
0
        /// <summary>
        /// 提交验证码
        /// </summary>
        /// <param name="code"></param>
        /// <param name="verifyEvent"></param>
        public void SubmitVerify(string code, QQNotifyEvent verifyEvent)
        {
            var verify = (ImageVerify)verifyEvent.Target;

            if (verify.Type == ImageVerify.VerifyType.LOGIN)
            {
                var mod = GetModule <ProcModule>(QQModuleType.PROC);
                mod.LoginWithVerify(code, (ProcActionFuture)verify.Future);
            }
        }
コード例 #6
0
        public Task <ActionEvent> Login(ActionEventListener listener)
        {
            return(new QQActionFuture(Context, listener)
                   .PushAction <GetQRCodeAction>(async(sender, @event) => // 1.»ñÈ¡¶þάÂë
            {
                if (@event.Type == ActionEventType.EvtOK)
                {
                    var verify = (Image)@event.Target;
                    await Context.FireNotifyAsync(QQNotifyEvent.CreateEvent(QQNotifyEventType.QRCodeReady, verify));
                }
            })
                   .PushAction <CheckQRCodeAction>(async(sender, @event) => // 2.»ñÈ¡¶þάÂëɨÃè״̬
            {
                if (@event.Type != ActionEventType.EvtOK)
                {
                    return;
                }

                var args = (CheckQRCodeArgs)@event.Target;
                switch (args.Status)
                {
                case QRCodeStatus.OK:
                    Context.GetModule <SessionModule>().CheckSigUrl = args.Msg;
                    await Context.FireNotifyAsync(QQNotifyEvent.CreateEvent(QQNotifyEventType.QRCodeSuccess));
                    break;

                case QRCodeStatus.Valid:
                case QRCodeStatus.Auth:
                    Context.GetSerivce <ILogger>().LogDebug($"¶þάÂë״̬£º{args.Status.GetDescription()}");
                    @event.Type = ActionEventType.EvtRepeat;
                    await Task.Delay(3000);
                    break;

                case QRCodeStatus.Invalid:
                    await Context.FireNotifyAsync(QQNotifyEvent.CreateEvent(QQNotifyEventType.QRCodeInvalid, args.Msg));
                    break;
                }
            })
                   .PushAction <CheckSigAction>()
                   .PushAction <GetVfwebqqAction>()
                   .PushAction <ChannelLoginAction>(async(sender, @event) => // 2.»ñÈ¡¶þάÂëɨÃè״̬
            {
                if (@event.Type != ActionEventType.EvtOK)
                {
                    return;
                }
                await Context.FireNotifyAsync(QQNotifyEvent.CreateEvent(QQNotifyEventType.LoginSuccess));
            })
                   //.PushAction<GetFriendsAction>()
                   //.PushAction<GetGroupNameListAction>()
                   .PushAction <GetDiscuzListAction>()
                   .PushAction <GetSelfInfoAction>()
                   .PushAction <GetOnlineBuddiesAction>()
                   .ExecuteAsync());
        }
コード例 #7
0
 /// <summary>
 /// 通知事件
 /// </summary>
 /// <param name="qqNotifyEvent"></param>
 public void FireNotify(QQNotifyEvent qqNotifyEvent)
 {
     try
     {
         NotifyListener?.Invoke(this, qqNotifyEvent);
     }
     catch (Exception ex)
     {
         Logger.LogError($"FireNotify Error!! {ex}", ex);
     }
 }
コード例 #8
0
        private void HandleGroupMessage(JToken resultValue, List <QQNotifyEvent> events)
        {
            /*
             *   {
             *      "result": [
             *          {
             *              "poll_type": "group_message",
             *              "value": {
             *                  "content": [
             *                      [
             *                          "font",
             *                          {
             *                              "color": "000000",
             *                              "name": "微软雅黑",
             *                              "size": 10,
             *                              "style": [
             *                                  0,
             *                                  0,
             *                                  0
             *                              ]
             *                          }
             *                      ],
             *                      "。。。"
             *                  ],
             *                  "from_uin": 3258316418,
             *                  "group_code": 3258316418,
             *                  "msg_id": 18537,
             *                  "msg_type": 0,
             *                  "send_uin": 2515522700,
             *                  "time": 1479175440,
             *                  "to_uin": 89009143
             *              }
             *          }
             *      ],
             *      "retcode": 0
             *  }
             */

            var msg = resultValue.ToObject <GroupMessage>();

            msg.Group = Store.GetOrAddGroupByGid(msg.GroupCode, u =>
            {
                events.Add(QQNotifyEvent.CreateEvent(QQNotifyEventType.NeedUpdateGroups));
                return(new QQGroup {
                    Gid = u
                });
            }); // 此处的GroupCode实际上是Group的gid
            msg.Contents = ContentFatory.ParseContents(resultValue["content"].ToJArray());

            events.Add(QQNotifyEvent.CreateEvent(QQNotifyEventType.ChatMsg, msg));
        }
コード例 #9
0
ファイル: WebQQClient.cs プロジェクト: ztxyzu/WebQQWeChat
 public async Task FireNotifyAsync(QQNotifyEvent notifyEvent)
 {
     try
     {
         if (_notifyListener != null)
         {
             await _notifyListener(this, notifyEvent);
         }
     }
     catch (Exception ex)
     {
         _logger.LogError($"FireNotify Error!! {ex}", ex);
     }
 }
コード例 #10
0
ファイル: PollMsgAction.cs プロジェクト: jjg0519/WebQQWeChat
        protected override Task <ActionEvent> HandleResponse(HttpResponseItem response)
        {
            var json    = response.ResponseString.ToJToken();
            var retcode = json["retcode"].ToInt();

            switch (retcode)
            {
            case 0: return(HandlePollMsg(json["result"]));

            case 102:
                // 接连正常,没有消息到达 {"retcode":102,"errmsg":""}
                // 继续进行下一个消息请求
                return(NotifyOkEventAsync());

            case 110:
            case 109:
            {
                // 客户端主动退出
                var msg = $"**** 客户端主动退出 retcode: {retcode} ****";
                Logger.LogWarning(msg);
                Session.State = SessionState.Offline;
                return(NotifyOkEventAsync(QQNotifyEvent.CreateEvent(QQNotifyEventType.NetError, msg)));
            }


            case 121:
            case 120:
            case 100:
            {
                // 客户端主动退出
                var msg = $"**** 服务器需求重新认证 retcode: {retcode} ****";
                Logger.LogWarning(msg);
                Session.State = SessionState.Offline;
                return(NotifyOkEventAsync(QQNotifyEvent.CreateEvent(QQNotifyEventType.NetError, msg)));
            }

            case 103:     // 此时需要登录Smart QQ,确认能收到消息后点击设置-退出登录,就会恢复正常了
            {
                // 客户端主动退出
                var msg = $"**** 需要登录Smart QQ retcode: {retcode} ****";
                Logger.LogWarning(msg);
                // Session.State = SessionState.Offline;
                // return NotifyOkEventAsync(QQNotifyEvent.CreateEvent(QQNotifyEventType.NetError, msg));
                return(NotifyOkEventAsync());
            }
            }
            throw new QQException(QQErrorCode.ResponseError, response.ResponseString);
        }
コード例 #11
0
ファイル: WebQQClient.cs プロジェクト: zjxbetter/iQQ.Net
 /// <summary>
 /// 通知事件
 /// </summary>
 /// <param name="Event"></param>
 public void FireNotify(QQNotifyEvent Event)
 {
     if (NotifyListener != null)
     {
         try
         {
             NotifyListener(this, Event);
         }
         catch (Exception e)
         {
             MyLogger.Default.Warn("FireNotify Error!!", e);
         }
     }
     // 重新登录成功,重新poll
     if (Event.Type == QQNotifyEventType.RELOGIN_SUCCESS)
     {
         BeginPollMsg();
     }
 }
コード例 #12
0
        /// <summary>
        /// 反复轮询
        /// </summary>
        /// <param name="sid">凭证ID,就算没有Cookie都可以轮询</param>
        /// <param name="t">邮件,好像是时间,用来消除轮询返回的列表中邮件,不然一直会返回那个邮件回来</param>
        private void LoopPoll(string sid, long t)
        {
            Poll(sid, t, (sender, Event) =>
            {
                if (Event.Type == QQActionEventType.EVT_OK)
                {
                    ErrorCount = 0;
                    if (Event.Target == null)
                    {
                        // 没有新邮件,t直接传0
                        LoopPoll(sid, 0);
                    }
                    else
                    {
                        // 有新邮件
                        QQNotifyEvent evt = (QQNotifyEvent)Event.Target;
                        // 通知事件
                        Context.FireNotify(evt);
                        // 消除所有,传上最后t的标记上去
                        List <QQEmail> mailList = (List <QQEmail>)evt.Target;
                        LoopPoll(sid, mailList[mailList.Count - 1].Flag);

                        // 把邮件标记为已读,需要邮件列表ID
                        // mark(false, mailList, null);
                    }
                }
                else if (Event.Type == QQActionEventType.EVT_ERROR)
                {
                    QQException ex = (QQException)Event.Target;
                    if (ex.ErrorCode == QQErrorCode.INVALID_LOGIN_AUTH)
                    {
                        // 凭证失效,重新认证
                        DoPoll();
                    }
                    else if (ErrorCount < QQConstants.MAX_POLL_ERR_CNT)
                    {
                        LoopPoll(sid, 0);
                        ErrorCount++;
                    }
                }
            });
        }
コード例 #13
0
        /// <summary>
        /// 刷新验证码
        /// </summary>
        /// <param name="verifyEvent"></param>
        /// <param name="listener"></param>
        /// <returns></returns>
        public IQQActionFuture FreshVerify(QQNotifyEvent verifyEvent, QQActionListener listener)
        {
            var mod = GetModule <LoginModule>(QQModuleType.LOGIN);

            return(mod.GetCaptcha(Account.Uin, listener));
        }
コード例 #14
0
ファイル: Extesions.cs プロジェクト: l376571926/WebQQWeChat
 public static T Get <T>(this QQNotifyEvent e)
 {
     return((T)e.Target);
 }
コード例 #15
0
ファイル: WebQQClient.cs プロジェクト: xtmhm2000/WebQQWeChat
 public Task FireNotifyAsync(QQNotifyEvent notifyEvent)
 {
     return(Task.Run(() => FireNotify(notifyEvent)));
 }
コード例 #16
0
ファイル: Extesions.cs プロジェクト: l376571926/WebQQWeChat
 public static Task FireNotifyAsync(this IQQContext context, QQNotifyEventType type, object target = null)
 {
     return(context.FireNotifyAsync(QQNotifyEvent.CreateEvent(type, target)));
 }
コード例 #17
0
        public Task <ActionEvent> Login(ActionEventListener listener)
        {
            return(new WebQQActionFuture(Context, listener)
                   .PushAction <GetQRCodeAction>(async(sender, @event) => // 1.获取二维码
            {
                if (@event.Type == ActionEventType.EvtOK)
                {
                    var verify = (Image)@event.Target;
                    await Context.FireNotifyAsync(QQNotifyEvent.CreateEvent(QQNotifyEventType.QRCodeReady, verify));
                }
            })
                   .PushAction <CheckQRCodeAction>(async(sender, @event) => // 2.获取二维码扫描状态
            {
                if (@event.Type != ActionEventType.EvtOK)
                {
                    return;
                }

                var args = (CheckQRCodeArgs)@event.Target;
                switch (args.Status)
                {
                case QRCodeStatus.OK:
                    Session.CheckSigUrl = args.Msg;
                    await Context.FireNotifyAsync(QQNotifyEvent.CreateEvent(QQNotifyEventType.QRCodeSuccess));
                    break;

                case QRCodeStatus.Valid:
                case QRCodeStatus.Auth:
                    Logger.LogDebug($"二维码状态:{args.Status.GetDescription()}");
                    @event.Type = ActionEventType.EvtRepeat;
                    await Task.Delay(3000);
                    break;

                case QRCodeStatus.Invalid:
                    await Context.FireNotifyAsync(QQNotifyEvent.CreateEvent(QQNotifyEventType.QRCodeInvalid, args.Msg));
                    break;
                }
            })
                   .PushAction <CheckSigAction>()
                   .PushAction <GetVfwebqqAction>()
                   .PushAction <ChannelLoginAction>(async(sender, @event) =>
            {
                if (@event.Type != ActionEventType.EvtOK)
                {
                    return;
                }
                await Context.FireNotifyAsync(QQNotifyEvent.CreateEvent(QQNotifyEventType.LoginSuccess));
            })
                   .PushAction <GetFriendsAction>(async(sender, @event) =>
            {
                if (@event.Type != ActionEventType.EvtOK)
                {
                    return;
                }
                var obj = Store.FriendDic.FirstOrDefault().Value;
                if (obj == null)
                {
                    return;
                }
                await new GetFriendLongNickAction(Context, obj).ExecuteAsyncAuto();
                await new GetFriendQQNumberAction(Context, obj).ExecuteAsyncAuto();
                await new GetFriendInfoAction(Context, obj).ExecuteAsyncAuto();
            })
                   .PushAction <GetGroupNameListAction>(async(sender, @event) =>
            {
                if (@event.Type != ActionEventType.EvtOK)
                {
                    return;
                }
                var group = Store.GroupDic.FirstOrDefault().Value;
                if (group != null)
                {
                    await new GetGroupInfoAction(Context, group).ExecuteAsyncAuto();
                }
            })
                   .PushAction <GetDiscussionListAction>(async(sender, @event) =>
            {
                if (@event.Type != ActionEventType.EvtOK)
                {
                    return;
                }
                var dis = Store.DiscussionDic.FirstOrDefault().Value;
                if (dis != null)
                {
                    await new GetDiscussionInfoAction(Context, dis).ExecuteAsyncAuto();
                }
            })
                   .PushAction <GetSelfInfoAction>()
                   .PushAction <GetOnlineFriendsAction>()
                   .ExecuteAsync());
        }