Skip to content

Commit 71e6433

Browse files
authored
Merge pull request #3061 from JeffreySu/Developer-SM
Developer sm
2 parents 29809fa + 8771243 commit 71e6433

File tree

7 files changed

+719
-8
lines changed

7 files changed

+719
-8
lines changed
Lines changed: 346 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,346 @@
1+
#region Apache License Version 2.0
2+
3+
/*----------------------------------------------------------------
4+
5+
Copyright 2024 Jeffrey Su & Suzhou Senparc Network Technology Co.,Ltd.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
8+
except in compliance with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software distributed under the
13+
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14+
either express or implied. See the License for the specific language governing permissions
15+
and limitations under the License.
16+
17+
Detail: https://github.com/JeffreySu/WeiXinMPSDK/blob/master/license.md
18+
19+
----------------------------------------------------------------*/
20+
21+
#endregion Apache License Version 2.0
22+
23+
/*----------------------------------------------------------------
24+
Copyright (C) 2024 Senparc
25+
26+
文件名:CustomerAcquisitionApi.cs
27+
文件功能描述:获客链接管理Api
28+
文档地址: https://developer.work.weixin.qq.com/document/path/97297
29+
30+
创建标识:IcedMango - 20240809
31+
32+
----------------------------------------------------------------*/
33+
using System.Threading.Tasks;
34+
using Senparc.CO2NET.Extensions;
35+
using Senparc.NeuChar;
36+
using Senparc.Weixin.Entities;
37+
using Senparc.Weixin.Work.AdvancedAPIs.CustomerAcquisition.CustomerAcquisitionJson;
38+
39+
namespace Senparc.Weixin.Work.AdvancedAPIs.CustomerAcquisition
40+
{
41+
/// <summary>
42+
/// 获客链接管理Api
43+
/// </summary>
44+
public class CustomerAcquisitionApi
45+
{
46+
#region 同步方法
47+
48+
/// <summary>
49+
/// 获取获客链接列表
50+
/// </summary>
51+
/// <param name="accessTokenOrAppKey"></param>
52+
/// <param name="limit">返回的最大记录数,整型,最大值100</param>
53+
/// <param name="cursor">用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填</param>
54+
/// <param name="timeOut"></param>
55+
/// <returns></returns>
56+
[NcApiBind(NeuChar.PlatformType.WeChat_Work, "CustomerAcquisitionApi.GetLinkList", true)]
57+
public static GetCustomerAcquisitionLinkListResult GetLinkList(string accessTokenOrAppKey,
58+
int limit = 100, string cursor = "", int timeOut = Config.TIME_OUT)
59+
{
60+
return ApiHandlerWapper.TryCommonApi(accessToken =>
61+
{
62+
var url = string.Format(
63+
Config.ApiWorkHost + "/cgi-bin/externalcontact/customer_acquisition/list_link?access_token={0}",
64+
accessToken.AsUrlData());
65+
66+
var postData = new
67+
{
68+
limit = limit,
69+
cursor = cursor
70+
};
71+
72+
return Senparc.Weixin.CommonAPIs.CommonJsonSend.Send<GetCustomerAcquisitionLinkListResult>(accessToken,
73+
url,
74+
postData, CommonJsonSendType.POST, timeOut);
75+
}, accessTokenOrAppKey);
76+
}
77+
78+
/// <summary>
79+
/// 获取获客链接详情
80+
/// </summary>
81+
/// <param name="accessTokenOrAppKey"></param>
82+
/// <param name="link_id">获客链接id</param>
83+
/// <param name="timeOut"></param>
84+
/// <returns></returns>
85+
[NcApiBind(NeuChar.PlatformType.WeChat_Work, "CustomerAcquisitionApi.GetLinkDetail", true)]
86+
public static GetCustomerAcquisitionLinkDetailResult GetLinkDetail(string accessTokenOrAppKey,
87+
string link_id = "", int timeOut = Config.TIME_OUT)
88+
{
89+
return ApiHandlerWapper.TryCommonApi(accessToken =>
90+
{
91+
var url = string.Format(
92+
Config.ApiWorkHost + "/cgi-bin/externalcontact/customer_acquisition/get?access_token={0}",
93+
accessToken.AsUrlData());
94+
95+
var postData = new
96+
{
97+
link_id = link_id
98+
};
99+
100+
return Senparc.Weixin.CommonAPIs.CommonJsonSend.Send<GetCustomerAcquisitionLinkDetailResult>(
101+
accessToken,
102+
url,
103+
postData, CommonJsonSendType.POST, timeOut);
104+
}, accessTokenOrAppKey);
105+
}
106+
107+
/// <summary>
108+
/// 创建获客链接
109+
/// </summary>
110+
/// <param name="accessTokenOrAppKey"></param>
111+
/// <param name="link_id">获客链接id</param>
112+
/// <param name="timeOut"></param>
113+
/// <returns></returns>
114+
[NcApiBind(NeuChar.PlatformType.WeChat_Work, "CustomerAcquisitionApi.CreateLink", true)]
115+
public static CreateCustomerAcquisitionLinkResult CreateLink(string accessTokenOrAppKey,
116+
CreateCustomerAcquisitionLinkRequest param, int timeOut = Config.TIME_OUT)
117+
{
118+
return ApiHandlerWapper.TryCommonApi(accessToken =>
119+
{
120+
var url = string.Format(
121+
Config.ApiWorkHost + "/cgi-bin/externalcontact/customer_acquisition/create_link?access_token={0}",
122+
accessToken.AsUrlData());
123+
124+
if (param.skip_verify == null) param.skip_verify = true;
125+
126+
return Senparc.Weixin.CommonAPIs.CommonJsonSend.Send<CreateCustomerAcquisitionLinkResult>(accessToken,
127+
url,
128+
param, CommonJsonSendType.POST, timeOut);
129+
}, accessTokenOrAppKey);
130+
}
131+
132+
133+
/// <summary>
134+
/// 编辑获客链接
135+
/// </summary>
136+
/// <param name="accessTokenOrAppKey"></param>
137+
/// <param name="link_id">获客链接id</param>
138+
/// <param name="timeOut"></param>
139+
/// <returns></returns>
140+
[NcApiBind(NeuChar.PlatformType.WeChat_Work, "CustomerAcquisitionApi.ModifyLink", true)]
141+
public static CreateCustomerAcquisitionLinkResult ModifyLink(string accessTokenOrAppKey,
142+
ModifyCustomerAcquisitionLinkRequest param, int timeOut = Config.TIME_OUT)
143+
{
144+
return ApiHandlerWapper.TryCommonApi(accessToken =>
145+
{
146+
var url = string.Format(
147+
Config.ApiWorkHost + "/cgi-bin/externalcontact/customer_acquisition/create_link?access_token={0}",
148+
accessToken.AsUrlData());
149+
150+
if (param.skip_verify == null) param.skip_verify = true;
151+
152+
return Senparc.Weixin.CommonAPIs.CommonJsonSend.Send<CreateCustomerAcquisitionLinkResult>(accessToken,
153+
url,
154+
param, CommonJsonSendType.POST, timeOut);
155+
}, accessTokenOrAppKey);
156+
}
157+
158+
/// <summary>
159+
/// 删除获客链接
160+
/// </summary>
161+
/// <param name="accessTokenOrAppKey"></param>
162+
/// <param name="link_id">获客链接id</param>
163+
/// <param name="timeOut"></param>
164+
/// <returns></returns>
165+
[NcApiBind(NeuChar.PlatformType.WeChat_Work, "CustomerAcquisitionApi.DeleteLink", true)]
166+
public static WorkJsonResult DeleteLink(string accessTokenOrAppKey, string link_id,
167+
int timeOut = Config.TIME_OUT)
168+
{
169+
return ApiHandlerWapper.TryCommonApi(accessToken =>
170+
{
171+
var url = string.Format(
172+
Config.ApiWorkHost + "/cgi-bin/externalcontact/customer_acquisition/delete_link?access_token={0}",
173+
accessToken.AsUrlData());
174+
175+
var param = new
176+
{
177+
link_id = link_id
178+
};
179+
180+
return Senparc.Weixin.CommonAPIs.CommonJsonSend.Send<WorkJsonResult>(accessToken,
181+
url,
182+
param, CommonJsonSendType.POST, timeOut);
183+
}, accessTokenOrAppKey);
184+
}
185+
186+
#endregion
187+
188+
#region 异步方法
189+
190+
/// <summary>
191+
/// 获取获客链接列表
192+
/// </summary>
193+
/// <param name="accessTokenOrAppKey"></param>
194+
/// <param name="limit">返回的最大记录数,整型,最大值100</param>
195+
/// <param name="cursor">用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填</param>
196+
/// <param name="timeOut"></param>
197+
/// <returns></returns>
198+
[NcApiBind(NeuChar.PlatformType.WeChat_Work, "CustomerAcquisitionApi.GetLinkListAsync", true)]
199+
public static async Task<GetCustomerAcquisitionLinkListResult> GetLinkListAsync(string accessTokenOrAppKey,
200+
int limit = 100, string cursor = "", int timeOut = Config.TIME_OUT)
201+
{
202+
return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
203+
{
204+
var url = string.Format(
205+
Config.ApiWorkHost + "/cgi-bin/externalcontact/customer_acquisition/list_link?access_token={0}",
206+
accessToken.AsUrlData());
207+
208+
var postData = new
209+
{
210+
limit = limit,
211+
cursor = cursor
212+
};
213+
214+
return await Senparc.Weixin.CommonAPIs.CommonJsonSend
215+
.SendAsync<GetCustomerAcquisitionLinkListResult>(accessToken, url, postData, timeOut: timeOut)
216+
.ConfigureAwait(false);
217+
}, accessTokenOrAppKey).ConfigureAwait(false);
218+
}
219+
220+
/// <summary>
221+
/// 获取获客链接详情
222+
/// </summary>
223+
/// <param name="accessTokenOrAppKey"></param>
224+
/// <param name="link_id">获客链接id</param>
225+
/// <param name="timeOut"></param>
226+
/// <returns></returns>
227+
[NcApiBind(NeuChar.PlatformType.WeChat_Work, "CustomerAcquisitionApi.GetLinkDetailAsync", true)]
228+
public static async Task<GetCustomerAcquisitionLinkDetailResult> GetLinkDetailAsync(string accessTokenOrAppKey,
229+
string link_id = "", int timeOut = Config.TIME_OUT)
230+
{
231+
return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
232+
{
233+
var url = string.Format(
234+
Config.ApiWorkHost + "/cgi-bin/externalcontact/customer_acquisition/get?access_token={0}",
235+
accessToken.AsUrlData());
236+
237+
var postData = new
238+
{
239+
link_id = link_id
240+
};
241+
242+
return await Senparc.Weixin.CommonAPIs.CommonJsonSend
243+
.SendAsync<GetCustomerAcquisitionLinkDetailResult>(
244+
accessToken,
245+
url,
246+
postData, CommonJsonSendType.POST, timeOut)
247+
.ConfigureAwait(false);
248+
}, accessTokenOrAppKey)
249+
.ConfigureAwait(false);
250+
}
251+
252+
/// <summary>
253+
/// 创建获客链接
254+
/// </summary>
255+
/// <param name="accessTokenOrAppKey"></param>
256+
/// <param name="link_id">获客链接id</param>
257+
/// <param name="timeOut"></param>
258+
/// <returns></returns>
259+
[NcApiBind(NeuChar.PlatformType.WeChat_Work, "CustomerAcquisitionApi.CreateLinkAsync", true)]
260+
public static async Task<CreateCustomerAcquisitionLinkResult> CreateLinkAsync(string accessTokenOrAppKey,
261+
CreateCustomerAcquisitionLinkRequest param, int timeOut = Config.TIME_OUT)
262+
{
263+
return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
264+
{
265+
var url = string.Format(
266+
Config.ApiWorkHost +
267+
"/cgi-bin/externalcontact/customer_acquisition/create_link?access_token={0}",
268+
accessToken.AsUrlData());
269+
270+
if (param.skip_verify == null) param.skip_verify = true;
271+
272+
return await Senparc.Weixin.CommonAPIs.CommonJsonSend
273+
.SendAsync<CreateCustomerAcquisitionLinkResult>(
274+
accessToken,
275+
url,
276+
param, CommonJsonSendType.POST, timeOut)
277+
.ConfigureAwait(false);
278+
}, accessTokenOrAppKey)
279+
.ConfigureAwait(false);
280+
}
281+
282+
283+
/// <summary>
284+
/// 编辑获客链接
285+
/// </summary>
286+
/// <param name="accessTokenOrAppKey"></param>
287+
/// <param name="link_id">获客链接id</param>
288+
/// <param name="timeOut"></param>
289+
/// <returns></returns>
290+
[NcApiBind(NeuChar.PlatformType.WeChat_Work, "CustomerAcquisitionApi.ModifyLinkAsync", true)]
291+
public static async Task<CreateCustomerAcquisitionLinkResult> ModifyLinkAsync(string accessTokenOrAppKey,
292+
ModifyCustomerAcquisitionLinkRequest param, int timeOut = Config.TIME_OUT)
293+
{
294+
return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
295+
{
296+
var url = string.Format(
297+
Config.ApiWorkHost +
298+
"/cgi-bin/externalcontact/customer_acquisition/create_link?access_token={0}",
299+
accessToken.AsUrlData());
300+
301+
if (param.skip_verify == null) param.skip_verify = true;
302+
303+
return await Senparc.Weixin.CommonAPIs.CommonJsonSend
304+
.SendAsync<CreateCustomerAcquisitionLinkResult>(
305+
accessToken,
306+
url,
307+
param, CommonJsonSendType.POST, timeOut)
308+
.ConfigureAwait(false);
309+
}, accessTokenOrAppKey)
310+
.ConfigureAwait(false);
311+
}
312+
313+
/// <summary>
314+
/// 删除获客链接
315+
/// </summary>
316+
/// <param name="accessTokenOrAppKey"></param>
317+
/// <param name="link_id">获客链接id</param>
318+
/// <param name="timeOut"></param>
319+
/// <returns></returns>
320+
[NcApiBind(NeuChar.PlatformType.WeChat_Work, "CustomerAcquisitionApi.DeleteLinkAsync", true)]
321+
public static async Task<WorkJsonResult> DeleteLinkAsync(string accessTokenOrAppKey, string link_id,
322+
int timeOut = Config.TIME_OUT)
323+
{
324+
return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
325+
{
326+
var url = string.Format(
327+
Config.ApiWorkHost +
328+
"/cgi-bin/externalcontact/customer_acquisition/delete_link?access_token={0}",
329+
accessToken.AsUrlData());
330+
331+
var param = new
332+
{
333+
link_id = link_id
334+
};
335+
336+
return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<WorkJsonResult>(accessToken,
337+
url,
338+
param, CommonJsonSendType.POST, timeOut)
339+
.ConfigureAwait(false);
340+
}, accessTokenOrAppKey)
341+
.ConfigureAwait(false);
342+
}
343+
344+
#endregion
345+
}
346+
}

0 commit comments

Comments
 (0)