调用网站监测API,监测一个或多个网站的http、ping、运营商等数据
1.创建任务
2.获取监测任务列表
3.获取监测网站实时数据
4.获取监测网站实时ping响应
5.获取监测网站实时http响应
6.获取监测网站实时运营商数
网站监测API接口申请地址:https://www.juhe.cn/docs/api/id/140,获取APPKEY
PHP示例:
<!--?php
// +----------------------------------------------------------------------
// | JuhePHP [ NO ZUO NO DIE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: Juhedata <info@juhe.cn-->
// +----------------------------------------------------------------------
//----------------------------------
// 网站监测调用示例代码 - 聚合数据
// 在线接口文档:http://www.juhe.cn/docs/140
//----------------------------------
header('Content-type:text/html;charset=utf-8');
//配置您申请的appkey
$appkey = "*********************";
//************1.创建任务************
$url = "http://op.juhe.cn/webxmf/createTask";
$params = array(
"key" => $appkey,//您申请到的APPKEY
"url" => "",//要监测的网站的根域名,注意:必须是根域名,其他不支持
"dtype" => "",//返回的数据格式,json或xml,默认json
"contactPhone" => "",//
);
$paramstring = http_build_query($params);
$content = juhecurl($url,$paramstring);
$result = json_decode($content,true);
if($result){
if($result['error_code']=='0'){
print_r($result);
}else{
echo $result['error_code'].":".$result['reason'];
}
}else{
echo "请求失败";
}
//**************************************************
//************2.获取监测任务列表************
$url = "http://op.juhe.cn/webxmf/getTaskList";
$params = array(
"key" => $appkey,//您申请到的APPKEY
"dtype" => "",//返回的数据格式,json或xml,默认json
"page" => "",//页码
"pageSize" => "",//每页的个数
);
$paramstring = http_build_query($params);
$content = juhecurl($url,$paramstring);
$result = json_decode($content,true);
if($result){
if($result['error_code']=='0'){
print_r($result);
}else{
echo $result['error_code'].":".$result['reason'];
}
}else{
echo "请求失败";
}
//**************************************************
//************3.获取监测网站实时数据************
$url = "http://op.juhe.cn/webxmf/getRealTimeData";
$params = array(
"key" => $appkey,//您申请到的APPKEY
"dtype" => "",//返回的数据格式,json或xml,默认json
"siteId" => "",//网站的id,请在任务列表API里查询
"industry" => "",//行业id,请在任务列表API里查询
);
$paramstring = http_build_query($params);
$content = juhecurl($url,$paramstring);
$result = json_decode($content,true);
if($result){
if($result['error_code']=='0'){
print_r($result);
}else{
echo $result['error_code'].":".$result['reason'];
}
}else{
echo "请求失败";
}
//**************************************************
//************4.获取监测网站实时ping响应************
$url = "http://op.juhe.cn/webxmf/getPingData";
$params = array(
"key" => $appkey,//您申请到的APPKEY
"siteId" => "",//网站URL唯一标识,请在任务列表API里查询
"industry" => "",//行业代码,请在任务列表API里查询
);
$paramstring = http_build_query($params);
$content = juhecurl($url,$paramstring);
$result = json_decode($content,true);
if($result){
if($result['error_code']=='0'){
print_r($result);
}else{
echo $result['error_code'].":".$result['reason'];
}
}else{
echo "请求失败";
}
//**************************************************
//************5.获取监测网站实时http响应************
$url = "http://op.juhe.cn/webxmf/getHttpData";
$params = array(
"key" => $appkey,//您申请到的APPKEY
"siteId" => "",//网站URL唯一标识,请在任务列表API里查询
"industry" => "",//行业代码,请在任务列表API里查询
);
$paramstring = http_build_query($params);
$content = juhecurl($url,$paramstring);
$result = json_decode($content,true);
if($result){
if($result['error_code']=='0'){
print_r($result);
}else{
echo $result['error_code'].":".$result['reason'];
}
}else{
echo "请求失败";
}
//**************************************************
//************6.获取监测网站实时运营商数据************
$url = "http://op.juhe.cn/webxmf/getIspRealtime";
$params = array(
"key" => $appkey,//您申请到的APPKEY
"siteId" => "",//网站URL唯一标识,请在任务列表API里查询
);
$paramstring = http_build_query($params);
$content = juhecurl($url,$paramstring);
$result = json_decode($content,true);
if($result){
if($result['error_code']=='0'){
print_r($result);
}else{
echo $result['error_code'].":".$result['reason'];
}
}else{
echo "请求失败";
}
//**************************************************
/**
* 请求接口返回内容
* @param string $url [请求的URL地址]
* @param string $params [请求的参数]
* @param int $ipost [是否采用POST形式]
* @return string
*/
function juhecurl($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_USERAGENT , 'JuheData' );
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;
} 