/**
* 获取涨停股票信息
*/
public function trading()
{
$data = date('Ymd',time());
$url = "http://push2ex.eastmoney.com/getTopicZTPool?cb=&ut=7eea3edcaed734bea9cbfc24409ed989&dpt=wz.ztzt&Pageindex=0&pagesize=200&sort=fbt%3Aasc&date=$data";
$list = file_get_contents($url);
$list = json_decode($list,true);
$list = $list['data']['pool'];
$ids = [];
foreach ($list as $key=>$v){
$code = $v['c'];
$name = $v['n'];
$url = "http://static.tdx.com.cn:7615/site/tdxf10/gg_jyds/$code.html?vertype=1&style=black&gp=$code&ispc=1&8517=5390";
$html = file_get_contents($url);
$pattern = '/window\[\'tql\.CWServ\.tdxf10_gg_jyds_\d+_ztfx_\'\]="(.*)";/U';
preg_match($pattern,$html,$dir);
$data = str_replace('\\','',$dir['1']);
$data = json_decode($data,true);
if (empty($data['ResultSets']['0']['Content'])){
continue;//不存在跳出
}
$data = $data['ResultSets']['0']['Content']['0'];
$speech = $data['3'].','.$name.','.'涨停主题'.','.$data['5'];
$info = Db::name('trading')->where(['code'=>$code,'name'=>$name])->whereTime('addtime','today')->find();
if ($info){continue;}//信息插入跳出
$path = $this->speech($speech);
$add = [
'code' => $code,
'name' => $name,
'introduce'=>$speech,
'path' => $path,
'addtime'=>time()
];
if (empty($info)){
$id = Db::name('trading')->insertGetId($add);
$ids[] = $id;
}
}
$msg = Db::name('trading')->where('id','in',$ids)->select();
foreach ($msg as $k=>$item){
$msg[$k]['addtime'] = date('Y-m-d H:i:s',$item['addtime']);
}
if (empty($msg)){
return json(['code'=>0,'msg'=>'暂无数据']);
}else{
return json(['code'=>1,'msg'=>'','data'=>$msg]);
}
}
12-08
647
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-02
1810
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-08