原理是先生成一個微信短網址,然后訪問該短網址,看是否會返回帶有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