微信推广中,域名会由于各种问题变得异常,所以我们会需要域名检测,来实时了解域名情况,检测方法五花八门,体验参差错落,其中有大部分人使用将链接生成短网址的手段来判断域名是否异常,这本身就是一种取巧行为,“生成短链接接口”本用于提升生成二维码的扫码速度和成功率。
使用说明
接口地址:http://api.monkeyapi.com
请求方式:http get/post
返回格式:json
请求示例:http://api.monkeyapi.com?appkey=appkey&url=www.baidu.com
代码示例
JAVA
public class Demo {
public static final String DEF_CHATSET = “UTF-8”;
public static final int DEF_CONN_TIMEOUT = 30000;
public static final int DEF_READ_TIMEOUT = 30000;
public static String userAgent = “Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36”;
public static void mobileQuery(){
String result =null;
String url =“http://api.monkeyapi.com”;//请求接口地址
Map params = new HashMap();//请求参数
params.put(“appkey” , “appkey”);//您申请的APPKEY
params.put(“url” , “www.monkeyapi.com”);//需要查询的网站
try {
result = net(url, params, “GET”);
JSONObject object = JSONObject.fromObject(result);
if(object.getInt(“error_code”)==0){
System.out.println(object.get(“result”));
}else{
System.out.println(object.get(“error_code”)+":"+object.get(“reason”));
}
} catch (Exception e) {
e.printStackTrace();
}
}
PHP
$url = “http://api.monkeyapi.com”;
$params = array(
‘appkey’ =>‘appkey’,//您申请的APPKEY
‘url’ =>‘www.monkeyapi.com’,//需要查询的网站
);
p a r a m s t r i n g = h t t p b u i l d q u e r y ( paramstring = http_build_query( paramstring=httpbuildquery(params);
c o n t e n t = C u r l ( content = Curl( content=Curl(url, $paramstring);
r e s u l t = j s o n d e c o d e ( result = json_decode( result=jsondecode(content, true);
if(KaTeX parse error: Expected '}', got 'EOF' at end of input: …{ var_dump(result);
}else {
//请求异常
}
// 想要详细了解可以+V mkapi002
/**
* 请求接口返回内容
* @param string $url [请求的URL地址]
* @param string $params [请求的参数]
* @param int i p o s t [ 是 否 采 用 P O S T 形 式 ] ∗ @ r e t u r n s t r i n g ∗ / f u n c t i o n C u r l ( ipost [是否采用POST形式] * @return string */ function Curl( ipost[是否采用POST形式]∗@returnstring∗/functionCurl(url, $params = false, $ispost = 0)
{
$httpInfo = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
if ($ispost) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_URL, $url);
}else {
if ($params) {
curl_setopt($ch, CURLOPT_URL, $url.'?'.$params);
} else {
curl_setopt($ch, CURLOPT_URL, $url);
}
}
$response = curl_exec($ch);
if ($response === FALSE) {
//echo "cURL Error: " . curl_error($ch);
return false;
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$httpInfo = array_merge($httpInfo, curl_getinfo($ch));
curl_close($ch);
return $response;
}
python
import json, urllib
from urllib import urlencode
url = “http://api.monkeyapi.com”
params = {
“appkey”: “appkey”, # 您申请的APPKEY
“url”: “www.monkeyapi.com”, # 需要查询的网站
}
params = urlencode(params)
f = urllib.urlopen(url, params)
content = f.read()
res = json.loads(content)
if res:
print(res)
else:
print(“请求异常”)