由于公司在安全方面要求比较严格,如果有与外网交互的服务(比如我们现在要做的这个小程序的服务)需要在本地服务器上配置能访问进来的ip地址。
所以我需要把微信服务的ip地址配在我本地服务器的白名单里面。我在微信公众号上看到有获取微信服务器地址的接口,如下
http请求方式: GEThttps://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=ACCESS_TOKEN
问题一:这个是公众号那边的api,和小程序是不是通用的
问题二:为什么我拿
api.weixin.qq.com
这个域名在网页上解析出来后的ip地址,居然不在我上面接口获取到的ip列表里?
比如api.weixin.qq.com 这个我查询出来 是183.57.48.62 广东省深圳市 电信,他是不在上述接口所获取的ip列表里的,所以我估计,这个和域名对应的ip地址是负载均衡后的ip,不是原始服务器ip,如果是这样的话,那我要怎么才能获取所有负载均衡后的ip地址呢?
附:接口获取微信服务ip地址列表是
{"ip_list":["101.226.233.139","101.226.233.140","101.226.233.141","101.226.233.142","101.226.233.143","101.226.233.144","101.226.233.145","101.226.233.146","101.226.233.147","101.226.233.148","101.226.233.149","101.226.233.150","101.226.233.151","101.226.233.152","101.226.233.153","101.226.233.154","101.226.233.155","101.226.233.156","101.226.233.157","101.226.233.158",
"61.129.6.110","61.129.6.111","61.129.6.112","61.129.6.113","61.129.6.114",
"61.129.6.69","61.129.6.70","61.129.6.71","61.129.6.72","61.129.6.73","61.129.6.74","61.129.6.75","61.129.6.76","61.129.6.77","61.129.6.78","61.129.6.79","61.129.6.80","61.129.6.81","61.129.6.82","61.129.6.83",
"101.91.60.100","101.91.60.101","101.91.60.102","101.91.60.103","101.91.60.104","101.91.60.105","101.91.60.106","101.91.60.107","101.91.60.108","101.91.60.109","101.91.60.11","101.91.60.110",
"183.3.234.44","183.3.234.45","183.3.234.46","183.3.234.47","183.3.234.48","183.3.234.49","183.3.234.50","183.3.234.51","183.3.234.52","183.3.234.53","183.3.234.54","183.3.234.55","183.3.234.56","183.3.234.57","183.3.234.58","183.3.234.59","183.3.234.60","183.3.234.61","183.3.234.62","183.3.234.63",
"58.60.9.114","58.60.9.115","58.60.9.116","58.60.9.117","58.60.9.118","58.60.9.119","58.60.9.12","58.60.9.120",
"140.207.54.80","140.207.54.79","140.207.54.78","140.207.54.77","140.207.54.76","140.207.54.75","140.207.54.74","140.207.54.73",
"58.247.206.139","58.247.206.140","58.247.206.141","58.247.206.142","58.247.206.143","58.247.206.144","58.247.206.145","58.247.206.146","58.247.206.147","58.247.206.148","58.247.206.149","58.247.206.150","58.247.206.151","58.247.206.152","58.247.206.153","58.247.206.154","58.247.206.155","58.247.206.156","58.247.206.157","58.247.206.158",
"58.251.80.44","58.251.80.45","58.251.80.46","58.251.80.47","58.251.80.48","58.251.80.49","58.251.80.50","58.251.80.51","58.251.80.52","58.251.80.53","58.251.80.54","58.251.80.55","58.251.80.56","58.251.80.57","58.251.80.58","58.251.80.59","58.251.80.60","58.251.80.61","58.251.80.62","58.251.80.63",
"157.255.192.118","157.255.192.119","157.255.192.12","157.255.192.120","223.166.222.108","223.166.222.109","223.166.222.11","223.166.222.110","121.51.66.100","121.51.66.101","121.51.66.102","121.51.66.103","121.51.66.104","121.51.66.105","121.51.66.106","121.51.66.107","121.51.66.111","121.51.66.112","121.51.66.113","121.51.66.114","121.51.66.115","121.51.66.116","121.51.66.118","121.51.66.117","121.51.130.69","121.51.130.70","121.51.130.71","121.51.130.72","121.51.130.73","121.51.130.64","121.51.130.65","121.51.130.66","121.51.130.67","121.51.130.68","121.51.154.100","121.51.154.101","121.51.154.102","121.51.154.103","121.51.154.104","121.51.154.105","121.51.154.106","121.51.154.107","121.51.154.108","121.51.154.109","121.51.154.110","121.51.154.111","121.51.154.112","121.51.154.113","121.51.154.114","121.51.154.115","121.51.154.116","121.51.154.117","121.51.154.118","121.51.154.119","121.51.162.120","121.51.162.121","121.51.162.122","121.51.162.123","182.254.86.139","182.254.86.140","182.254.86.141","182.254.86.142","182.254.86.143","182.254.86.144","182.254.86.145","182.254.86.146","182.254.86.147","182.254.86.148","182.254.86.149","182.254.86.150","182.254.86.151","182.254.86.152","182.254.86.153","182.254.86.154","182.254.86.155","182.254.86.156","182.254.86.157","182.254.86.158","203.205.219.179","203.205.219.180","203.205.219.181","203.205.219.182","203.205.219.183","203.205.219.184","203.205.219.185","203.205.219.186","103.7.30.71","103.7.30.70","103.7.30.69","103.7.30.68"]}
微信服务器访问你 是 动态ip 的 不是固定的。
api.weixin.qq.com ---->183.57.48.62 是你访问微信服务器的。
微信服务器访问你的 自然是
ip_list
中的一个
ip_list获取
https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=
拜谢大神,我明白了:要限制来访问我服务器的ip,就只要配置ip_list里面的ip就可以了。
那如果要限制我要访问的ip地址为微信服务,应该怎么配呢?按理讲应该是api.weixin.qq.com这个域名对应的ip地址,但是好像也是不固定的啊...怎么获取所有的呢?
这个就不知道 。按理来说 ,服务器不应该限制出口的(访问外网ip),限制入口是可以的。
好的,再次感谢 !
IP太多了,限制域名不可以么?
网络请求的
referer
header 不可设置。其格式固定为https://servicewechat.com/{appid}/{version}/page-frame.html
,其中{appid}
为小程序的 appid,{version}
为小程序的版本号,版本号为0
表示为开发版、体验版以及审核版本,版本号为devtools
表示为开发者工具,其余为正式版本;