随机视频,天气查询

This commit is contained in:
muzihuaner
2026-03-18 13:16:49 +08:00
parent cf64fdc6f5
commit a5a679b69b
4 changed files with 298 additions and 0 deletions

110
api/icp/index.php Normal file
View File

@@ -0,0 +1,110 @@
<?php
$file = 'counter.dat';
// 读取并自增
$counter = (int)@file_get_contents($file);
$counter++;
// 使用 LOCK_EX 防止并发写入冲突
file_put_contents($file, $counter, LOCK_EX);
?>
<?php
Header('Content-type: Application/json; charset=utf-8');
require '../../need.php';
$Request = need::Request();
$type = isset($Request['type']) ? $Request['type'] : 'json'; //获取返回格式 默认json
$url = isset($Request['url']) ? $Request['url'] : '';
new icp(['url'=>$url, 'type'=>$type]);
class icp
{
private $info = [];
private $array = [];
private $Message;
public function __construct(array $array)
{
/* php构造函数 类初始化时自动运行 */
foreach($array as $k=>$v)
{
/* for循环获取参数并赋值到类中使用 */
$this->info[$k] = $v;
}
$this->parameterException(); //调用类中方法
}
private function parameterException()
{
/* 判断参数是否正常 */
if(!stristr($this->info['url'], 'http'))
{
$this->info['url'] = 'http://'.$this->info['url'];
}
$host = parse_url($this->info['url'], PHP_URL_HOST);
if(!$host)
{
$this->evaluation(array('code'=>-1, 'text'=>'请输入正确的域名'));
return;
}
$this->run(); //调用方法
return true;
}
private function Run()
{
$scheme = @parse_url($this->info['url'], PHP_URL_SCHEME);
$host = @parse_url($this->info['url'], PHP_URL_HOST);
$url = $scheme.'://'.$host;
$data = json_decode(trim(preg_replace('/([a-z]+):/i', '"$1":', preg_replace('/jQuery\((.*)\)/', '$1', need::teacher_curl('https://micp.chinaz.com/Handle/AjaxHandler.ashx?action=GetPermit&callback=jQuery&query='.$host.'&type=host&_=1672673081420')))));
// print_r($data);
if(!isset($data->Typ))
{
$this->evaluation(array('code'=>-2, 'text'=>'备案数据获取失败'));
return;
}
$String = '';
$array = array(
'unit'=>$data->ComName,
'property'=>$data->Typ,
'record'=>$data->Permit,
'hostname'=>$data->WebName,
);
$String = "主办单位:{$data->ComName}\n单位性质{$data->Typ}\n网站名字{$data->WebName}\n网站备案号{$data->Permit}";
$String = trim($String, PHP_EOL);
$this->evaluation(array('code'=>1, 'text'=>'获取成功', 'data'=>$array), $String);
return;
}
private function delete() : bool
{
/* 删除已有参数 */
unset($this->array, $this->Message);
return true;
}
private function evaluation(array $array, $string = false) : bool
{
/* 输出数据 */
$string = $string ? $string : $array['text']; //判断$string是否存在
$this->delete(); //调用删除方法
$this->array = $array; //赋值
$this->Message = $string; //赋值
$this->result(); //输出内容
return true;
}
private function result()
{
$info = $this->info;
$type = isset($info['type']) ? $info['type'] : 'json';
Switch($type)
{
case 'text':
need::send($this->Message, 'text');
break;
default:
need::send($this->array, 'json');
break;
}
return true;
}
}

View File

@@ -1,3 +1,13 @@
<?php
$file = 'counter.dat';
// 读取并自增
$counter = (int)@file_get_contents($file);
$counter++;
// 使用 LOCK_EX 防止并发写入冲突
file_put_contents($file, $counter, LOCK_EX);
?>
<?php
Header('content-type: application/json');
require ('../../curl.php');//引进封装好的curl文件

126
api/tq/index.php Normal file
View File

