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

Developer #2254

Merged
merged 11 commits into from
Oct 13, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
修改标识:lishewen - 20200318
修改描述:v3.7.401 新增“获取客户群列表”“获取客户群详情” API

修改标识:gokeiyou - 20201013
修改描述:v3.7.604 添加外部联系人管理 > 客户管理相关接口

----------------------------------------------------------------*/

/*
Expand All @@ -20,6 +23,7 @@
using Senparc.Weixin.CommonAPIs;
using Senparc.Weixin.Entities;
using Senparc.Weixin.Work.AdvancedAPIs.External;
using Senparc.Weixin.Work.AdvancedAPIs.External.ExternalJson;
using System.Threading.Tasks;

namespace Senparc.Weixin.Work.AdvancedAPIs
Expand Down Expand Up @@ -119,6 +123,91 @@ public static GroupChatGetResult GroupChatGet(string accessTokenOrAppKey, string
}, accessTokenOrAppKey);

}

#region 客户管理

/// <summary>
/// 获取客户列表
/// </summary>
/// <param name="accessTokenOrAppKey">调用接口凭证</param>
/// <param name="userid">企业成员的userid</param>
/// <param name="timeOut"></param>
/// <returns></returns>
[ApiBind(NeuChar.PlatformType.WeChat_Work, "ExternalApi.GetExternalContactList", true)]
public static GetExternalContactListResult GetExternalContactList(string accessTokenOrAppKey, string userid, int timeOut = Config.TIME_OUT)
{
return ApiHandlerWapper.TryCommonApi(accessToken =>
{
var url = $"{Config.ApiWorkHost}/cgi-bin/externalcontact/list?access_token={accessToken}&userid={userid}";

return CommonJsonSend.Send<GetExternalContactListResult>(null, url, null, CommonJsonSendType.GET, timeOut);
}, accessTokenOrAppKey);
}

/// <summary>
/// 获取客户详情
/// </summary>
/// <param name="accessTokenOrAppKey">调用接口凭证</param>
/// <param name="externalUserId">外部联系人的userid,注意不是企业成员的帐号</param>
/// <param name="timeOut"></param>
/// <returns></returns>
[ApiBind(NeuChar.PlatformType.WeChat_Work, "ExternalApi.GetExternalContactInfo", true)]
public static GetExternalContactResultJson GetExternalContactInfo(string accessTokenOrAppKey, string externalUserId, int timeOut = Config.TIME_OUT)
{
return ApiHandlerWapper.TryCommonApi(accessToken =>
{
var url = $"{Config.ApiWorkHost}/cgi-bin/externalcontact/get?access_token={accessToken}&external_userid={externalUserId}";

return CommonJsonSend.Send<GetExternalContactResultJson>(null, url, null, CommonJsonSendType.GET, timeOut);
}, accessTokenOrAppKey);
}

/// <summary>
/// 批量获取客户详情
/// </summary>
/// <param name="accessTokenOrAppKey"></param>
/// <param name="userid"></param>
/// <param name="cursor"></param>
/// <param name="limit"></param>
/// <param name="timeOut"></param>
[ApiBind(NeuChar.PlatformType.WeChat_Work, "ExternalApi.GetExternalContactInfoBatch", true)]
public static GetExternalContactInfoBatchResult GetExternalContactInfoBatch(string accessTokenOrAppKey, string userid, string cursor = "", int limit = 50, int timeOut = Config.TIME_OUT)
{
return ApiHandlerWapper.TryCommonApi(accessToken =>
{
var url = $"{Config.ApiWorkHost}/cgi-bin/externalcontact/batch/get_by_user?access_token={accessToken}";

var data = new
{
userid,
cursor,
limit
};

return CommonJsonSend.Send<GetExternalContactInfoBatchResult>(null, url, data, CommonJsonSendType.POST, timeOut);
}, accessTokenOrAppKey);
}

/// <summary>
/// 修改客户备注信息
/// </summary>
/// <param name="accessTokenOrAppKey">调用接口凭证</param>
/// <param name="rquest">请求报文</param>
/// <param name="timeOut"></param>
/// <returns></returns>
[ApiBind(NeuChar.PlatformType.WeChat_Work, "ExternalApi.UpdateExternalContactRemark", true)]
public static WorkJsonResult UpdateExternalContactRemark(string accessTokenOrAppKey, UpdateExternalContactRemarkRequest rquest, int timeOut = Config.TIME_OUT)
{
return ApiHandlerWapper.TryCommonApi(accessToken =>
{
var url = $"{Config.ApiWorkHost}/cgi-bin/externalcontact/remark?access_token={accessToken}";

return CommonJsonSend.Send<WorkJsonResult>(null, url, rquest, CommonJsonSendType.POST, timeOut);
}, accessTokenOrAppKey);
}

#endregion

#endregion


Expand Down Expand Up @@ -212,6 +301,91 @@ public static async Task<GroupChatGetResult> GroupChatGetAsync(string accessToke
}, accessTokenOrAppKey).ConfigureAwait(false);

}

#region 客户管理

/// <summary>
/// 【异步方法】获取客户列表
/// </summary>
/// <param name="accessTokenOrAppKey">调用接口凭证</param>
/// <param name="userid">企业成员的userid</param>
/// <param name="timeOut"></param>
/// <returns></returns>
[ApiBind(NeuChar.PlatformType.WeChat_Work, "ExternalApi.GetExternalContactListAsync", true)]
public static async Task<GetExternalContactListResult> GetExternalContactListAsync(string accessTokenOrAppKey, string userid, int timeOut = Config.TIME_OUT)
{
return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
{
var url = $"{Config.ApiWorkHost}/cgi-bin/externalcontact/list?access_token={accessToken}&userid={userid}";

return await CommonJsonSend.SendAsync<GetExternalContactListResult>(null, url, null, CommonJsonSendType.GET, timeOut).ConfigureAwait(false);
}, accessTokenOrAppKey).ConfigureAwait(false);
}

/// <summary>
/// 【异步方法】获取客户详情
/// </summary>
/// <param name="accessTokenOrAppKey">调用接口凭证</param>
/// <param name="externalUserId">外部联系人的userid,注意不是企业成员的帐号</param>
/// <param name="timeOut"></param>
/// <returns></returns>
[ApiBind(NeuChar.PlatformType.WeChat_Work, "ExternalApi.GetExternalContactInfoAsync", true)]
public static async Task<GetExternalContactResultJson> GetExternalContactInfoAsync(string accessTokenOrAppKey, string externalUserId, int timeOut = Config.TIME_OUT)
{
return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
{
var url = $"{Config.ApiWorkHost}/cgi-bin/externalcontact/get?access_token={accessToken}&external_userid={externalUserId}";

return await CommonJsonSend.SendAsync<GetExternalContactResultJson>(null, url, null, CommonJsonSendType.GET, timeOut).ConfigureAwait(false);
}, accessTokenOrAppKey).ConfigureAwait(false);
}

/// <summary>
/// 【异步方法】批量获取客户详情
/// </summary>
/// <param name="accessTokenOrAppKey"></param>
/// <param name="userid"></param>
/// <param name="cursor"></param>
/// <param name="limit"></param>
/// <param name="timeOut"></param>
[ApiBind(NeuChar.PlatformType.WeChat_Work, "ExternalApi.GetExternalContactInfoBatchAsync", true)]
public static async Task<GetExternalContactInfoBatchResult> GetExternalContactInfoBatchAsync(string accessTokenOrAppKey, string userid, string cursor = "", int limit = 50, int timeOut = Config.TIME_OUT)
{
return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
{
var url = $"{Config.ApiWorkHost}/cgi-bin/externalcontact/batch/get_by_user?access_token={accessToken}";

var data = new
{
userid,
cursor,
limit
};

return await CommonJsonSend.SendAsync<GetExternalContactInfoBatchResult>(null, url, data, CommonJsonSendType.POST, timeOut).ConfigureAwait(false);
}, accessTokenOrAppKey).ConfigureAwait(false);
}

/// <summary>
/// 修改客户备注信息
/// </summary>
/// <param name="accessTokenOrAppKey">调用接口凭证</param>
/// <param name="rquest">请求报文</param>
/// <param name="timeOut"></param>
/// <returns></returns>
[ApiBind(NeuChar.PlatformType.WeChat_Work, "ExternalApi.UpdateExternalContactRemarkAsync", true)]
public static async Task<WorkJsonResult> UpdateExternalContactRemarkAsync(string accessTokenOrAppKey, UpdateExternalContactRemarkRequest rquest, int timeOut = Config.TIME_OUT)
{
return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
{
var url = $"{Config.ApiWorkHost}/cgi-bin/externalcontact/remark?access_token={accessToken}";

return await CommonJsonSend.SendAsync<WorkJsonResult>(null, url, rquest, CommonJsonSendType.POST, timeOut).ConfigureAwait(false);
}, accessTokenOrAppKey).ConfigureAwait(false);
}

#endregion

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*----------------------------------------------------------------
Copyright (C) 2020 Senparc

文件名:GetExternalContactInfoBatchResult.cs
文件功能描述:批量获取客户详情 返回结果


创建标识:gokeiyou - 20201013

----------------------------------------------------------------*/

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
{
/// <summary>
/// 批量获取客户详情 返回结果
/// </summary>
public class GetExternalContactInfoBatchResult : WorkJsonResult
{
/// <summary>
///
/// </summary>
public List<ExternalContactList> external_contact_list { get; set; }

/// <summary>
/// 分页游标,再下次请求时填写以获取之后分页的记录,如果已经没有更多的数据则返回空
/// </summary>
public string next_cursor { get; set; }
}

public class ExternalContactList
{
public ExternalContact external_contact { get; set; }
public FollowUser follow_info { get; set; }
}


public class ExternalContact
{
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 FollowUser
{
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; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*----------------------------------------------------------------
Copyright (C) 2020 Senparc

文件名:GetExternalContactInfoBatchResult.cs
文件功能描述:批量获取客户详情 返回结果


创建标识:gokeiyou - 20201013

----------------------------------------------------------------*/

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
{
/// <summary>
/// 获取客户列表返回实体
/// </summary>
public class GetExternalContactListResult : WorkJsonResult
{
/// <summary>
/// 外部联系人的userid列表
/// </summary>
public List<string> external_userid { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*----------------------------------------------------------------
Copyright (C) 2020 Senparc

文件名:GetExternalContactInfoBatchResult.cs
文件功能描述:批量获取客户详情 返回结果


创建标识:gokeiyou - 20201013

----------------------------------------------------------------*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Senparc.Weixin.Work.AdvancedAPIs.External.ExternalJson
{
public class UpdateExternalContactRemarkRequest
{
/// <summary>
/// 企业成员的userid
/// </summary>
public string userid { get; set; }
/// <summary>
/// 外部联系人userid
/// </summary>
public string external_userid { get; set; }
/// <summary>
/// 此用户对外部联系人的备注,最多20个字符
/// </summary>
public string remark { get; set; }
/// <summary>
/// 此用户对外部联系人的描述,最多150个字符
/// </summary>
public string description { get; set; }
/// <summary>
/// 此用户对外部联系人备注的所属公司名称,最多20个字符
/// </summary>
public string remark_company { get; set; }
/// <summary>
/// 此用户对外部联系人备注的手机号
/// </summary>
public string[] remark_mobiles { get; set; }
/// <summary>
/// 备注图片的mediaid
/// </summary>
public string remark_pic_mediaid { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
修改标识:OrchesAdam - 20200430
修改描述:v3.7.502 添加编辑企业客户事件

修改标识:gokeiyou - 20201013
修改描述:v3.7.604 添加外部联系人管理 > 客户管理相关接口

----------------------------------------------------------------*/

namespace Senparc.Weixin.Work.Entities.Request.Event
Expand All @@ -22,6 +25,8 @@ namespace Senparc.Weixin.Work.Entities.Request.Event
/// </summary>
public interface IRequestMessageEvent_Change_ExternalContact_Base : IRequestMessageEventBase
{
string SuiteId { get; set; }
string AuthCorpId { get; set; }
ExternalContactChangeType ChangeType
{
get;
Expand All @@ -30,6 +35,8 @@ ExternalContactChangeType ChangeType

public class RequestMessageEvent_Change_ExternalContact_Base : RequestMessageEventBase, IRequestMessageEvent_Change_ExternalContact_Base
{
public string SuiteId { get; set; }
public string AuthCorpId { get; set; }
public override Work.Event Event
{
get { return Work.Event.CHANGE_EXTERNAL_CONTACT; }
Expand Down
Loading