Exemplo n.º 1
0
    public static MsgHandle getHandle(EMessageID msgId_)
    {
        MsgHandle handle = null;

        s_msgDict.TryGetValue(msgId_, out handle);
        return(handle);
    }
Exemplo n.º 2
0
 private object Message_AcceptedMessage(IMessageUsable sender, MessageAcceptArgs args)
 {
     if (!MsgHandle.TryGetValue(args.Key, out var handle))
     {
         throw new ArgumentException($"不存在key={args.Key} 的处理方法");
     }
     return(handle.Invoke(sender, args));
 }
Exemplo n.º 3
0
    void Awake()
    {
        inst = this;

        loginMsgHandle = new LoginMsgHandle();
        lobbyMsgHandle = new LobbyMsgHandle();
        frameMsgHandle = new FrameMsgHanlde();
    }
Exemplo n.º 4
0
    public void RegMsg(int mid, MsgHandle msg)
    {
        List <MsgHandle> msgLst;

        if (!m_msgHandle.TryGetValue(mid, out msgLst))
        {
            msgLst = new List <MsgHandle>();
            m_msgHandle.Add(mid, msgLst);
        }
        msgLst.Add(msg);
    }
Exemplo n.º 5
0
 public MainViewModel()
 {
     IocHelper.EnsureIocKey(this);
     stringResource = ViewModelLocatorBase.StringResources;
     ViewItems      = new ObservableCollection <ViewItem>
     {
         new ViewItem(stringResource.GetString("HomeText"), (char)0xE10F, string.Empty, HomePageId),
         new ViewItem(stringResource.GetString("ContentText"), (char)0xE132, string.Empty, ContentPageId),
         new ViewItem(stringResource.GetString("MakeContentTitle"), (char)0xE11F, string.Empty, SendContentPageId),
         new ViewItem(stringResource.GetString("MsgPageText"), (char)0xE119, string.Empty, MsgPageId),
     };
     //注册消息服务
     MsgHandle.Add(ShowMsgKey, ShowMsgHandle);
 }
Exemplo n.º 6
0
    public void UnRegMsg(int mid, MsgHandle msg)
    {
        List <MsgHandle> msgLst;

        if (!m_msgHandle.TryGetValue(mid, out msgLst))
        {
            return;
        }
        msgLst.Remove(msg);
        if (msgLst.Count <= 0)
        {
            m_msgHandle.Remove(mid);
        }
    }
Exemplo n.º 7
0
 public ContentViewModel()
 {
     LocalPage            = 0;
     IsNotWebConnecting   = false;
     ParWidth             = _ParWidth;
     apiManager           = SimpleIoc.Inst.GetInstance <WebApiManager>(ViewModelLocatorBase.ApiManagerKey);
     appResources         = SimpleIoc.Inst.GetInstance <IStringResource>(ViewModelLocatorBase.StringReourceKey);
     Contents             = new ObservableCollection <Content>();
     IsNotWebConnecting   = true;
     UpdateContentCommand = new RelayCommand(UpdateContent);
     SearchContentCommand = new RelayCommand(SearchContent);
     NextPageCommand      = new RelayCommand(NextPage);
     PrevPageCommand      = new RelayCommand(PrevPage);
     IocHelper.EnsureIocKey(this);
     MsgHandle.Add(SetVisitContentKey, SetVisitContent);
     MsgHandle.Add(SetLeftPartVisibilityKey, SetLeftPartVisibility);
 }
