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);
            }
        }
示例#2
0
 public async Task AddUserTag(string accessTokenOrAppId, string tagName)
 {
     await UserTagApi.CreateAsync(accessTokenOrAppId, tagName);
 }