Exemplo n.º 1
0
        private void btnClose_Click(object sender, EventArgs e)
        {
            string groupID = this.skinTextBox_id.SkinTxt.Text.Trim();

            if (groupID.Length == 0)
            {
                MessageBoxEx.Show("群帐号不能为空!");
                this.DialogResult = System.Windows.Forms.DialogResult.None;
                return;
            }

            try
            {
                CreateGroupContract contract = new CreateGroupContract(groupID, this.skinTextBox_name.SkinTxt.Text.Trim(), this.skinTextBox_announce.SkinTxt.Text);
                byte[]            bRes       = this.rapidPassiveEngine.CustomizeOutter.Query(InformationTypes.CreateGroup, CompactPropertySerializer.Default.Serialize(contract));
                CreateGroupResult res        = (CreateGroupResult)BitConverter.ToInt32(bRes, 0);
                if (res == CreateGroupResult.GroupExisted)
                {
                    MessageBoxEx.Show("同ID的群已经存在!");
                    this.DialogResult = System.Windows.Forms.DialogResult.None;
                    return;
                }

                this.group        = new GGGroup(groupID, contract.Name, this.rapidPassiveEngine.CurrentUserID, "", this.rapidPassiveEngine.CurrentUserID);
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            catch (Exception ee)
            {
                MessageBoxEx.Show("创建群失败!" + ee.Message);
                this.DialogResult = System.Windows.Forms.DialogResult.None;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 创建分组
        /// </summary>
        /// <param name="accessToken">调用接口凭证</param>
        /// <param name="name">分组名称</param>
        /// <returns></returns>
        public GroupJson CreateGroup(string accessToken, string name)
        {
            string url  = string.Format("https://api.weixin.qq.com/cgi-bin/groups/create?access_token={0}", accessToken);
            var    data = new
            {
                group = new
                {
                    name = name
                }
            };
            string postData = data.ToJson();

            GroupJson         group  = null;
            CreateGroupResult result = JsonHelper <CreateGroupResult> .ConvertJson(url, postData);

            if (result != null)
            {
                group = result.group;
            }
            return(group);
        }
Exemplo n.º 3
0
        public CreateGroupResult Create(string title, string shortDescription)
        {
            var result = new CreateGroupResult();

            try
            {
                if (!_http.HttpContext.User.Identity.IsAuthenticated)
                {
                    return(new CreateGroupResult(401, "You must be logged in to this."));
                }

                var user = _userManager.GetUserAsync(_http.HttpContext.User).Result;

                if (!String.IsNullOrEmpty(title))
                {
                    result.Title = "OK";
                }
                else
                {
                    result.Title = "NO";
                }

                if (!String.IsNullOrEmpty(shortDescription))
                {
                    result.Description = "OK";
                }
                else
                {
                    result.Description = "NO";
                }

                if (user != null)
                {
                    result.Owner = "OK";
                }
                else
                {
                    result.Owner = "NO";
                }

                if (result.Title == "NO" || result.Description == "NO" || result.Owner == "NO")
                {
                    result.Error      = "Not all required fields were filled.";
                    result.StatusCode = 412;
                    return(result);
                }
                else
                {
                    result.StatusCode = 200;

                    var newGroup = new Group {
                        ShortDescription = shortDescription, Title = title, Owner = user
                    };
                    result.Id = newGroup.Id;


                    _context.Groups.Add(newGroup);
                    _context.GroupTeam.Add(new GroupTeam
                    {
                        RequestDate  = DateTime.Today,
                        ApprovalDate = DateTime.Today,
                        Approved     = true,
                        Comment      = "Init",
                        GroupId      = newGroup.Id,
                        UserId       = user.Id
                    });
                    _context.SaveChanges();
                    result.Id = newGroup.Id;
                }

                return(result);
            }
            catch (Exception ex)
            {
                LogException(ex);
                return(new CreateGroupResult(400, ex.Message));
            }
        }
        /// <summary>
        /// 处理来自客户端的同步调用请求。
        /// </summary>
        public byte[] HandleQuery(string sourceUserID, int informationType, byte[] info)
        {
            if (informationType == InformationTypes.GetFriendIDList)
            {
                List <string> friendIDs = this.globalCache.GetFriends(sourceUserID);
                return(CompactPropertySerializer.Default.Serialize <List <string> >(friendIDs));
            }

            if (informationType == InformationTypes.AddFriend)
            {
                AddFriendContract contract = CompactPropertySerializer.Default.Deserialize <AddFriendContract>(info, 0);
                bool isExist = this.globalCache.IsUserExist(contract.FriendID);
                if (!isExist)
                {
                    return(BitConverter.GetBytes((int)AddFriendResult.FriendNotExist));
                }
                this.globalCache.AddFriend(sourceUserID, contract.FriendID, contract.CatalogName);

                //0922
                GGUser owner     = this.globalCache.GetUser(sourceUserID);
                byte[] ownerBuff = CompactPropertySerializer.Default.Serialize <GGUser>(owner);

                //通知对方
                this.rapidServerEngine.CustomizeController.Send(contract.FriendID, InformationTypes.FriendAddedNotify, ownerBuff, true, ESFramework.ActionTypeOnChannelIsBusy.Continue);
                return(BitConverter.GetBytes((int)AddFriendResult.Succeed));
            }

            if (informationType == InformationTypes.GetAllContacts)
            {
                List <string> contacts = this.globalCache.GetAllContacts(sourceUserID);
                Dictionary <string, GGUser> contactDic = new Dictionary <string, GGUser>();
                foreach (string friendID in contacts)
                {
                    if (!contactDic.ContainsKey(friendID))
                    {
                        GGUser friend = this.globalCache.GetUser(friendID);
                        if (friend != null)
                        {
                            contactDic.Add(friendID, friend);
                        }
                    }
                }

                return(CompactPropertySerializer.Default.Serialize <List <GGUser> >(new List <GGUser>(contactDic.Values)));
            }

            if (informationType == InformationTypes.GetSomeUsers)
            {
                List <string> friendIDs = CompactPropertySerializer.Default.Deserialize <List <string> >(info, 0);
                List <GGUser> friends   = new List <GGUser>();
                foreach (string friendID in friendIDs)
                {
                    GGUser friend = this.globalCache.GetUser(friendID);
                    if (friend != null)
                    {
                        friends.Add(friend);
                    }
                }

                return(CompactPropertySerializer.Default.Serialize <List <GGUser> >(friends));
            }

            if (informationType == InformationTypes.GetContactsRTData)
            {
                List <string> contacts = this.globalCache.GetAllContacts(sourceUserID);
                Dictionary <string, UserRTData> dic = new Dictionary <string, UserRTData>();
                foreach (string friendID in contacts)
                {
                    if (!dic.ContainsKey(friendID))
                    {
                        GGUser data = this.globalCache.GetUser(friendID);
                        if (data != null)
                        {
                            UserRTData rtData = new UserRTData(data.UserStatus, data.Version);
                            dic.Add(friendID, rtData);
                        }
                    }
                }
                Dictionary <string, int> groupVerDic = this.globalCache.GetMyGroupVersions(sourceUserID);
                ContactsRTDataContract   contract    = new ContactsRTDataContract(dic, groupVerDic);
                return(CompactPropertySerializer.Default.Serialize(contract));
            }

            if (informationType == InformationTypes.GetUserInfo)
            {
                string target = System.Text.Encoding.UTF8.GetString(info);
                GGUser user   = this.globalCache.GetUser(target);
                if (user == null)
                {
                    return(null);
                }
                if (sourceUserID != target)  //0922
                {
                    user = user.PartialCopy;
                }
                return(CompactPropertySerializer.Default.Serialize <GGUser>(user));
            }

            if (informationType == InformationTypes.GetMyGroups)
            {
                List <GGGroup> myGroups = this.globalCache.GetMyGroups(sourceUserID);
                return(CompactPropertySerializer.Default.Serialize(myGroups));
            }

            if (informationType == InformationTypes.GetSomeGroups)
            {
                List <string>  groups   = ESPlus.Serialization.CompactPropertySerializer.Default.Deserialize <List <string> >(info, 0);
                List <GGGroup> myGroups = new List <GGGroup>();
                foreach (string groupID in groups)
                {
                    GGGroup group = this.globalCache.GetGroup(groupID);
                    if (group != null)
                    {
                        myGroups.Add(group);
                    }
                }

                return(CompactPropertySerializer.Default.Serialize(myGroups));
            }

            if (informationType == InformationTypes.JoinGroup)
            {
                string          groupID = System.Text.Encoding.UTF8.GetString(info);
                JoinGroupResult res     = this.globalCache.JoinGroup(sourceUserID, groupID);
                if (res == JoinGroupResult.Succeed)
                {
                    //通知其它组成员
                    this.rapidServerEngine.ContactsController.Broadcast(groupID, BroadcastTypes.SomeoneJoinGroup, System.Text.Encoding.UTF8.GetBytes(sourceUserID), null, ESFramework.ActionTypeOnChannelIsBusy.Continue);
                }
                return(BitConverter.GetBytes((int)res));
            }

            if (informationType == InformationTypes.CreateGroup)
            {
                CreateGroupContract contract = CompactPropertySerializer.Default.Deserialize <CreateGroupContract>(info, 0);
                CreateGroupResult   res      = this.globalCache.CreateGroup(sourceUserID, contract.ID, contract.Name, contract.Announce);
                return(BitConverter.GetBytes((int)res));
            }

            if (informationType == InformationTypes.GetGroup)
            {
                string  groupID = System.Text.Encoding.UTF8.GetString(info);
                GGGroup group   = this.globalCache.GetGroup(groupID);
                return(CompactPropertySerializer.Default.Serialize(group));
            }

            if (informationType == InformationTypes.ChangePassword)
            {
                ChangePasswordContract contract = CompactPropertySerializer.Default.Deserialize <ChangePasswordContract>(info, 0);
                ChangePasswordResult   res      = this.globalCache.ChangePassword(sourceUserID, contract.OldPasswordMD5, contract.NewPasswordMD5);
                return(BitConverter.GetBytes((int)res));
            }
            return(null);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 创建微信分组
        /// </summary>
        /// <param name="strAccessToken"></param>
        /// <param name="strGroupName"></param>
        /// <returns></returns>
        public CreateGroupResult CreateWXGroup(string strAccessToken, string strGroupName)
        {
            CreateGroupResult pResult = Senparc.Weixin.MP.AdvancedAPIs.GroupsApi.Create(strAccessToken, strGroupName);

            return(pResult);
        }