View Javadoc
1   package com.foxinmy.weixin4j.qy.api;
2   
3   import java.util.List;
4   
5   import com.alibaba.fastjson.JSON;
6   import com.foxinmy.weixin4j.exception.WeixinException;
7   import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
8   import com.foxinmy.weixin4j.model.Token;
9   import com.foxinmy.weixin4j.token.TokenManager;
10  
11  /**
12   * 辅助API
13   * 
14   * @className HelperApi
15   * @author jinyu(foxinmy@gmail.com)
16   * @date 2014年12月28日
17   * @since JDK 1.6
18   * @see
19   */
20  public class HelperApi extends QyApi {
21  	private final TokenManager tokenManager;
22  
23  	public HelperApi(TokenManager tokenManager) {
24  		this.tokenManager = tokenManager;
25  	}
26  
27  	/**
28  	 * 获取微信服务器IP地址
29  	 * 
30  	 * @return IP地址
31  	 * @see <a
32  	 *      href="http://qydev.weixin.qq.com/wiki/index.php?title=%E5%9B%9E%E8%B0%83%E6%A8%A1%E5%BC%8F#.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">获取IP地址</a>
33  	 * @throws WeixinException
34  	 */
35  	public List<String> getWechatServerIp() throws WeixinException {
36  		String getcallbackip_uri = getRequestUri("getcallbackip_uri");
37  		Token token = tokenManager.getCache();
38  		WeixinResponse response = weixinExecutor.get(String.format(getcallbackip_uri,
39  				token.getAccessToken()));
40  		return JSON.parseArray(response.getAsJson().getString("ip_list"),
41  				String.class);
42  	}
43  }