示例#1
0
 public async Task <List <WxUserTag> > GetUserTagsAsync(string accessTokenOrAppId)
 {
     return((await UserTagApi.GetAsync(accessTokenOrAppId)).tags.Select(tag =>
                                                                        new WxUserTag
     {
         Id = tag.id,
         Name = tag.name,
         Count = tag.count
     }).ToList());
 }
示例#2
0
        public ActionResult MenuManager()

        {
            AccessTokenContainer.Register("wx4df7108464fb86f1", "46515264f29685ba478ea93d44919ed5");
            var accessToken = AccessTokenContainer.GetAccessToken(AppId);


            var aa = UserTagApi.Get(accessToken);


            ButtonGroup bg = new ButtonGroup();

            //单击
            bg.button.Add(new SingleClickButton()
            {
                name = "单击测试",
                key  = "OneClick",
                type = ButtonType.click.ToString(),//默认已经设为此类型,这里只作为演示
            });

            //二级菜单
            var subButton = new SubButton()
            {
                name = "二级菜单"
            };

            subButton.sub_button.Add(new SingleClickButton()
            {
                key  = "SubClickRoot_Text",
                name = "返回文本"
            });
            subButton.sub_button.Add(new SingleClickButton()
            {
                key  = "SubClickRoot_News",
                name = "返回图文"
            });
            subButton.sub_button.Add(new SingleClickButton()
            {
                key  = "SubClickRoot_Music",
                name = "返回音乐"
            });
            subButton.sub_button.Add(new SingleViewButton()
            {
                url  = "http://weixin.senparc.com",
                name = "Url跳转"
            });
            bg.button.Add(subButton);
            var result = CommonApi.CreateMenu(accessToken, bg);

            return(View());
        }
        public async Task <int> GetTagIdAsync(UserTypeEnum typeSCode)
        {
            int    tagId   = 0;
            string tagName = "";
            //var fans1 = await UserTagApi.UserTagListAsync(AppConfig.AppId, "oPM5Uv81jfyJqWbVxWAH-RUqsCAs");

            var tags = await UserTagApi.GetAsync(AppConfig.AppId);

            var groupSe = await _wechatgroupRepository.GetAll().Where(G => G.TypeName == typeSCode.ToString()).FirstOrDefaultAsync();

            foreach (var item in tags.tags)
            {
                if (item.name == typeSCode.ToString())
                {
                    tagId   = item.id;
                    tagName = item.name;
                }
            }
            if (string.IsNullOrEmpty(tagName))
            {
                var result = await UserTagApi.CreateAsync(AppConfig.AppId, typeSCode.ToString());

                if (groupSe == null)
                {
                    WeChatGroupListDto group = new WeChatGroupListDto();
                    if (result.errcode == 0)
                    {
                        group.TagId    = result.tag.id;
                        group.TagName  = result.tag.name;
                        group.TypeName = typeSCode.ToString();
                        group.TypeCode = typeSCode;
                        await CreateWeChatGroupAsync(group.MapTo <WeChatGroupEditDto>());
                    }
                }
                return(result.tag.id);
            }
            else
            {
                if (groupSe == null)
                {
                    WeChatGroupListDto group = new WeChatGroupListDto();
                    group.TagId    = tagId;
                    group.TagName  = tagName;
                    group.TypeName = typeSCode.ToString();
                    group.TypeCode = typeSCode;
                    await CreateWeChatGroupAsync(group.MapTo <WeChatGroupEditDto>());
                }
                return(tagId);
            }
        }
