Exemplo n.º 1
0
        public void RemoveNotExistMemberInWeixin()
        {
            var list = _Repository.FindBy(null, 1, int.MaxValue);

            var accessToken = _commonService.GetContactsAccessToken();
            var members     = _contactsService.GetMembers(accessToken);

            var sbError = new StringBuilder();

            var deletedList = members.Where(x => !string.IsNullOrWhiteSpace(x.Userid) && !list.Select(d => d.Userid).Contains(x.Userid));

            foreach (var member in deletedList)
            {
                try
                {
                    _contactsService.DeleteMember(accessToken, member.Userid);
                }
                catch (Exception ex)
                {
                    sbError.AppendLine(string.Format("{0} {1}", member.Userid, ex.Message));
                }
            }

            if (sbError.Length > 0)
            {
                throw new Exception(sbError.ToString());
            }
        }