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 4accc2f60b0f5781f86591c94f0a102377b7fa5a..9bcb1615348078b14ac1f051fa026f26bf0b5753 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 a66b059c5f75378c876446367cc984e64e9ffd34..f613f6138c3c45421f9d40ae9b40cad313ccc0bf 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 21f7ff9774491a4313eea5c99f05c3aa7bf49f18..c2f8a93100dde6a9227b4d3c77aff2c112447148 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.
*/