示例#4
0
        /// <summary>
        /// 根据标签名称获取标签的Id;
        /// </summary>
        /// <param name="tagName"></param>
        /// <returns></returns>
        public int?GetTagId(string tagName)
        {
            var tagList = UserTagApi.Get(AccessToken);

            if (tagList.errcode != 0 || tagList.tags == null || tagList.tags.Count == 0)
            {
                return(null);
            }
            var tag = tagList.tags.FirstOrDefault(a => a.name == tagName);

            if (tag == null)
            {
                return(null);
            }
            return(tag.id);
        }
        /// <summary>
        ///检查在微信端是否已存在此标签
        /// </summary>
        /// <param name="tagName"></param>
        /// <returns></returns>
        public async Task <CheckResult> CheckTagName(string tagName)
        {
            var tags = await UserTagApi.GetAsync(AppConfig.AppId);

            var result = new CheckResult();

            foreach (var item in tags.tags)
            {
                if (item.name == tagName)
                {
                    result.IsExist = true;
                    result.TagId   = item.id;
                    break;
                }
            }
            return(result);
        }
        /// <summary>
        /// 批量标记用户分组
        /// </summary>
        /// <returns></returns>
        public async Task BatchMarkWeChatGroup()
        {
            //try
            //{
            //}
            //catch (Exception ex)
            //{

            //}
            var weChatGroupList = await _wechatgroupRepository.GetAllListAsync();

            foreach (var item in weChatGroupList)
            {
                //if(item.TypeCode!= UserTypeEnum.消费者)
                //{
                var count = await _wechatuserRepository.GetAll().Where(g => g.UserType == item.TypeCode && g.BindStatus == BindStatusEnum.已绑定).Select(g => g.OpenId).CountAsync();

                if (count > 0)
                {
                    int cycleCount = count / 50 + (count % 50 == 0 ? 0 : 1);
                    for (var i = 0; i < cycleCount; i++)
                    {
                        var weChatUser = await _wechatuserRepository.GetAll().Where(g => g.UserType == item.TypeCode && g.BindStatus == BindStatusEnum.已绑定).Skip(i * 50).Take(50).Select(g => g.OpenId).ToListAsync();

                        var result = await UserTagApi.BatchTaggingAsync(AppConfig.AppId, item.TagId, weChatUser);

                        //if (result.errcode != 0)
                        //{
                        //    return new APIResultDto() { Code = 0, Msg = "标记失败" };
                        //}
                    }
                }
                //}
            }
            //return new APIResultDto() { Code = 0, Msg = "标记成功" };
        }
示例#7
0
 public async Task UserBatchUnTaggingAsync(string accessTokenOrAppId, int tagId, List <string> openIds)
 {
     await UserTagApi.BatchUntaggingAsync(accessTokenOrAppId, tagId, openIds);
 }
示例#8
0
 public async Task DeleteUserTag(string accessTokenOrAppId, int tagId)
 {
     await UserTagApi.DeleteAsync(accessTokenOrAppId, tagId);
 }
示例#9
0
 public async Task UpdateUserTag(string accessTokenOrAppId, int tagId, string tagName)
 {
     await UserTagApi.UpdateAsync(accessTokenOrAppId, tagId, tagName);
 }
示例#10
0
 public async Task AddUserTag(string accessTokenOrAppId, string tagName)
 {
     await UserTagApi.CreateAsync(accessTokenOrAppId, tagName);
 }
示例#11
0
 public async Task CancelTagAsync(int tagId, List <string> openIds)
 {
     //List<string> openIds = new List<string>();
     //openIds.Add(openId);
     var result = await UserTagApi.BatchUntaggingAsync(AppConfig.AppId, tagId, openIds);
 }
示例#12
0
 /// <summary>
 /// 获取用户上的标签
 /// </summary>
 /// <returns></returns>
 public async Task GetUserForWeChatUser()
 {
     var openId = "";
     await UserTagApi.UserTagListAsync(AppConfig.AppId, openId);
 }
示例#13
0
 /// <summary>
 /// 获取在微信中的分组(标签)
 /// </summary>
 /// <returns></returns>
 public async Task GetWeChatGroupFromWeChat()
 {
     await UserTagApi.GetAsync(AppConfig.AppId);
 }