Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supplement #2414

Merged
merged 17 commits into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ bak.zip
*.pdb
*.tmp

# JetBrains Rider
.idea/

#/Tools/*
*.DotSettings
.vs
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System.Collections.Generic;
using Senparc.Weixin.Entities;

namespace Senparc.Weixin.Work.AdvancedAPIs.CustomerTag
{
public class GetCorpTagListResult : WorkJsonResult
{
public List<CorpTagGroup> tag_group { get; set; }
}

public class AddCorpCustomerTagResult : WorkJsonResult
{
public CorpTagGroup tag_group { get; set; }
}

public class EditCorpCustomerTagRequest
{
/// <summary>
/// 标签或标签组的id
/// </summary>
public string id { get; set; }
/// <summary>
/// 新的标签或标签组名称,最长为30个字符
/// </summary>
public string name { get; set; }
/// <summary>
/// 标签/标签组的次序值
/// order值大的排序靠前。有效的值范围是[0, 2^32)
/// </summary>
public int order { get; set; }
}

public class DeleteCorpCustomerTagRequest
{
public List<string> tag_id { get; set; }
public List<string> group_id { get; set; }
}

public class ExternalContactMarkTagRequest
{
public string userid { get; set; }
public string external_userid { get; set; }
public List<string> add_tag { get; set; }
public List<string> remove_tag { get; set; }
}

public class CorpTagGroup
{
public string group_id { get; set; }
public string group_name { get; set; }
public long create_time { get; set; }
public long order { get; set; }
public bool deleted { get; set; }
public List<CorpTag> tag { get; set; }
}

public class CorpTag
{
public string id { get; set; }
public string name { get; set; }
public long create_time { get; set; }
public long order { get; set; }
public bool deleted { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
using System.Threading.Tasks;
using Senparc.CO2NET.Extensions;
using Senparc.NeuChar;
using Senparc.Weixin.Entities;

namespace Senparc.Weixin.Work.AdvancedAPIs.CustomerTag
{
/// <summary>
/// 客户标签管理Api
/// </summary>
public class CustomerTagApi
{

#region 同步方法

/// <summary>
/// 获取企业标签库
/// </summary>
/// <param name="accessTokenOrAppKey"></param>
/// <param name="timeOut"></param>
/// <returns></returns>
[ApiBind(NeuChar.PlatformType.WeChat_Work, "CustomerTagApi.GetCustomerTagList", true)]
public static GetCorpTagListResult GetCustomerTagList(string accessTokenOrAppKey, int timeOut = Config.TIME_OUT)
{
return ApiHandlerWapper.TryCommonApi(accessToken =>
{
var url = string.Format(Config.ApiWorkHost + "/cgi-bin/externalcontact/get_corp_tag_list?access_token={0}", accessToken.AsUrlData());

return Senparc.Weixin.CommonAPIs.CommonJsonSend.Send<GetCorpTagListResult>(accessToken, url, null, CommonJsonSendType.POST, timeOut);
}, accessTokenOrAppKey);
}

/// <summary>
/// 添加企业客户标签
/// </summary>
/// <param name="accessTokenOrAppKey"></param>
/// <param name="data"></param>
/// <param name="timeOut"></param>
[ApiBind(NeuChar.PlatformType.WeChat_Work, "CustomerTagApi.AddCorpCustomerTag", true)]
public static AddCorpCustomerTagResult AddCorpCustomerTag(string accessTokenOrAppKey, CorpTagGroup data, int timeOut = Config.TIME_OUT)
{
return ApiHandlerWapper.TryCommonApi(accessToken =>
{
var url = string.Format(Config.ApiWorkHost + "/cgi-bin/externalcontact/add_corp_tag?access_token={0}", accessToken.AsUrlData());

return Senparc.Weixin.CommonAPIs.CommonJsonSend.Send<AddCorpCustomerTagResult>(accessToken, url, data, timeOut: timeOut);
}, accessTokenOrAppKey);
}

/// <summary>
/// 编辑企业客户标签
/// </summary>
/// <param name="accessTokenOrAppKey"></param>
/// <param name="data"></param>
/// <param name="timeOut"></param>
/// <returns></returns>
[ApiBind(NeuChar.PlatformType.WeChat_Work, "CustomerTagApi.EditCorpCustomerTag", true)]
public static WorkJsonResult EditCorpCustomerTag(string accessTokenOrAppKey, EditCorpCustomerTagRequest data, int timeOut = Config.TIME_OUT)
{
return ApiHandlerWapper.TryCommonApi(accessToken =>
{
var url = string.Format(Config.ApiWorkHost + "/cgi-bin/externalcontact/edit_corp_tag?access_token={0}", accessToken.AsUrlData());

return Senparc.Weixin.CommonAPIs.CommonJsonSend.Send<WorkJsonResult>(accessToken, url, data, timeOut: timeOut);
}, accessTokenOrAppKey);
}

/// <summary>
/// 删除企业客户标签
/// </summary>
/// <param name="accessTokenOrAppKey"></param>
/// <param name="data"></param>
/// <param name="timeOut"></param>
/// <returns></returns>
[ApiBind(NeuChar.PlatformType.WeChat_Work, "CustomerTagApi.DeleteCorpCustomerTag", true)]
public static WorkJsonResult DeleteCorpCustomerTag(string accessTokenOrAppKey, DeleteCorpCustomerTagRequest data, int timeOut = Config.TIME_OUT)
{
return ApiHandlerWapper.TryCommonApi(accessToken =>
{
var url = string.Format(Config.ApiWorkHost + "/cgi-bin/externalcontact/del_corp_tag?access_token={0}", accessToken.AsUrlData());

return Senparc.Weixin.CommonAPIs.CommonJsonSend.Send<WorkJsonResult>(accessToken, url, data, timeOut: timeOut);
}, accessTokenOrAppKey);
}

/// <summary>
/// 编辑客户企业标签标签
/// </summary>
/// <param name="accessTokenOrAppKey"></param>
/// <param name="data"></param>
/// <param name="timeOut"></param>
/// <returns></returns>
[ApiBind(NeuChar.PlatformType.WeChat_Work, "CustomerTagApi.ExternalContactMarkTag", true)]
public static WorkJsonResult ExternalContactMarkTag(string accessTokenOrAppKey, ExternalContactMarkTagRequest data, int timeOut = Config.TIME_OUT)
{
return ApiHandlerWapper.TryCommonApi(accessToken =>
{
var url = string.Format(Config.ApiWorkHost + "/cgi-bin/externalcontact/mark_tag?access_token={0}", accessToken.AsUrlData());

return Senparc.Weixin.CommonAPIs.CommonJsonSend.Send<WorkJsonResult>(accessToken, url, data, timeOut: timeOut);
}, accessTokenOrAppKey);
}

#endregion

#region 异步方法

/// <summary>
/// 获取企业标签库
/// </summary>
/// <param name="accessTokenOrAppkey"></param>
/// <param name="timeOut"></param>
/// <returns></returns>
[ApiBind(NeuChar.PlatformType.WeChat_Work, "CustomerTagApi.GetCustomerTagListAsync", true)]
public static async Task<GetCorpTagListResult> GetCustomerTagListAsync(string accessTokenOrAppkey, int timeOut = Config.TIME_OUT)
{
return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
{
var url = string.Format(Config.ApiWorkHost + "/cgi-bin/externalcontact/get_corp_tag_list?access_token={0}", accessToken.AsUrlData());

return await Weixin.CommonAPIs.CommonJsonSend.SendAsync<GetCorpTagListResult>(accessToken, url, null, CommonJsonSendType.POST, timeOut).ConfigureAwait(false);
}, accessTokenOrAppkey).ConfigureAwait(false);
}

/// <summary>
/// 添加企业客户标签
/// </summary>
/// <param name="accessTokenOrAppKey"></param>
/// <param name="data"></param>
/// <param name="timeOut"></param>
[ApiBind(NeuChar.PlatformType.WeChat_Work, "CustomerTagApi.AddCorpCustomerTagAsync", true)]
public static async Task<AddCorpCustomerTagResult> AddCorpCustomerTagAsync(string accessTokenOrAppKey, CorpTagGroup data, int timeOut = Config.TIME_OUT)
{
return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
{
var url = string.Format(Config.ApiWorkHost + "/cgi-bin/externalcontact/add_corp_tag?access_token={0}", accessToken.AsUrlData());

return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<AddCorpCustomerTagResult>(accessToken, url, data, timeOut: timeOut).ConfigureAwait(false);
}, accessTokenOrAppKey).ConfigureAwait(false);
}

/// <summary>
/// 编辑企业客户标签
/// </summary>
/// <param name="accessTokenOrAppKey"></param>
/// <param name="data"></param>
/// <param name="timeOut"></param>
/// <returns></returns>
[ApiBind(NeuChar.PlatformType.WeChat_Work, "CustomerTagApi.EditCorpCustomerTagAsync", true)]
public static async Task<WorkJsonResult> EditCorpCustomerTagAsync(string accessTokenOrAppKey, EditCorpCustomerTagRequest data, int timeOut = Config.TIME_OUT)
{
return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
{
var url = string.Format(Config.ApiWorkHost + "/cgi-bin/externalcontact/edit_corp_tag?access_token={0}", accessToken.AsUrlData());

return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<WorkJsonResult>(accessToken, url, data, timeOut: timeOut).ConfigureAwait(false);
}, accessTokenOrAppKey).ConfigureAwait(false);
}

/// <summary>
/// 删除企业客户标签
/// </summary>
/// <param name="accessTokenOrAppKey"></param>
/// <param name="data"></param>
/// <param name="timeOut"></param>
/// <returns></returns>
[ApiBind(NeuChar.PlatformType.WeChat_Work, "CustomerTagApi.DeleteCorpCustomerTagAsync", true)]
public static async Task<WorkJsonResult> DeleteCorpCustomerTagAsync(string accessTokenOrAppKey, DeleteCorpCustomerTagRequest data, int timeOut = Config.TIME_OUT)
{
return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
{
var url = string.Format(Config.ApiWorkHost + "/cgi-bin/externalcontact/del_corp_tag?access_token={0}", accessToken.AsUrlData());

return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<WorkJsonResult>(accessToken, url, data, timeOut: timeOut).ConfigureAwait(false);
}, accessTokenOrAppKey).ConfigureAwait(false);
}

/// <summary>
/// 编辑客户企业标签标签
/// </summary>
/// <param name="accessTokenOrAppKey"></param>
/// <param name="data"></param>
/// <param name="timeOut"></param>
/// <returns></returns>
[ApiBind(NeuChar.PlatformType.WeChat_Work, "CustomerTagApi.ExternalContactMarkTagAsync", true)]
public static async Task<WorkJsonResult> ExternalContactMarkTagAsync(string accessTokenOrAppKey, ExternalContactMarkTagRequest data, int timeOut = Config.TIME_OUT)
{
return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
{
var url = string.Format(Config.ApiWorkHost + "/cgi-bin/externalcontact/mark_tag?access_token={0}", accessToken.AsUrlData());

return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<WorkJsonResult>(accessToken, url, data, timeOut: timeOut).ConfigureAwait(false);
}, accessTokenOrAppKey).ConfigureAwait(false);
}

