mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-02-18 14:16:25 +08:00
issue #101 获取微信服务器IP地址
This commit is contained in:
@@ -421,6 +421,16 @@ public interface WxMpService {
|
||||
*/
|
||||
public boolean oauth2validateAccessToken(WxMpOAuth2AccessToken oAuth2AccessToken);
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取微信服务器IP地址
|
||||
* http://mp.weixin.qq.com/wiki/0/2ad4b6bfd29f30f71d39616c2a0fcedc.html
|
||||
* </pre>
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
String[] getCallbackIP() throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的GET请求
|
||||
* @param url
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.internal.Streams;
|
||||
@@ -451,6 +452,19 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getCallbackIP() throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/getcallbackip";
|
||||
String responseContent = get(url, null);
|
||||
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
|
||||
JsonArray ipList = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray();
|
||||
String[] ipArray = new String[ipList.size()];
|
||||
for (int i = 0; i < ipList.size(); i++) {
|
||||
ipArray[i] = ipList.get(i).getAsString();
|
||||
}
|
||||
return ipArray;
|
||||
}
|
||||
|
||||
public String get(String url, String queryParam) throws WxErrorException {
|
||||
return execute(new SimpleGetRequestExecutor(), url, queryParam);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user