From b8d2b2f1aa6725d593f1ff4c37a6a04cc186929c Mon Sep 17 00:00:00 2001 From: Javen Date: Mon, 29 Apr 2024 21:53:58 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=96=B0=E5=A2=9E=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=BC=81=E4=B8=9A=E5=BE=AE=E4=BF=A1=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?IP=E6=AE=B5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/chanjar/weixin/cp/api/WxCpService.java | 13 ++++++++++++- .../cp/api/impl/BaseWxCpServiceImpl.java | 18 +++++++++++++++++- .../weixin/cp/constant/WxCpApiPathConsts.java | 4 ++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java index 4accc2f60..9bcb16153 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java @@ -149,7 +149,7 @@ public interface WxCpService extends WxService { /** *
-   * 获取微信服务器的ip段
+   * 获取企业微信回调IP段
    * http://qydev.weixin.qq.com/wiki/index.php?title=回调模式#.E8.8E.B7.E5.8F.96.E5.BE.AE.E4.BF.A1.E6.9C.8D.E5.8A.A1.E5.99.A8.E7.9A.84ip.E6.AE.B5
    * 
* @@ -158,6 +158,17 @@ public interface WxCpService extends WxService { */ String[] getCallbackIp() throws WxErrorException; + /** + *
+   * 获取企业微信接口IP段
+   * https://developer.work.weixin.qq.com/document/path/92520
+   * 
+ * + * @return 企业微信接口IP段 + * @throws WxErrorException the wx error exception + */ + String[] getApiDomainIp() throws WxErrorException; + /** *
    * 获取服务商凭证
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java
index a66b059c5..f613f6138 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java
@@ -229,7 +229,23 @@ public abstract class BaseWxCpServiceImpl implements WxCpService, RequestH
 
   @Override
   public String[] getCallbackIp() throws WxErrorException {
-    String responseContent = get(this.configStorage.getApiUrl(GET_CALLBACK_IP), null);
+    return getIp(GET_CALLBACK_IP);
+  }
+
+  @Override
+  public String[] getApiDomainIp() throws WxErrorException {
+    return getIp(GET_API_DOMAIN_IP);
+  }
+
+  /**
+   * 获取 IP
+   *
+   * @param suffixUrl 接口URL 后缀
+   * @return 返回结果
+   * @throws WxErrorException 异常信息
+   */
+  private String[] getIp(String suffixUrl) throws WxErrorException {
+    String responseContent = get(this.configStorage.getApiUrl(suffixUrl), null);
     JsonObject tmpJsonObject = GsonParser.parse(responseContent);
     JsonArray jsonArray = tmpJsonObject.get("ip_list").getAsJsonArray();
     String[] ips = new String[jsonArray.size()];
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 21f7ff977..c2f8a9310 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
@@ -27,6 +27,10 @@ public interface WxCpApiPathConsts {
    * The constant GET_CALLBACK_IP.
    */
   String GET_CALLBACK_IP = "/cgi-bin/getcallbackip";
+  /**
+   * The constant GET_API_DOMAIN_IP.
+   */
+  String GET_API_DOMAIN_IP = "/cgi-bin/get_api_domain_ip";
   /**
    * The constant BATCH_REPLACE_PARTY.
    */
-- 
Gitee