Skip to content

Commit 47dba7f

Browse files
Javen205binarywang
authored andcommitted
🆕 【企业微信】新增获取企业微信接口IP段的接口 !126
1 parent e5255ed commit 47dba7f

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public interface WxCpService extends WxService {
149149

150150
/**
151151
* <pre>
152-
* 获取微信服务器的ip段
152+
* 获取企业微信回调IP段
153153
* 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
154154
* </pre>
155155
*
@@ -158,6 +158,17 @@ public interface WxCpService extends WxService {
158158
*/
159159
String[] getCallbackIp() throws WxErrorException;
160160

161+
/**
162+
* <pre>
163+
* 获取企业微信接口IP段
164+
* https://developer.work.weixin.qq.com/document/path/92520
165+
* </pre>
166+
*
167+
* @return 企业微信接口IP段
168+
* @throws WxErrorException the wx error exception
169+
*/
170+
String[] getApiDomainIp() throws WxErrorException;
171+
161172
/**
162173
* <pre>
163174
* 获取服务商凭证

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,23 @@ public WxCpMaJsCode2SessionResult jsCode2Session(String jsCode) throws WxErrorEx
229229

230230
@Override
231231
public String[] getCallbackIp() throws WxErrorException {
232-
String responseContent = get(this.configStorage.getApiUrl(GET_CALLBACK_IP), null);
232+
return getIp(GET_CALLBACK_IP);
233+
}
234+
235+
@Override
236+
public String[] getApiDomainIp() throws WxErrorException {
237+
return getIp(GET_API_DOMAIN_IP);
238+
}
239+
240+
/**
241+
* 获取 IP
242+
*
243+
* @param suffixUrl 接口URL 后缀
244+
* @return 返回结果
245+
* @throws WxErrorException 异常信息
246+
*/
247+
private String[] getIp(String suffixUrl) throws WxErrorException {
248+
String responseContent = get(this.configStorage.getApiUrl(suffixUrl), null);
233249
JsonObject tmpJsonObject = GsonParser.parse(responseContent);
234250
JsonArray jsonArray = tmpJsonObject.get("ip_list").getAsJsonArray();
235251
String[] ips = new String[jsonArray.size()];

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
@@ -27,6 +27,10 @@ public interface WxCpApiPathConsts {
2727
* The constant GET_CALLBACK_IP.
2828
*/
2929
String GET_CALLBACK_IP = "/cgi-bin/getcallbackip";
30+
/**
31+
* The constant GET_API_DOMAIN_IP.
32+
*/
33+
String GET_API_DOMAIN_IP = "/cgi-bin/get_api_domain_ip";
3034
/**
3135
* The constant BATCH_REPLACE_PARTY.
3236
*/

0 commit comments

Comments
 (0)