内容简介:由于微信限制比较严格,域名一不小心就被判定是诱导分享的。所以,公司内部决定调研一套稳定、快速、正确率高的微信域名拦截检测查询接口。开发组尝试谷歌搜索了一段时间,发现很少把源码及原理分享出来的。后来我们摸索了几天,终于解决这个问题。使用
背景
由于微信限制比较严格,域名一不小心就被判定是诱导分享的。所以,公司内部决定调研一套稳定、快速、正确率高的微信域名拦截检测查询接口。
开发组尝试谷歌搜索了一段时间,发现很少把源码及原理分享出来的。后来我们摸索了几天,终于解决这个问题。
源码
原理
使用 Wireshark
抓包获取微信的域名拦截查询接口。
域名有如下几种状态:
- 域名能正常访问(未被微信拦截)
-
域名被微信拦截
- 非微信官方网页,继续访问将转换成手机预览模式(在公众号后台把域名添加到业务域名一般能解决这个问题)
- 据用户投诉及腾讯安全网址安全中心检测,该网页包含恶意欺诈内容,为维护绿色上网环境,已停止访问
- 网页包含诱导分享、关注等诱导行为内容,被多人投诉,为维护绿色上网环境,已停止访问
Demo
PHP 版
<?php
// 您的 API Token,在用户中心可查询到
$apiToken = "********************************";
// 需要检测的地址或域名
$reqUrl = "www.qq.com";
$url = sprintf("https://wx.horocn.com/api/v1/wxUrlCheck?api_token=%s&req_url=%s", $apiToken, $reqUrl);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$responseBody = curl_exec($ch);
$responseArr = json_decode($responseBody, true);
if (json_last_error() != JSON_ERROR_NONE) {
echo "JSON 解析接口结果出错\n";
return;
}
if (isset($responseArr['code']) && $responseArr['code'] == 0) {
// 接口正确返回
// $responseArr['data']['status'] 的取值范围:ok、blocked
// ok 表示正常、blocked 表示被封
printf("测试地址(%s)的状态为:%s\n", $reqUrl, $responseArr['data']['status']);
} else {
printf("接口异常:%s\n", var_export($responseArr, true));
}
Python 版
# -*- coding: utf-8 -*-
import json, urllib
from urllib import urlencode
def main():
# 您的 API Token,在用户中心可查询到
apiToken = "*********************"
url = "https://wx.horocn.com/api/v1/wxUrlCheck"
params = {
"req_url" : "www.qq.com", #需要检测的地址或域名
"api_token" : apiToken,
}
params = urlencode(params)
f = urllib.urlopen("%s?%s" % (url, params))
content = f.read()
res = json.loads(content)
if res:
code = res["code"]
if code == 0:
#成功请求
print res["result"]
else:
print "%s: %s" % (res["code"],res["msg"])
else:
print "request api error"
if __name__ == '__main__':
main()
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
About Face 3
Alan Cooper、Robert Reimann、David Cronin / John Wiley & Sons / 2007-5-15 / GBP 28.99
* The return of the authoritative bestseller includes all new content relevant to the popularization of how About Face maintains its relevance to new Web technologies such as AJAX and mobile platforms......一起来看看 《About Face 3》 这本书的介绍吧!