# 获取微信服务器IP地址

如果公众号基于安全等考虑,需要获知微信服务器的IP地址列表,以便进行相关限制,可以通过该接口获得微信服务器IP地址列表或者IP网段信息。

由于出口IP及入口IP可能存在变动,建议用户每天请求接口1次,以便于及时更新IP列表。为了避免造成单点故障,强烈建议用户不要长期使用旧的IP列表作为api.weixin.qq.com的访问入口。

# 1. 获取微信API接口 IP地址

使用固定IP访问api.weixin.qq.com时,请开发者注意运营商适配,跨运营商访问可能会存在高峰期丢包问题。

API接口IP即api.weixin.qq.com的解析地址,由开发者调用微信侧的接入IP。

接口调用请求说明

http请求方式: GET https://api.weixin.qq.com/cgi-bin/get_api_domain_ip?access_token=ACCESS_TOKEN

参数说明

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

返回说明

正常情况下,微信会返回下述JSON数据包给公众号:

{
	"ip_list": [
		"101.89.47.18",
		"101.91.34.103",
		"101.91.37.13",
		"109.244.129.223",
		"109.244.145.152",
		"109.244.184.250",
		"112.53.42.235",
		"112.60.20.154",
		"112.65.193.153",
		"112.90.80.215",
		"116.128.170.42",
		"116.128.184.169",
		"117.144.228.18",
		"117.144.228.62",
		"119.147.6.203",
		"119.147.6.237",
		"120.232.65.161",
		"120.233.18.202",
		"121.14.23.85",
		"129.226.107.92",
		"157.148.36.94",
		"157.148.58.82",
		"157.255.218.109",
		"162.62.115.186",
		"162.62.115.246",
		"175.27.18.18",
		"175.27.5.221",
		"183.2.143.222",
		"221.181.99.40",
		"43.129.2.204",
		"43.130.8.250",
		"43.130.8.50",
		"43.141.57.197",
		"43.159.233.227",
		"81.69.216.43"
	]
}
参数 说明
ip_list 微信服务器IP地址列表

错误时微信会返回错误码等信息,JSON数据包示例如下(该示例为AppID无效错误):

{"errcode":40013,"errmsg":"invalid appid"}

# 2. 获取微信callback IP地址

请开发者确保防火墙、ddos攻击白名单IP内已添加回调IP,以避免误拦截的情况出现。

callback IP即微信调用开发者服务器所使用的出口IP。

接口调用请求说明

http请求方式: GET https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=ACCESS_TOKEN

参数说明

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

返回说明

正常情况下,微信会返回下述JSON数据包给公众号:

{
	"ip_list": [
		"106.55.206.146",
		"106.55.206.211",
		"106.55.207.148",
		"106.55.207.31",
		"118.126.124.186",
		"118.126.124.246",
		"119.29.180.49",
		"119.29.9.101",
		"124.223.151.119",
		"129.226.105.242",
		"162.62.80.57",
		"162.62.80.8",
		"162.62.81.123",
		"175.24.211.142",
		"175.24.211.157",
		"175.24.211.198",
		"175.24.211.31",
		"175.24.211.4",
		"175.24.212.10",
		"175.24.212.185",
		"175.24.212.195",
		"175.24.213.149",
		"175.24.214.150",
		"175.24.214.222",
		"175.27.64.215",
		"175.27.65.216",
		"42.192.0.152",
		"42.192.0.224",
		"42.192.6.57",
		"43.132.112.30",
		"43.132.141.238",
		"43.137.147.169",
		"43.143.52.12",
		"43.143.59.119",
		"81.69.101.193",
		"81.69.101.225",
		"81.69.101.233",
		"81.69.101.237",
		"81.69.103.129",
		"81.69.103.147",
		"81.69.103.163",
		"81.69.103.205",
		"81.69.103.236",
		"81.69.103.238",
		"81.69.103.37",
		"81.69.103.74",
		"81.71.140.59",
		"81.71.19.101"
	]
}
参数 说明
ip_list 微信服务器IP地址列表

错误时微信会返回错误码等信息,JSON数据包示例如下(该示例为AppID无效错误):

{"errcode":40013,"errmsg":"invalid appid"}