From 783c89523dc800b863f91e578ecbc06597de2304 Mon Sep 17 00:00:00 2001 From: imyzt Date: Fri, 7 Feb 2025 19:58:53 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20#3488=E3=80=90=E4=BC=81=E4=B8=9A?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E3=80=91=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E4=BC=81=E4=B8=9A=E5=B7=B2=E9=85=8D=E7=BD=AE=E7=9A=84=E3=80=8C?= =?UTF-8?q?=E8=81=94=E7=B3=BB=E6=88=91=E3=80=8D=E5=88=97=E8=A1=A8=E7=9A=84?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cp/api/WxCpExternalContactService.java | 19 ++++++ .../impl/WxCpExternalContactServiceImpl.java | 11 ++++ .../cp/bean/external/WxCpContactWayList.java | 63 +++++++++++++++++++ .../weixin/cp/constant/WxCpApiPathConsts.java | 4 ++ .../WxCpExternalContactServiceImplTest.java | 17 +++++ 5 files changed, 114 insertions(+) create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpContactWayList.java diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java index f55d2f7b9..c886fcab6 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java @@ -59,6 +59,25 @@ public interface WxCpExternalContactService { */ WxCpContactWayInfo getContactWay(String configId) throws WxErrorException; + /** + * 获取企业已配置的「联系我」列表 + * + *
+   * 获取企业配置的「联系我」二维码和「联系我」小程序插件列表。不包含临时会话。
+   * 注意,该接口仅可获取2021年7月10日以后创建的「联系我」
+   * 
+ * + * 文档地址: 获取企业已配置的「联系我」列表 + * + * @param startTime 「联系我」创建起始时间戳, 默认为90天前 + * @param endTime 「联系我」创建结束时间戳, 默认为当前时间 + * @param cursor 分页查询使用的游标,为上次请求返回的 next_cursor + * @param limit 每次查询的分页大小,默认为100条,最多支持1000条 + * @return contact way configId + * @throws WxErrorException the wx error exception + */ + WxCpContactWayList listContactWay(Long startTime, Long endTime, String cursor, Long limit) throws WxErrorException; + /** * 更新企业已配置的「联系我」方式 * diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java index c2fbdfe6e..8e3a8d7b9 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java @@ -65,6 +65,17 @@ public class WxCpExternalContactServiceImpl implements WxCpExternalContactServic return WxCpContactWayInfo.fromJson(this.mainService.post(url, json.toString())); } + @Override + public WxCpContactWayList listContactWay(Long startTime, Long endTime, String cursor, Long limit) throws WxErrorException { + JsonObject json = new JsonObject(); + json.addProperty("start_time", startTime); + json.addProperty("end_time", endTime); + json.addProperty("cursor", cursor); + json.addProperty("limit", limit); + final String url = this.mainService.getWxCpConfigStorage().getApiUrl(LIST_CONTACT_WAY); + return WxCpContactWayList.fromJson(this.mainService.post(url, json.toString())); + } + @Override public WxCpBaseResp updateContactWay(WxCpContactWayInfo info) throws WxErrorException { if (StringUtils.isBlank(info.getContactWay().getConfigId())) { diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpContactWayList.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpContactWayList.java new file mode 100644 index 000000000..04918f64e --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpContactWayList.java @@ -0,0 +1,63 @@ +package me.chanjar.weixin.cp.bean.external; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.io.Serializable; +import java.util.List; + +/** + * 「联系我」方式 列表返回对象 + * + * @author imyzt + */ +@EqualsAndHashCode(callSuper = true) +@Data +@NoArgsConstructor +public class WxCpContactWayList extends WxCpBaseResp implements Serializable { + private static final long serialVersionUID = -8697184659526210472L; + + @SerializedName("contact_way") + private List contactWay; + + /** + * The type Contact way. + */ + @Getter + @Setter + public static class ContactWay implements Serializable { + private static final long serialVersionUID = -8697184659526210472L; + + /** + * 联系方式的配置id + */ + @SerializedName("config_id") + private String configId; + } + + /** + * From json wx cp contact way list. + * + * @param json the json + * @return the wx cp contact way list + */ + public static WxCpContactWayList fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpContactWayList.class); + } + + /** + * To json string. + * + * @return the string + */ + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java index dfb38a524..3aecf7212 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java @@ -1085,6 +1085,10 @@ public interface WxCpApiPathConsts { * The constant GET_CONTACT_WAY. */ String GET_CONTACT_WAY = "/cgi-bin/externalcontact/get_contact_way"; + /** + * The constant LIST_CONTACT_WAY. + */ + String LIST_CONTACT_WAY = "/cgi-bin/externalcontact/list_contact_way"; /** * The constant UPDATE_CONTACT_WAY. */ diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java index c629165ca..4bd80928b 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java @@ -4,6 +4,9 @@ import static org.testng.Assert.assertNotNull; import com.google.common.collect.Lists; import com.google.inject.Inject; + +import java.time.LocalDateTime; +import java.time.ZoneOffset; import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -90,6 +93,20 @@ public class WxCpExternalContactServiceImplTest { assertNotNull(contactWayInfo); } + /** + * Test list contact way. + * + * @throws WxErrorException the wx error exception + */ + @Test + public void testListContactWay() throws WxErrorException { + long startTime = LocalDateTime.now().minusDays(1).toEpochSecond(ZoneOffset.of("+8")); + long endTime = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")); + WxCpContactWayList wxCpContactWayList = this.wxCpService.getExternalContactService().listContactWay(startTime, endTime, null, 100L); + System.out.println(wxCpContactWayList.toJson()); + assertNotNull(wxCpContactWayList); + } + /** * Test update contact way. *