Skip to content

Commit 4ce392d

Browse files
authored
🆕 #3064 【企业微信】增加获客助手相关的接口
1 parent 10b1e4d commit 4ce392d

9 files changed

+507
-1
lines changed

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import me.chanjar.weixin.common.error.WxErrorException;
55
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
66
import me.chanjar.weixin.cp.bean.external.*;
7+
import me.chanjar.weixin.cp.bean.external.acquisition.*;
78
import me.chanjar.weixin.cp.bean.external.contact.*;
89
import me.chanjar.weixin.cp.bean.external.interceptrule.WxCpInterceptRule;
910
import me.chanjar.weixin.cp.bean.external.interceptrule.WxCpInterceptRuleAddRequest;
@@ -1144,4 +1145,117 @@ WxMediaUploadResult uploadAttachment(String mediaType, Integer attachmentType, F
11441145
*/
11451146
void deleteProductAlbum(String productId) throws WxErrorException;
11461147

1148+
/**
1149+
* <pre>
1150+
* 获取获客链接列表
1151+
* 企业可通过此接口获取当前仍然有效的获客链接。
1152+
* 请求方式:POST(HTTPS)
1153+
* 请求地址:
1154+
* <a href="https://qyapi.weixin.qq.com/cgi-bin/externalcontact/customer_acquisition/list_link?access_token=ACCESS_TOKEN">接口地址</a>
1155+
*
1156+
* <a href="https://developer.work.weixin.qq.com/document/path/97297#%E8%8E%B7%E5%8F%96%E8%8E%B7%E5%AE%A2%E9%93%BE%E6%8E%A5%E5%88%97%E8%A1%A8">文档地址</a>
1157+
* </pre>
1158+
* @param limit 商品id
1159+
* @param cursor 商品id
1160+
* @return 获客链接列表
1161+
* @throws WxErrorException the wx error exception
1162+
*/
1163+
WxCpCustomerAcquisitionList customerAcquisitionLinkList(Integer limit, String cursor) throws WxErrorException;
1164+
1165+
/**
1166+
* <pre>
1167+
* 获取获客链接详情
1168+
* 企业可通过此接口根据获客链接id获取链接配置详情。。
1169+
* 请求方式:POST(HTTPS)
1170+
* 请求地址:
1171+
* <a href="https://qyapi.weixin.qq.com/cgi-bin/externalcontact/customer_acquisition/get?access_token=ACCESS_TOKEN">接口地址</a>
1172+
*
1173+
* <a href="https://developer.work.weixin.qq.com/document/path/97297#%E8%8E%B7%E5%8F%96%E8%8E%B7%E5%AE%A2%E9%93%BE%E6%8E%A5%E8%AF%A6%E6%83%85">文档地址</a>
1174+
* </pre>
1175+
* @param linkId 获客链接ID
1176+
* @return 获客链接详情
1177+
* @throws WxErrorException the wx error exception
1178+
*/
1179+
WxCpCustomerAcquisitionInfo customerAcquisitionLinkGet(String linkId) throws WxErrorException;
1180+
1181+
/**
1182+
* <pre>
1183+
* 创建获客链接
1184+
* 企业可通过此接口创建新的获客链接。
1185+
* 请求方式:POST(HTTPS)
1186+
* 请求地址:
1187+
* <a href="https://qyapi.weixin.qq.com/cgi-bin/externalcontact/customer_acquisition/create_link?access_token=ACCESS_TOKEN">接口地址</a>
1188+
* <a href="https://developer.work.weixin.qq.com/document/path/97297#%E5%88%9B%E5%BB%BA%E8%8E%B7%E5%AE%A2%E9%93%BE%E6%8E%A5">文档地址</a>
1189+
* </pre>
1190+
*
1191+
* @param wxCpCustomerAcquisitionRequest 创建链接请求
1192+
* @return 创建链接详情
1193+
* @throws WxErrorException the wx error exception
1194+
*/
1195+
WxCpCustomerAcquisitionCreateResult customerAcquisitionLinkCreate(WxCpCustomerAcquisitionRequest wxCpCustomerAcquisitionRequest) throws WxErrorException;
1196+
1197+
/**
1198+
* <pre>
1199+
* 编辑获客链接
1200+
* 企业可通过此接口编辑获客链接,修改获客链接的关联范围或修改获客链接的名称。
1201+
* 请求方式:POST(HTTPS)
1202+
* 请求地址:
1203+
* <a href="https://qyapi.weixin.qq.com/cgi-bin/externalcontact/customer_acquisition/update_link?access_token=ACCESS_TOKEN">接口地址</a>
1204+
* <a href="https://developer.work.weixin.qq.com/document/path/97297#%E7%BC%96%E8%BE%91%E8%8E%B7%E5%AE%A2%E9%93%BE%E6%8E%A5">文档地址</a>
1205+
* </pre>
1206+
*
1207+
* @param wxCpCustomerAcquisitionRequest 编辑链接请求
1208+
* @return 编辑链接详情
1209+
* @throws WxErrorException the wx error exception
1210+
*/
1211+
WxCpBaseResp customerAcquisitionUpdate(WxCpCustomerAcquisitionRequest wxCpCustomerAcquisitionRequest) throws WxErrorException;
1212+
1213+
/**
1214+
* <pre>
1215+
* 删除获客链接
1216+
* 企业可通过此接口删除获客链接,删除后的获客链接将无法继续使用。
1217+
* 请求方式:POST(HTTPS)
1218+
* 请求地址:
1219+
* <a href="https://qyapi.weixin.qq.com/cgi-bin/externalcontact/customer_acquisition/delete_link?access_token=ACCESS_TOKEN">接口地址</a>
1220+
* <a href="https://developer.work.weixin.qq.com/document/path/97297#%E5%88%A0%E9%99%A4%E8%8E%B7%E5%AE%A2%E9%93%BE%E6%8E%A5">文档地址</a>
1221+
* </pre>
1222+
*
1223+
* @param linkId 获客链接的id
1224+
* @return 删除结果
1225+
* @throws WxErrorException the wx error exception
1226+
*/
1227+
WxCpBaseResp customerAcquisitionLinkDelete(String linkId) throws WxErrorException;
1228+
1229+
/**
1230+
* <pre>
1231+
* 获取获客客户列表
1232+
* 企业可通过此接口获取到由指定的获客链接添加的客户列表。
1233+
* 请求方式:POST(HTTPS)
1234+
* 请求地址:
1235+
* <a href="https://qyapi.weixin.qq.com/cgi-bin/externalcontact/customer_acquisition/customer?access_token=ACCESS_TOKEN">接口地址</a>
1236+
* <a href="https://developer.work.weixin.qq.com/document/path/97298">文档地址</a>
1237+
* </pre>
1238+
*
1239+
* @param linkId 获客链接id
1240+
* @param limit 返回的最大记录数,整型,最大值1000
1241+
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
1242+
* @return 由获客链接添加的客户信息列表
1243+
* @throws WxErrorException the wx error exception
1244+
*/
1245+
WxCpCustomerAcquisitionCustomerList customerAcquisitionCustomer(String linkId, Integer limit, String cursor) throws WxErrorException;
1246+
1247+
/**
1248+
* <pre>
1249+
* 查询剩余使用量
1250+
* 企业可通过此接口查询当前剩余的使用量。
1251+
* 请求方式:GET(HTTPS)
1252+
* 请求地址:
1253+
* <a href="https://qyapi.weixin.qq.com/cgi-bin/externalcontact/customer_acquisition_quota?access_token=ACCESS_TOKEN">接口地址</a>
1254+
* <a href="https://developer.work.weixin.qq.com/document/path/97375">文档地址</a>
1255+
* </pre>
1256+
*
1257+
* @return 剩余使用量
1258+
* @throws WxErrorException the wx error exception
1259+
*/
1260+
WxCpCustomerAcquisitionQuota customerAcquisitionQuota() throws WxErrorException;
11471261
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import me.chanjar.weixin.cp.api.WxCpService;
1717
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
1818
import me.chanjar.weixin.cp.bean.external.*;
19+
import me.chanjar.weixin.cp.bean.external.acquisition.*;
1920
import me.chanjar.weixin.cp.bean.external.contact.*;
2021
import me.chanjar.weixin.cp.bean.external.interceptrule.WxCpInterceptRule;
2122
import me.chanjar.weixin.cp.bean.external.interceptrule.WxCpInterceptRuleAddRequest;
@@ -741,6 +742,63 @@ public void deleteProductAlbum(String productId) throws WxErrorException {
741742
this.mainService.post(url, o.toString());
742743
}
743744

745+
@Override
746+
public WxCpCustomerAcquisitionList customerAcquisitionLinkList(Integer limit, String cursor) throws WxErrorException {
747+
JsonObject o = new JsonObject();
748+
o.addProperty("limit", limit);
749+
o.addProperty("cursor", cursor);
750+
751+
String url = this.mainService.getWxCpConfigStorage().getApiUrl(CUSTOMER_ACQUISITION_LINK_LIST);
752+
return WxCpCustomerAcquisitionList.fromJson(this.mainService.post(url, o));
753+
}
754+
755+
@Override
756+
public WxCpCustomerAcquisitionInfo customerAcquisitionLinkGet(String linkId) throws WxErrorException {
757+
JsonObject o = new JsonObject();
758+
o.addProperty("link_id", linkId);
759+
760+
String url = this.mainService.getWxCpConfigStorage().getApiUrl(CUSTOMER_ACQUISITION_LINK_GET);
761+
return WxCpCustomerAcquisitionInfo.fromJson(this.mainService.post(url, o));
762+
}
763+
764+
@Override
765+
public WxCpCustomerAcquisitionCreateResult customerAcquisitionLinkCreate(WxCpCustomerAcquisitionRequest wxCpCustomerAcquisitionRequest) throws WxErrorException {
766+
String url = this.mainService.getWxCpConfigStorage().getApiUrl(CUSTOMER_ACQUISITION_LINK_CREATE);
767+
return WxCpCustomerAcquisitionCreateResult.fromJson(this.mainService.post(url, wxCpCustomerAcquisitionRequest.toJson()));
768+
}
769+
770+
@Override
771+
public WxCpBaseResp customerAcquisitionUpdate(WxCpCustomerAcquisitionRequest wxCpCustomerAcquisitionRequest) throws WxErrorException {
772+
String url = this.mainService.getWxCpConfigStorage().getApiUrl(CUSTOMER_ACQUISITION_LINK_UPDATE);
773+
return WxCpBaseResp.fromJson(this.mainService.post(url, wxCpCustomerAcquisitionRequest.toJson()));
774+
}
775+
776+
@Override
777+
public WxCpBaseResp customerAcquisitionLinkDelete(String linkId) throws WxErrorException {
778+
JsonObject o = new JsonObject();
779+
o.addProperty("link_id", linkId);
780+
781+
String url = this.mainService.getWxCpConfigStorage().getApiUrl(CUSTOMER_ACQUISITION_LINK_DELETE);
782+
return WxCpBaseResp.fromJson(this.mainService.post(url, o));
783+
}
784+
785+
@Override
786+
public WxCpCustomerAcquisitionCustomerList customerAcquisitionCustomer(String linkId, Integer limit, String cursor) throws WxErrorException {
787+
JsonObject o = new JsonObject();
788+
o.addProperty("link_id", linkId);
789+
o.addProperty("limit", limit);
790+
o.addProperty("cursor", cursor);
791+
792+
String url = this.mainService.getWxCpConfigStorage().getApiUrl(CUSTOMER_ACQUISITION_CUSTOMER);
793+
return WxCpCustomerAcquisitionCustomerList.fromJson(this.mainService.post(url, o));
794+
}
795+
796+
@Override
797+
public WxCpCustomerAcquisitionQuota customerAcquisitionQuota() throws WxErrorException {
798+
String url = this.mainService.getWxCpConfigStorage().getApiUrl(CUSTOMER_ACQUISITION_QUOTA);
799+
return WxCpCustomerAcquisitionQuota.fromJson(this.mainService.get(url, null));
800+
}
801+
744802
@Override
745803
public WxCpGroupJoinWayResult addJoinWay(WxCpGroupJoinWayInfo wxCpGroupJoinWayInfo) throws WxErrorException {
746804
if (wxCpGroupJoinWayInfo.getJoinWay().getChatIdList() != null && wxCpGroupJoinWayInfo.getJoinWay().getChatIdList().size() > 5) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package me.chanjar.weixin.cp.bean.external.acquisition;
2+
3+
import lombok.Data;
4+
import lombok.EqualsAndHashCode;
5+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
6+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
7+
8+
/**
9+
* 创建获客助手链接结果
10+
*
11+
* @author alien_zyl
12+
*/
13+
@Data
14+
@EqualsAndHashCode(callSuper = true)
15+
public class WxCpCustomerAcquisitionCreateResult extends WxCpBaseResp {
16+
private static final long serialVersionUID = -6301164294371861558L;
17+
18+
private WxCpCustomerAcquisitionInfo.Link link;
19+
20+
public static WxCpCustomerAcquisitionCreateResult fromJson(String json) {
21+
return WxCpGsonBuilder.create().fromJson(json, WxCpCustomerAcquisitionCreateResult.class);
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package me.chanjar.weixin.cp.bean.external.acquisition;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
6+
7+
import java.io.Serializable;
8+
import java.util.List;
9+
10+
/**
11+
* 获取由获客链接添加的客户信息结果
12+
*
13+
* @author alien_zyl
14+
*/
15+
@Data
16+
public class WxCpCustomerAcquisitionCustomerList {
17+
18+
@SerializedName("customer_list")
19+
private List<Customer> customerList;
20+
21+
/**
22+
* 分页游标,再下次请求时填写以获取之后分页的记录,如果已经没有更多的数据则返回空
23+
*/
24+
@SerializedName("next_cursor")
25+
private String nextCursor;
26+
27+
28+
public static WxCpCustomerAcquisitionCustomerList fromJson(String json) {
29+
return WxCpGsonBuilder.create().fromJson(json, WxCpCustomerAcquisitionCustomerList.class);
30+
}
31+
32+
public String toJson() {
33+
return WxCpGsonBuilder.create().toJson(this);
34+
}
35+
36+
@Data
37+
public static class Customer implements Serializable {
38+
private static final long serialVersionUID = 4456053823277371278L;
39+
40+
/**
41+
* 客户external_userid
42+
*/
43+
@SerializedName("external_userid")
44+
private String externalUserid;
45+
46+
/**
47+
* 通过获客链接添加此客户的跟进人userid
48+
*/
49+
@SerializedName("userid")
50+
private String userid;
51+
52+
/**
53+
* 会话状态,0-客户未发消息 1-客户已发送消息
54+
*/
55+
@SerializedName("chat_status")
56+
private Integer chatStatus;
57+
58+
/**
59+
* 用于区分客户具体是通过哪个获客链接进行添加,
60+
* 用户可在获客链接后拼接customer_channel=自定义字符串,字符串不超过64字节,超过会被截断。
61+
* 通过点击带有customer_channel参数的链接获取到的客户,调用获客信息接口或获取客户详情接口时,返回的state参数即为链接后拼接自定义字符串
62+
*/
63+
@SerializedName("state")
64+
private String state;
65+
66+
}
67+
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package me.chanjar.weixin.cp.bean.external.acquisition;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
7+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
8+
9+
import java.io.Serializable;
10+
import java.util.List;
11+
12+
/**
13+
* 获客链接详情
14+
*
15+
* @author alien_zyl
16+
*/
17+
@Data
18+
@EqualsAndHashCode(callSuper = true)
19+
public class WxCpCustomerAcquisitionInfo extends WxCpBaseResp implements Serializable {
20+
21+
private static final long serialVersionUID = -425354507473041229L;
22+
/**
23+
* link_id列表
24+
*/
25+
@SerializedName("link")
26+
private Link link;
27+
28+
/**
29+
* 分页游标,在下次请求时填写以获取之后分页的记录
30+
*/
31+
@SerializedName("range")
32+
private Range range;
33+
34+
/**
35+
* 是否无需验证,默认为true
36+
*/
37+
@SerializedName("skip_verify")
38+
private Boolean skipVerify;
39+
40+
public static WxCpCustomerAcquisitionInfo fromJson(String json) {
41+
return WxCpGsonBuilder.create().fromJson(json, WxCpCustomerAcquisitionInfo.class);
42+
}
43+
44+
@Data
45+
@EqualsAndHashCode(callSuper = true)
46+
public static class Link extends WxCpBaseResp implements Serializable {
47+
private static final long serialVersionUID = 6750537220943228300L;
48+
49+
/**
50+
* 获客链接的id
51+
*/
52+
@SerializedName("link_id")
53+
private String linkId;
54+
55+
/**
56+
* 获客链接的名称
57+
*/
58+
@SerializedName("link_name")
59+
private String linkName;
60+
61+
/**
62+
* 获客链接实际的url
63+
*/
64+
@SerializedName("url")
65+
private String url;
66+
67+
/**
68+
* 创建时间
69+
*/
70+
@SerializedName("create_time")
71+
private Long createTime;
72+
73+
public static Link fromJson(String json) {
74+
return WxCpGsonBuilder.create().fromJson(json, Link.class);
75+
}
76+
}
77+
78+
@Data
79+
public static class Range implements Serializable {
80+
private static final long serialVersionUID = -6343768645371744643L;
81+
82+
/**
83+
* 此获客链接关联的userid列表,最多可关联100个
84+
*/
85+
@SerializedName("user_list")
86+
private List<String> userList;
87+
88+
/**
89+
* 此获客链接关联的部门id列表,部门覆盖总人数最多100个
90+
*/
91+
@SerializedName("department_list")
92+
private List<String> departmentList;
93+
94+
public static Range fromJson(String json) {
95+
return WxCpGsonBuilder.create().fromJson(json, Range.class);
96+
}
97+
98+
public String toJson() {
99+
return WxCpGsonBuilder.create().toJson(this);
100+
}
101+
}
102+
103+
}

0 commit comments

Comments
 (0)