微信开发之(三)获取微信服务器IP地址

官方文档解析:获取微信服务器IP地址

在上面的官方文档中我们可以直接在最浏览器里面进行测试例如:

请求访问这个地址,前提是已经获得了access_token的值上篇已获得:https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=ACCESS_TOKEN

  是否必须 说明
access_token 公众号的access_token

C#代码(access_token的值见上一篇的获取方法):

         /// <summary>
        /// 获取微信服务器的IP地址
        /// </summary>
        /// <returns></returns>
        private string GetWechatIpAddress(string access_token)
        {
            string url_token = "https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=" + access_token;
            HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url_token);
            myRequest.Method = "GET";
            HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
            StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
            string content = reader.ReadToEnd();
            reader.Close();
            return content;
        }

正常情况下返回的json数据包我的如下:

{"ip_list":["101.226.62.77","101.226.62.78","101.226.62.79","101.226.62.80","101.226.62.81","101.226.62.82","101.226.62.83","101.226.62.84","101.226.62.85","101.226.62.86","101.226.103.59","101.226.103.60","101.226.103.61","101.226.103.62","101.226.103.63","101.226.103.69","101.226.103.70","101.226.103.71","101.226.103.72","101.226.103.73","140.207.54.73","140.207.54.74","140.207.54.75","140.207.54.76","140.207.54.77","140.207.54.78","140.207.54.79","140.207.54.80","182.254.11.203","182.254.11.202","182.254.11.201","182.254.11.200","182.254.11.199","182.254.11.198","59.37.97.100","59.37.97.101","59.37.97.102","59.37.97.103","59.37.97.104","59.37.97.105","59.37.97.106","59.37.97.107","59.37.97.108","59.37.97.109","59.37.97.110","59.37.97.111","59.37.97.112","59.37.97.113","59.37.97.114","59.37.97.115","59.37.97.116","59.37.97.117","59.37.97.118","112.90.78.158","112.90.78.159","112.90.78.160","112.90.78.161","112.90.78.162","112.90.78.163","112.90.78.164","112.90.78.165","112.90.78.166","112.90.78.167","140.207.54.19","140.207.54.76","140.207.54.77","140.207.54.78","140.207.54.79","140.207.54.80","180.163.15.149","180.163.15.151","180.163.15.152","180.163.15.153","180.163.15.154","180.163.15.155","180.163.15.156","180.163.15.157","180.163.15.158","180.163.15.159","180.163.15.160","180.163.15.161","180.163.15.162","180.163.15.163","180.163.15.164","180.163.15.165","180.163.15.166","180.163.15.167","180.163.15.168","180.163.15.169","180.163.15.170","101.226.103.0\/25","101.226.233.128\/25","58.247.206.128\/25","182.254.86.128\/25","103.7.30.21","103.7.30.64\/26","58.251.80.32\/27","183.3.234.32\/27","121.51.130.64\/27"]}
时间: 2024-10-08 11:13:02

微信开发之(三)获取微信服务器IP地址的相关文章

微信公众号平台接口开发:基础支持,获取微信服务器IP地址

官方说明 目前看不出来这个接口有哪些具体运用,但是既然有这个接口,那我们就试试能不能用 访问接口 修改WeCharBase.cs,新增以下2个方法 1 public static string ServerIPs 2 { 3 get { return GetServerIPs(); } 4 } 5 6 /// <summary>获取所有服务器IP</summary> 7 /// <returns></returns> 8 private static str

Delphi XE7 用indy开发微信公众平台(2)- 获取微信服务器IP地址

获取微信服务器IP地址 const ServerIpUrl = 'https://api.weixin.qq.com/cgi-bin/getcallbackip?&access_token=%s'; procedure GetServerList(out List: TStringList; AccessToken: String); var Url: string; J: TJSONObject; temp: String; begin Url := Format(ServerIpUrl, [

获取微信服务器IP地址

关键字:微信公众平台 微信服务器 IP地址 如果公众号基于安全等考虑,需要获知微信服务器的IP地址列表,以便进行相关限制,可以通过该接口获得微信服务器IP地址列表. 接口调用请求说明 http请求方式: GET https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=ACCESS_TOKEN 参数说明 参数 是否必须 说明 access_token 是 公众号的access_token 返回说明 正常情况下,微信会返回下述JSON

微信开发——通过授权获取用户的基本信息

这年头,招个人不容易,现在大小活都得干了, 现在干起了微信开发这活儿,顺带写点经验. 上一回,写了篇文章是封装微信接口消息的处理的,具体可以看:实现虽易,写好不易--小玩意也能体现编码功力,微信消息处理框架发布 现在来谈谈如何获取通过微信提供的接口来获取微信用户所写的基本信息,包括国家,省,市,昵称.当然,要获取用户的信息,是要经过用户授权.关于这部份的文档,点击这里可以看到. 我要说的是具体的操作. 一.填写授权回调页面的域名 在这里填的是 wx.alinq.org.在获得用户的授权后,会跳转

Java微信开发-崔用志-微信开发-java版本

  今天看到一些关于微信开发的知识蛮好的博客,分享给大家,希望对大家有帮助. 微信开发准备(一)--Maven仓库管理新建WEB项目 微信开发准备(二)--springmvc+mybatis项目结构的搭建 微信开发准备(三)--框架以及工具的基本使用 Mybatis工具Generator 微信开发准备(四)--nat123内网地址公网映射实现 Java微信公众平台开发(一)--接入微信公众平台 Java微信公众平台开发(二)--微信服务器post消息体的接收 Java微信公众平台开发(三)--接

服务器端获取客户端的IP地址(当客户端调用由Axis开发的WebService)

一.前言 由于项目中一个小的模块需要获取客户端的IP地址以保证安全调用webservice接口,项目中客户端使用C#编写,服务器端使用Java编写,服务器端与客户端采用Axis开发的WebService进行通信.服务器端维护IP白名单列表,只有IP地址在白名单中的客户端才可以成功调用到接口,获得服务. 二.代码清单 若要成功获取客户端IP地址,需要如下Jar包的支持. servlet-api.jar axis.jar axis2-kernel-1.6.2.jar 获取IP地址的具体代码如下: i

Java获取当前服务器IP实现

package hope.ipaddress.demo; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.util.Enumeration; /** * 获取当前服务器IP * @author hp * */ public class IpDemo { /** * @param args */ public static void

关于Java获取本地服务器IP的问题

Java获取本地服务器IP,我们最简单的写法: import java.net.InetAddress; public class CatchIp{ public static void main(String[] args) { try { // 获取IP地址 String ip = InetAddress.getLocalHost().getHostAddress(); System.out.println("IP地址:"+ip); } catch (Exception e) {

Java-No.01 Java Linux下获取服务器ip地址

1.在window下获取本机ip地址 InetAddress inet = InetAddress.getLocalHost();   System.out.println("本机的ip=" + inet.getHostAddress()); 该方法在linux下获取到的ip为127.0.0.1,原因是你linux服务器上hosts配置了 127.0.0.1 localhost 可以修改hosts下将127.0.0.1改成你的本机真实ip地址 2.linux下代码获取本机ip地址 pu