@@ -0,0 +1,126 @@
<?php
$file = 'counter.dat';
// 读取并自增
$counter = (int)@file_get_contents($file);
$counter++;
// 使用 LOCK_EX 防止并发写入冲突
file_put_contents($file, $counter, LOCK_EX);
require '../../need.php';
/* End */
header("Content-type: application/json");
function jiequ($txt1,$q1,$h1)
{
$txt1=strstr($txt1,$q1);
$cd=strlen($q1);
$txt1=substr($txt1,$cd);
$txt1=strstr($txt1,$h1,"TRUE");
return $txt1;
}
$msg=@$_REQUEST['msg'];
$b=@$_REQUEST['b'];
$type = @$_REQUEST['type'];
$num = @$_REQUEST['num'];
new 三日天气多选(Array('name'=>$msg, 'n'=>$b, 'num'=>$num, 'type'=>$type));
class 三日天气多选{
protected $info = [];
protected $Array = [];
protected $Msg;
public function __construct(Array $Array){
foreach($Array as $k=>$v){
$this->info[$k] = $v;
}
$this->ParameterException();
}
protected function ParameterException(){
$name = $this->info['name'];
if(empty($name)){
$this->Array = Array('code'=>-1, 'text'=>'请输入地名');
$this->send();
return;
}
$n = $this->info['n'];
if($n > 0 && is_numEric($n)){
$this->info['n'] = $n - 1;
}else{
$this->info['n'] = false;
}
$num = $this->info['num'];
if($num < 1 && is_numEric($num)){
$this->info['num'] = 10;
}else{
$this->info['num'] = 10;
}
$this->Getdata();
return;
}
protected function Getdata(){
$name = ($this->info['name']);
$data = need::teacher_curl('http://m.moji.com/api/citysearch/'.$name);
$result = preg_match_all("/{\"cityId\":(.*?),\"city_lable\":(.*?),\"counname\":\"(.*?)\",\"id\":(.*?),\"localCounname\":\"(.*?)\",\"localName\":\"(.*?)\",\"localPname\":\"(.*?)\",\"name\":\"(.*?)\",\"pname\":\"(.*?)\"}/",$data,$nute);
$n = $this->info['n'];
//print_r($nute);exit;
$Array = [];
$num = $this->info['num'];
if($n === false){
for ($x=0; $x < $result && $x < $num; $x++) {
$jec=$nute[6][$x];
$je=$nute[7][$x];
$echo .= ($x+1)."".$je."-".$jec."\n";
$Array[] = Array('city'=>$je, 'city_t'=>$jec);
}
$this->Msg = trim($echo);
$this->Array = Array('code'=>1, 'text'=>'获取成功', 'data'=>$Array);
$this->send();
return;
}
$je=$nute[1][$n];
$jec=$nute[6][$n];
$data = file_Get_Contents("http://m.moji.com/api/redirect/".$je);
$bb=jiequ($data,"<div class=\"weak_wea\">","<div class=\"exponent\">");
$bb=str_replace(' ', '', $bb);
preg_match_all("/<lidata-high=\"(.*?)\"data-low=\"(.*?)\">/",$bb,$aa);
preg_match_all("/<em>(.*?)<\/em>/",$bb,$qq);
preg_match_all("/<dd><strong>(.*?)<\/strong><\/dd>/",$bb,$cc);
preg_match_all("/<pclass=\"(.*?)\">(.*?)<\/p><dlclass=\"wind\">/",$bb,$dd);
preg_match_all("/<dd>(.*?)<\/dd>/",$bb,$ee);
preg_match_all("/<dd>(.*?)<\/dd>/",$bb,$ff);
if(empty($aa[2][0])){
$this->Msg = '不支持';
$this->Array = Array('code'=>-2, 'text'=>'不支持');
$this->send();
return;
}
$this->Msg = "☁.查询:".$jec."\n☁.日期:".$qq[1][0]."\n☁.温度:".$aa[2][0]."".$aa[1][0]."\n☁.天气:".$cc[1][0]."\n☁.风度:".$ee[1][2]."-".$ff[1][3]."\n☁.空气质量:".$dd[2][0]."\n\n☁.日期:".$qq[1][1]."\n☁.温度:".$aa[2][1]."".$aa[1][1]."\n☁.天气:".$cc[1][1]."\n☁.风度:".$ee[1][6]."-".$ff[1][7]."\n☁.空气质量:".$dd[2][1]."\n\n☁.日期:".$qq[1][2]."\n☁.温度:".$aa[2][2]."".$aa[1][2]."\n☁.天气:".$cc[1][2]."\n☁.风度:".$ee[1][10]."-".$ff[1][11]."\n☁.空气质量:".$dd[2][2]."";
$this->Array = Array('code'=>1, 'text'=>'获取成功', 'data'=>Array('city'=>$jec, 'data'=>Array(Array('Time'=>$qq[1][0], 'temperature'=>$aa[2][0]."".$aa[1][0]."", 'weather'=>$cc[1][0], 'bearing'=>$ee[1][2]."-".$ff[1][3], 'air_quality'=>$dd[2][0]), Array('Time'=>$qq[1][1], 'temperature'=>$aa[2][1]."".$aa[1][1]."", 'weather'=>$cc[1][1], 'bearing'=>$ee[1][6]."-".$ff[1][7], 'air_quality'=>$dd[2][1]), Array('Time'=>$qq[1][2], 'temperature'=>$aa[2][2]."".$aa[1][2]."", 'weather'=>$cc[1][2], 'bearing'=>$ee[1][10]."-".$ff[1][11], 'air_quality'=>$dd[2][2]))));
$this->send();
return;
}
public function send(){
$type = $this->info['type'];
$data = $this->Array;
if($data['data']['city']){
Switch($type){
case 'text':
need::send($this->Msg, 'text');
break;
default:
need::send($data);
break;
}
}else{
Switch($type){
case 'text':
need::send($this->Msg, 'text');
break;
default:
need::send($data);
break;
}
}
}
}