原理是先生成一个微信短网址,然后访问该短网址,看是否会返回带有weixin110.qq.com这样的关键字。
参考 https://www.pianshen.com/article/4855274152/
# 检查域名是否被封
def check_domain_killed(domain):
try:
check_url = "http://%s" % domain
short_url = create_wechat_short_url(check_url)
if short_url:
return_url = requests.get(url=short_url, timeout=30).url
if "weixin110.qq.com" in return_url:
push_msg("封号提醒", '域名' + domain + '被封')
else:
return False
except Exception as e:
return False
# 创建微信短域名
def create_wechat_short_url(domain):
try:
access_token_string = "" # 这里根据文档从微信获取access_token
to_short_params = {
"access_token": access_token_string,
"action": "long2short",
"long_url": domain
}
short_url = "https://api.weixin.qq.com/cgi-bin/shorturl?access_token=%s" % access_token_string
weixin_response = requests.post(url=short_url, data=json.dumps(to_short_params)).json()
short_url = weixin_response.get("short_url")
return short_url
except Exception as e:
return False