Exemplo n.º 8
0
        private void backgroundWorkerSync_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            //MsgHandle handle = new MsgHandle();
            string state = e.UserState as string;

            if (string.IsNullOrEmpty(state))
            {
                AddMsgList msg = e.UserState as AddMsgList;
                if (msg != null)
                {
                    LogOut(string.Format("消息类型:{0},FromUserName:{1},ToUserName:{2},消息内容:{3},\r\n NotifyUserName:{4},时间:{5}",
                                         msg.MsgType, msg.FromUserName, msg.ToUserName, msg.Content, msg.StatusNotifyUserName, DateTime.Now));

                    MsgHandle handle  = new MsgHandle();
                    int       msgType = msg.MsgType;
                    switch (msgType)
                    {
                    case (int)MsgTypeEnum.系统消息:
                        handle.InitWxUser(msg);
                        break;

                    case (int)MsgTypeEnum.加好友:
                        if (buyService.HaveUser(Global.robot.Id, msg.RecommendInfo.NickName))
                        {
                            var result = protocol.VerifyUser(msg.RecommendInfo.UserName, msg.RecommendInfo.Ticket, Global.robot.Cookie, Global.robot.CookieStr);
                            LogOut("加好友" + result.ErrMsg);
                            //加完好友之后增加到机器人的好友表中
                            //wx_friend friend = new wx_friend();
                            //friend.UserName = msg.RecommendInfo.UserName;
                            //friend.NickName = msg.RecommendInfo.NickName;
                            //friend.AttrStatus = msg.RecommendInfo.AttrStatus;
                            //ContactService service = new ContactService();
                            //service.AddContent(friend);
                            Global.robot.Contact = protocol.GetContact(Global.robot.Cookie, Global.robot.CookieStr).MemberList.ToList();
                            Task.Run(() =>
                            {
                                protocol.StatusNotify(Global.robot.Cookie, Global.robot.CookieStr, Global.robot.UserName);
                            });

                            //发送消息
                            protocol.SendMsg("请输入验证码,如未购买,请访问", msg.RecommendInfo.UserName, 1, Global.robot.Cookie, Global.robot.CookieStr, Global.robot.UserName);
                        }
                        break;

                    case (int)MsgTypeEnum.群通知:
                        //好友已添加,被拉进群
                        if (msg.FromUserName.StartsWith("@@"))
                        {
                            //拉进群
                            //初始化
                            //拉别人进群也会有此通知
                            //判断群id是否存在,不存在初始化
                            var user = Global.robot.WxUserList.Where(u => u.UserName == msg.FromUserName).FirstOrDefault();
                            if (user == null)
                            {
                                protocol.StatusNotify(Global.robot.Cookie, Global.robot.CookieStr, Global.robot.UserName);
                            }
                            //protocol.SendMsg("群绑定成功,机器人开始为您服务", msg.FromUserName, 1, Global.robot.Cookie, Global.robot.CookieStr, Global.robot.UserName);
                        }
                        else
                        {
                            //好友
                        }
                        break;

                    default:
                        if (msg.FromUserName.StartsWith("@@") && msg.ToUserName.StartsWith("@"))
                        {
                            //群消息对个人
                            string fromAlias = WechatCommon.GetTrueId(msg.FromUserName);
                            bool   isBind    = buyService.IsBind(fromAlias);
                            string content   = msg.Content;

                            if (isBind)
                            {
                                //聊天记录
                                wx_group_chat chat = new wx_group_chat();
                                chat.Createtime    = DateTime.Now;
                                chat.MsgType       = msg.MsgType;
                                chat.GroupUserName = msg.FromUserName;
                                chat.GroupId       = WechatCommon.GetTrueId(msg.FromUserName);

                                if (content.StartsWith("@"))
                                {
                                    int    startIndex   = content.IndexOf(':');
                                    string fromUserName = content.Substring(0, startIndex);
                                    chat.SendAlias      = WechatCommon.GetTrueId(fromUserName);
                                    chat.SendUserName   = fromUserName;
                                    chat.Content        = content.Substring(startIndex + 6);
                                    chat.SendNickName   = WechatCommon.GetNickNameFromGroup(msg.FromUserName, fromUserName);
                                    chat.SendAttrStatus = WechatCommon.GetAttrStatusFromGroup(msg.FromUserName, fromUserName);
                                }
                                else
                                {
                                    chat.Content = content;
                                }
                                msgService.InsertMsg(chat);
                            }
                            //判断是否是开通群空间
                            if (content.StartsWith("@"))
                            {
                                int    startIndex   = content.IndexOf(':');
                                string fromUserName = content.Substring(0, startIndex);
                                string sendAlias    = WechatCommon.GetTrueId(fromUserName);
                                string message      = content.Substring(startIndex + 6);

                                string[] c = message.Split(' ');
                                if (c != null && c.Length == 2)
                                {
                                    if (c[0] == "@" + Global.robot.NickName && c[1] == "开通群空间")
                                    {
                                        //判断已经开通的群无法再次开通
                                        if (!isBind)
                                        {
                                            int recordId = buyService.GetBuyRecordId(Global.robot.Id, sendAlias);
                                            if (recordId > 0)
                                            {
                                                int result = buyService.BindGroup(recordId, fromAlias);
                                                if (result > 0)
                                                {
                                                    protocol.SendMsg("群绑定成功,机器人开始为您服务", msg.FromUserName, 1, Global.robot.Cookie, Global.robot.CookieStr, Global.robot.UserName);
                                                    //群空间开通功能,捞取人员信息存入数据库等操作

                                                    var groupInfo = Global.robot.GroupInfo.Where(n => n.UserName == msg.FromUserName).FirstOrDefault();
                                                    if (groupInfo == null)
                                                    {
                                                        BatchGetContactResult contactResult = protocol.BatchGetContact(new List <string>()
                                                        {
                                                            msg.FromUserName
                                                        }, Global.robot.Cookie, Global.robot.CookieStr);
                                                        if (contactResult != null)
                                                        {
                                                            groupInfo = contactResult.ContactList[0];
                                                        }
                                                    }
                                                    //存数据库
                                                    Task.Run(() => {
                                                        GroupService groupService = new GroupService();
                                                        groupService.SyncGroup(groupInfo);
                                                    });
                                                }
                                                else
                                                {
                                                    protocol.SendMsg("群绑定失败", msg.FromUserName, 1, Global.robot.Cookie, Global.robot.CookieStr, Global.robot.UserName);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            protocol.SendMsg("群已经被绑定", msg.FromUserName, 1, Global.robot.Cookie, Global.robot.CookieStr, Global.robot.UserName);
                                        }
                                    }
                                }
                            }
                        }
                        else if (msg.FromUserName.StartsWith("@") && msg.ToUserName.StartsWith("@@"))
                        {
                            //个人发群消息
                        }
                        else if (msg.FromUserName.StartsWith("@") && msg.ToUserName.StartsWith("@"))
                        {
                            //个人对个人
                            if (msg.ToUserName == Global.robot.UserName)
                            {
                                //判断内容是否跟验证码符合
                                string nickName = Global.robot.Contact.Where(n => n.UserName == msg.FromUserName).Select(n => n.NickName).FirstOrDefault();
                                int    recordId = buyService.VaildCode(Global.robot.Id, nickName, msg.Content);
                                if (recordId > 0)
                                {
                                    //绑定成功
                                    string alias = WechatCommon.GetTrueId(msg.FromUserName);
                                    if (buyService.UseCode(recordId, alias) > 0)
                                    {
                                        protocol.SendMsg("验证成功,请添加到群中", msg.FromUserName, 1, Global.robot.Cookie, Global.robot.CookieStr, Global.robot.UserName);
                                    }
                                    else
                                    {
                                        protocol.SendMsg("验证失败,请重新输入", msg.FromUserName, 1, Global.robot.Cookie, Global.robot.CookieStr, Global.robot.UserName);
                                    }
                                }
                                else
                                {
                                    protocol.SendMsg("验证码错误,如未购买,请访问", msg.FromUserName, 1, Global.robot.Cookie, Global.robot.CookieStr, Global.robot.UserName);
                                }
                            }
                        }
                        break;
                    }

                    //if (msg.MsgType == (int)MsgTypeEnum.加好友)
                    //{
                    //    //加好友
                    //    var result = protocol.VerifyUser(msg.RecommendInfo.UserName, msg.RecommendInfo.Ticket, Global.robot.Cookie, Global.robot.CookieStr);
                    //    LogOut("加好友" + result.ErrMsg);
                    //}
                    //else if (msg.MsgType == (int)MsgTypeEnum.系统消息&&msg.ToUserName.StartsWith("@@"))
                    //{
                    //    //群
                    //    //protocol.SendMsg("欢迎加入群聊天", msg.ToUserName, 1, Global.robot.Cookie, Global.robot.CookieStr,Global.robot.UserName);
                    //    //string html = protocol.BatchGetContact(msg.ToUserName, Global.robot.Cookie, Global.robot.CookieStr);
                    //}
                }
            }
            else if (state == "1100")
            {
                LogOut("拉取消息请求超时,请重新登录" + DateTime.Now);
                syncRun = false;
            }
            else if (state == "正常")
            {
                LogOut("0正常捞取" + DateTime.Now);
            }
            else
            {
                LogOut(state + "未知异常,请重新登录" + DateTime.Now);
                syncRun = false;
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 处理不同请求
        /// </summary>
        /// <returns></returns>
        public string Dispatch()
        {
            if (xml == null)
            {
                return(string.Empty);
            }
            //XElement root=new XElement("xml",
            //    new XElement("ToUserName","kkisc"),
            //    new XElement("FromUserName","scikk"));
            //return string.Empty;
            var result = string.Empty;
            //获取消息对应枚举类型
            var msgType = (RequestMsgType)Enum.Parse(typeof(RequestMsgType), xml.Element("MsgType").Value, true);

            #region 判断消息类型
            switch (msgType)
            {
            case RequestMsgType.Text:
                RText rtext = new RText();
                rtext = XmlHelper.GetModel <RText>(rtext, xml);
                MsgHandle mh = new MsgHandle();
                result = mh.TextHandle(rtext);   //处理相关逻辑
                break;

            case RequestMsgType.Image: break;

            case RequestMsgType.Voice: break;

            case RequestMsgType.Video: break;

            case RequestMsgType.Location: break;

            case RequestMsgType.Link: break;

                #region 事件
            case RequestMsgType.Event:
                //获取事件对应枚举类型
                var eventType = (Event)Enum.Parse(typeof(Event), xml.Element("Event").Value, true);
                switch (eventType)
                {
                case Event.subscribe: break;

                case Event.unsubscribe: break;

                case Event.scan: break;

                case Event.LOCATION: break;

                case Event.CLICK: break;

                case Event.VIEW:        //自定义菜单跳转
                    break;

                default:
                    break;
                }
                break;

                #endregion
            default:
                break;
            }
            #endregion
            return(result);
        }
Exemplo n.º 10
0
 /// <summary>
 /// 接收消息通知
 /// </summary>
 /// <param name="msg"></param>
 private void Msg(string msg)
 {
     MsgHandle?.Invoke(serviceName + msg);
 }