#endregion

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Collections.Generic;
using Senparc.Weixin.Work.Entities.Models;

namespace Senparc.Weixin.Work.AdvancedAPIs.External.ExternalJson
{
/// <summary>
/// 添加企业群发消息任务参数实体
/// </summary>
public class AddMsgTemplateRequest
{
/// <summary>
/// 群发任务的类型,默认为single,表示发送给客户,group表示发送给客户群
/// </summary>
public string chat_type { get; set; } = "single";
/// <summary>
/// 客户的外部联系人id列表,仅在chat_type为single时有效,不可与sender同时为空,最多可传入1万个客户
/// </summary>
public List<string> external_userid { get; set; }
/// <summary>
/// 发送企业群发消息的成员userid,当类型为发送给客户群时必填
/// </summary>
public string sender { get; set; }
/// <summary>
/// 文本消息
/// </summary>
public MessageText text { get; set; }
/// <summary>
/// 图片消息
/// </summary>
public MessageImage image { get; set; }
/// <summary>
/// 图文消息
/// </summary>
public MessageLink link { get; set; }
/// <summary>
/// 小程序消息
/// </summary>
public MessageMiniprogram miniprogram { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using Senparc.Weixin.Entities;

namespace Senparc.Weixin.Work.AdvancedAPIs.External.ExternalJson
{
/// <summary>
///
/// </summary>
public class AddMsgTemplateResult : WorkJsonResult
{
public List<string> fail_list { get; set; }
public string msgid { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Senparc.Weixin.Entities;

namespace Senparc.Weixin.Work.AdvancedAPIs.External.ExternalJson
{
public class GetExternalContactInfoResult : WorkJsonResult
{
public ExternalContactInfo external_contact { get; set; }
public FollowUserInfo follow_user { get; set; }
}

public class ExternalContactInfo
{
public string external_userid { get; set; }
public string name { get; set; }
public int type { get; set; }
public string avatar { get; set; }
public int gender { get; set; }
public string unionid { get; set; }
}

public class FollowUserInfo
{
public string remark { get; set; }
public string description { get; set; }
public long creattime { get; set; }
public string[] tag_id { get; set; }
public string[] remark_mobiles { get; set; }
public int add_way { get; set; }
public string remark_corp_name { get; set; }
public string oper_userid { get; set; }
public string state { get; set; }
}
}
Loading