Skip to content

Commit 783c895

Browse files
authored
🆕 binarywang#3488【企业微信】增加获取企业已配置的「联系我」列表的接口
1 parent 3e48dc7 commit 783c895

5 files changed

Lines changed: 114 additions & 0 deletions

File tree

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,25 @@ public interface WxCpExternalContactService {
5959
*/
6060
WxCpContactWayInfo getContactWay(String configId) throws WxErrorException;
6161

62+
/**
63+
* 获取企业已配置的「联系我」列表
64+
*
65+
* <pre>
66+
* 获取企业配置的「联系我」二维码和「联系我」小程序插件列表。不包含临时会话。
67+
* 注意,<b>该接口仅可获取2021年7月10日以后创建的「联系我」</b>
68+
* </pre>
69+
*
70+
* 文档地址: <a href="https://developer.work.weixin.qq.com/document/path/92228#%E8%8E%B7%E5%8F%96%E4%BC%81%E4%B8%9A%E5%B7%B2%E9%85%8D%E7%BD%AE%E7%9A%84%E3%80%8C%E8%81%94%E7%B3%BB%E6%88%91%E3%80%8D%E5%88%97%E8%A1%A8">获取企业已配置的「联系我」列表</a>
71+
*
72+
* @param startTime 「联系我」创建起始时间戳, 默认为90天前
73+
* @param endTime 「联系我」创建结束时间戳, 默认为当前时间
74+
* @param cursor 分页查询使用的游标,为上次请求返回的 next_cursor
75+
* @param limit 每次查询的分页大小,默认为100条,最多支持1000条
76+
* @return contact way configId
77+
* @throws WxErrorException the wx error exception
78+
*/
79+
WxCpContactWayList listContactWay(Long startTime, Long endTime, String cursor, Long limit) throws WxErrorException;
80+
6281
/**
6382
* 更新企业已配置的「联系我」方式
6483
*

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ public WxCpContactWayInfo getContactWay(String configId) throws WxErrorException
6565
return WxCpContactWayInfo.fromJson(this.mainService.post(url, json.toString()));
6666
}
6767

68+
@Override
69+
public WxCpContactWayList listContactWay(Long startTime, Long endTime, String cursor, Long limit) throws WxErrorException {
70+
JsonObject json = new JsonObject();
71+
json.addProperty("start_time", startTime);
72+
json.addProperty("end_time", endTime);
73+
json.addProperty("cursor", cursor);
74+
json.addProperty("limit", limit);
75+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(LIST_CONTACT_WAY);
76+
return WxCpContactWayList.fromJson(this.mainService.post(url, json.toString()));
77+
}
78+
6879
@Override
6980
public WxCpBaseResp updateContactWay(WxCpContactWayInfo info) throws WxErrorException {
7081
if (StringUtils.isBlank(info.getContactWay().getConfigId())) {
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package me.chanjar.weixin.cp.bean.external;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
import lombok.Getter;
7+
import lombok.NoArgsConstructor;
8+
import lombok.Setter;
9+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
10+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
11+
12+
import java.io.Serializable;
13+
import java.util.List;
14+
15+
/**
16+
* 「联系我」方式 列表返回对象
17+
*
18+
* @author <a href="https://github.com/imyzt">imyzt</a>
19+
*/
20+
@EqualsAndHashCode(callSuper = true)
21+
@Data
22+
@NoArgsConstructor
23+
public class WxCpContactWayList extends WxCpBaseResp implements Serializable {
24+
private static final long serialVersionUID = -8697184659526210472L;
25+
26+
@SerializedName("contact_way")
27+
private List<ContactWay> contactWay;
28+
29+
/**
30+
* The type Contact way.
31+
*/
32+
@Getter
33+
@Setter
34+
public static class ContactWay implements Serializable {
35+
private static final long serialVersionUID = -8697184659526210472L;
36+
37+
/**
38+
* 联系方式的配置id
39+
*/
40+
@SerializedName("config_id")
41+
private String configId;
42+
}
43+
44+
/**
45+
* From json wx cp contact way list.
46+
*
47+
* @param json the json
48+
* @return the wx cp contact way list
49+
*/
50+
public static WxCpContactWayList fromJson(String json) {
51+
return WxCpGsonBuilder.create().fromJson(json, WxCpContactWayList.class);
52+
}
53+
54+
/**
55+
* To json string.
56+
*
57+
* @return the string
58+
*/
59+
public String toJson() {
60+
return WxCpGsonBuilder.create().toJson(this);
61+
}
62+
63+
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,10 @@ interface ExternalContact {
10851085
* The constant GET_CONTACT_WAY.
10861086
*/
10871087
String GET_CONTACT_WAY = "/cgi-bin/externalcontact/get_contact_way";
1088+
/**
1089+
* The constant LIST_CONTACT_WAY.
1090+
*/
1091+
String LIST_CONTACT_WAY = "/cgi-bin/externalcontact/list_contact_way";
10881092
/**
10891093
* The constant UPDATE_CONTACT_WAY.
10901094
*/

weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
import com.google.common.collect.Lists;
66
import com.google.inject.Inject;
7+
8+
import java.time.LocalDateTime;
9+
import java.time.ZoneOffset;
710
import java.util.ArrayList;
811
import java.util.Collections;
912
import java.util.Date;
@@ -90,6 +93,20 @@ public void testGetContactWay() throws WxErrorException {
9093
assertNotNull(contactWayInfo);
9194
}
9295

96+
/**
97+
* Test list contact way.
98+
*
99+
* @throws WxErrorException the wx error exception
100+
*/
101+
@Test
102+
public void testListContactWay() throws WxErrorException {
103+
long startTime = LocalDateTime.now().minusDays(1).toEpochSecond(ZoneOffset.of("+8"));
104+
long endTime = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"));
105+
WxCpContactWayList wxCpContactWayList = this.wxCpService.getExternalContactService().listContactWay(startTime, endTime, null, 100L);
106+
System.out.println(wxCpContactWayList.toJson());
107+
assertNotNull(wxCpContactWayList);
108+
}
109+
93110
/**
94111
* Test update contact way.
95112
*

0 commit comments

Comments
 (0)