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.
*/