issue #81 增加获取微信服务器的ip段接口

This commit is contained in:
Daniel Qian 2015-01-24 15:00:10 +08:00
parent b43a62c3a6
commit 037c326ebf
2 changed files with 23 additions and 0 deletions

View File

@ -327,6 +327,16 @@ public interface WxCpService {
*/
public int invite(String userId, String inviteTips) throws WxErrorException;
/**
* <pre>
* 获取微信服务器的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
* </pre>
* @return { "ip_list": ["101.226.103.*", "101.226.62.*"] }
* @throws WxErrorException
*/
String[] getCallbackIp() throws WxErrorException;
/**
* 当本Service没有实现某个API的时候可以用这个针对所有微信API中的GET请求
* @param url

View File

@ -370,6 +370,19 @@ public class WxCpServiceImpl implements WxCpService {
return tmpJsonElement.getAsJsonObject().get("type").getAsInt();
}
@Override
public String[] getCallbackIp() throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/getcallbackip";
String responseContent = get(url, null);
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
JsonArray jsonArray = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray();
String[] ips = new String[jsonArray.size()];
for(int i = 0; i < jsonArray.size(); i++) {
ips[i] = jsonArray.get(i).getAsString();
}
return ips;
}
public String get(String url, String queryParam) throws WxErrorException {
return execute(new SimpleGetRequestExecutor(), url, queryParam);
}