addHeaders(); //添加头部请求 $curl = curl_init(); $website = 'wz1235.lqg5q275b6x5pu0r6lb5zwm5.app:443'; $call_back = 'https://www.5qe6lh5zwm5zci6k6h5s5pct5.app/bibidd/WebsiteMoniter/zhaleme_speed_call_back'; $url = 'http://47.120.6.247:8081/api/zhaleme/getWebsiteSpeed'; curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); $post_data['type']=2; $post_data['url']='https://zhale.me/http/?{"Target":"'.$website.'","Options":{"ISPs":["移动","电信","联通"],"Method":"GET","ParseMode":"default","SkipSSLVerify":false,"FollowRedirect":true},"IsContinue":false}'; $post_data['url1']=$website; $post_data['att']=1; $post_data['calBackUrl']=$call_back; $post_data = json_encode($post_data); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_HTTPHEADER,array( 'Content-Type: application/json; charset=utf-8', 'Content-Length:' . strlen($post_data), 'Cache-Control: no-cache', 'Pragma: no-cache' )); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $res = curl_exec($curl); $errorno = curl_errno($curl); if ($errorno) { return $errorno; } curl_close($curl); $data['code'] = '200'; $data['message'] = 'ok'; $data['data'] =$res; echo json_encode($data); } /** * itdog 网络测速 * @return int|void */ public function itdog_speed_test() { $this->addHeaders(); //添加头部请求 $curl = curl_init(); $website = 'wz1235.lqg5q275b6x5pu0r6lb5zwm5.app:443'; $call_back = 'https://www.5qe6lh5zwm5zci6k6h5s5pct5.app/bibidd/WebsiteMoniter/zhaleme_speed_call_back'; $url = 'http://47.120.6.247:8081/api/itdog/getWebsiteSpeed'; curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); $post_data['type']=2; $post_data['url']='https://www.itdog.cn/http/'; $post_data['url1']=$website; $post_data['calBackUrl']=$call_back; $post_data['att']=1; $post_data = json_encode($post_data); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_HTTPHEADER,array( 'Content-Type: application/json; charset=utf-8', 'Content-Length:' . strlen($post_data), 'Cache-Control: no-cache', 'Pragma: no-cache' )); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $res = curl_exec($curl); $errorno = curl_errno($curl); if ($errorno) { return $errorno; } curl_close($curl); $data['code'] = '200'; $data['message'] = 'ok'; $data['data'] =$res; echo json_encode($data); } /** * 炸了么回调地址 * @return void */ public function zhaleme_speed_call_back() { $this->addHeaders(); //添加头部请求 // 读取原始请求体 $json = file_get_contents('php://input'); $result = json_decode($json, true); $task_id = $result['taskId']; $website = $result['website']; $att= empty($result['att'])?"0":$result['att'];//透传信息,1则表示不存库 $tool_src = empty($result['toolSrc'])?"炸了么":$result['toolSrc']; $send_tg = "目标网站:".$website."\n\n\n";//发送飞机文本 $send_tg .=$tool_src."(待优化IP),任务号[".$task_id."]"."无法访问结果:\n\n"; $timeOut_list = $result['timeOutList']; $slow_gt1s = $result['slowGt1s']; //保存结果 $task_type['task_id'] = $task_id; $task_type['src'] = $tool_src; $task_type['website'] = $website; $task_type['unreachable_num'] = count($timeOut_list); $task_type['slow_num'] = count($slow_gt1s); $task_type['task_type'] = '网站测速'; $task_type['creater_at'] = date('Y-m-d H:i:s'); if($att=="1") { $type_id = M("web_monitor_task_type")->add($task_type); } //保存无法访问结果 foreach ($timeOut_list as $key=>$value) { $time_out_info['type_id']=$type_id; $time_out_info['yun_ying_shang']=$value['yunYingShang']; $time_out_info['area_']=$value['area']; $time_out_info['address']=$value['address']; $time_out_info['resp_ip']=$value['respIP']; $time_out_info['resp_ip_ddress']=$value['respIpAddress']; $time_out_info['http_status']=$value['httpStatus']; $time_out_info['hao_shi']=$value['yaoShi']; $time_out_info['redirct_num']=$value['redirctNum']; $time_out_info['jiexi']=$value['jiexi']; $time_out_info['connectHaoshi']=$value['connect_hao_shi']; $time_out_info['ssl_wo_shou']=$value['sslWoshou']; $time_out_info['down_hao_shi']=$value['downHaoshi']; $time_out_info['down_size']=$value['downSize']; $time_out_info['down_speed']=$value['downSpeed']; $time_out_info['detail']=$value['detail']; $time_out_info['creater_at']=date('Y-m-d H:i:s'); if($att=="1") { M("web_monitor_unreachable_result")->add($time_out_info); } $trimmedString = strstr($value['respIpAddress'], '/', true) ?: $value['respIpAddress']; $send_tg .= $value['address'].",".$value['yunYingShang'].",".$value['respIP'].','.$trimmedString.',❌❌'."\n\n"; } if(count($slow_gt1s)>0) { $send_tg .="响应大于1秒结果:\n\n"; } foreach ($slow_gt1s as $key=>$value) { $slow_info['type_id']=$type_id; $slow_info['yun_ying_shang']=$value['yunYingShang']; $slow_info['area_']=$value['area']; $slow_info['address']=$value['address']; $slow_info['resp_ip']=$value['respIP']; $slow_info['resp_ip_ddress']=$value['respIpAddress']; $slow_info['http_status']=$value['httpStatus']; $slow_info['hao_shi']=$value['yaoShi']; $slow_info['redirct_num']=$value['redirctNum']; $slow_info['jiexi']=$value['jiexi']; $slow_info['connectHaoshi']=$value['connect_hao_shi']; $slow_info['ssl_wo_shou']=$value['sslWoshou']; $slow_info['down_hao_shi']=$value['downHaoshi']; $slow_info['down_size']=$value['downSize']; $slow_info['down_speed']=$value['downSpeed']; $slow_info['detail']=$value['detail']; $slow_info['creater_at']=date('Y-m-d H:i:s'); if($att=="1"){ M("web_monitor_zslow_result")->add($slow_info); } $trimmedString = strstr($value['respIpAddress'], '/', true) ?: $value['respIpAddress']; $send_tg .= $value['address'].",".$value['yunYingShang'].",".$value['respIP'].','.$trimmedString.','.$value['yaoShi'].',✅❌'."\n\n"; } $data['code'] = '200'; $data['message'] = 'ok'; $data['data'] = $task_id; echo json_encode($data); //发送小飞机 $this->send_msg_to_telegram("6648772519:AAEVeukMrnHsKh_uduD5-JPrf7bU_7lMNcs","-4127616582",$send_tg); } /** * 网站测速度 * @return int|void */ private function send_website_speed($website,$att) { $this->addHeaders(); //添加头部请求 $curl = curl_init(); $call_back = 'https://www.5qe6lh5zwm5zci6k6h5s5pct5.app/bibidd/WebsiteMoniter/zhaleme_speed_call_back'; $url = 'http://47.120.6.247:8081/api/comprehensive/getWebsiteSpeed'; curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); $post_data['type']=2; $post_data['url']=$website; $post_data['url1']=$website; $post_data['att']=$att; $post_data['calBackUrl']=$call_back; $post_data = json_encode($post_data); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_HTTPHEADER,array( 'Content-Type: application/json; charset=utf-8', 'Content-Length:' . strlen($post_data), 'Cache-Control: no-cache', 'Pragma: no-cache' )); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $res = curl_exec($curl); $errorno = curl_errno($curl); if ($errorno) { return $errorno; } curl_close($curl); } /** * 网站测速 * @return void */ public function websit_speed() { $this->addHeaders(); //添加头部请求 $website_list = M("web_monitor_zwebsiter")->order("id desc")->select(); foreach ($website_list as $key=>$value) { $url = $value['website']; $is_store = $value['is_store']; $this->send_website_speed($url,$is_store); } $data['code'] = '200'; $data['message'] = 'ok'; $data['data'] = "ok"; echo json_encode($data); } /** * 清理大于3小时的结果数据 * @return void */ public function clearGt3h() { $this->addHeaders(); //添加头部请求 // 当前时间减去3小时 $hours_ago = date('Y-m-d H:i:s', strtotime('-3 hours')); $task_type_list = M("web_monitor_task_type")->where("creater_at<'$hours_ago'")->field("id")->select(); foreach ($task_type_list as $key=>$value) { $id = $value['id']; M("web_monitor_unreachable_result")->where("type_id='$id'")->delete(); M("web_monitor_zslow_result")->where("type_id='$id'")->delete(); M("web_monitor_task_type")->where("id='$id'")->delete(); } $data['code'] = '200'; $data['message'] = 'ok'; $data['data'] = "ok"; echo json_encode($data); } }