微信域名拦截采用云拦截的机制, 那么如果检测一个域名是否被拦截那?
1. 第一步:浏览器打开地址: https://wx.qq.com/ 登录网页微信
2. 打开浏览器调试模式, 一般为F12, 找到:
找到Cookie 和User-agnet
3. 代码 用第二部的参数替换代码中的cookie, useragent 测试:
public boolean isBlock(String domain, String userAgent, String cookie){
HttpURLConnection connection = null;
InputStream is = null;
BufferedReader br = null;
String result = null;
try {
URL url = new URL(MessageFormat.format("https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxcheckurl?requrl={0}", URLEncoder.encode(domain, "utf-8")));
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
// !!!!!! 这里是最重要的
connection.setRequestProperty("User-Agent", userAgent);
connection.setRequestProperty("Cookie", cookie);
connection.connect();
if (connection.getResponseCode() == 200) {
is = connection.getInputStream();
br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
StringBuffer sbf = new StringBuffer();
String temp = null;
while ((temp = br.readLine()) != null) {
sbf.append(temp);
sbf.append("\r\n");
}
result = sbf.toString();
}
}catch (Exception e){
System.out.println(e);
}
System.out.println(result);
if(result.contains("\"retcode\":0")){
return true;
}else{
return false;
}
}
public static void main(String args[]) throws Exception{
// 合法域名 https://www.baidu.com
// 非法域名 http://airav.cc
boolean block = new DomainController().isBlock("https://www.baidu.com",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36",
"xxxxxxxxxxxxxxxxxxxxxxxx");
System.out.println(block);
// boolean block = new DomainController().isBlock("http://airav.cc",
// "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36",
// "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
// System.out.println(block);
}
4. 个人封装接口:
5. 备注: 2019-07-26 亲自测试有效。另外网上有很多收费的版本,但是稳定性可能不高, 所谓道高一尺,魔高一丈。腾讯会不断的升级自己的策略。
微信交流:13257734257