🆕 【企业微信】新增获取企业微信接口IP段的接口 !126

This commit is contained in:
Javen 2024-05-07 03:25:01 +00:00 committed by Binary Wang
parent e5255ed6ce
commit 47dba7f04f
3 changed files with 33 additions and 2 deletions

View File

@ -149,7 +149,7 @@ public interface WxCpService extends WxService {
/** /**
* <pre> * <pre>
* 获取微信服务器的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 * 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
* </pre> * </pre>
* *
@ -158,6 +158,17 @@ public interface WxCpService extends WxService {
*/ */
String[] getCallbackIp() throws WxErrorException; String[] getCallbackIp() throws WxErrorException;
/**
* <pre>
* 获取企业微信接口IP段
* https://developer.work.weixin.qq.com/document/path/92520
* </pre>
*
* @return 企业微信接口IP段
* @throws WxErrorException the wx error exception
*/
String[] getApiDomainIp() throws WxErrorException;
/** /**
* <pre> * <pre>
* 获取服务商凭证 * 获取服务商凭证

View File

@ -229,7 +229,23 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
@Override @Override
public String[] getCallbackIp() throws WxErrorException { 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); JsonObject tmpJsonObject = GsonParser.parse(responseContent);
JsonArray jsonArray = tmpJsonObject.get("ip_list").getAsJsonArray(); JsonArray jsonArray = tmpJsonObject.get("ip_list").getAsJsonArray();
String[] ips = new String[jsonArray.size()]; String[] ips = new String[jsonArray.size()];

View File

@ -27,6 +27,10 @@ public interface WxCpApiPathConsts {
* The constant GET_CALLBACK_IP. * The constant GET_CALLBACK_IP.
*/ */
String GET_CALLBACK_IP = "/cgi-bin/getcallbackip"; 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. * The constant BATCH_REPLACE_PARTY.
*/ */