| xqd
@@ -3,43 +3,106 @@
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
use App\Model\Communite;
|
|
|
+use App\Model\DeviceInfo;
|
|
|
+use App\Server\DeviceServer;
|
|
|
use Illuminate\Http\Request;
|
|
|
+use Illuminate\Support\Facades\Blade;
|
|
|
use QL\QueryList;
|
|
|
|
|
|
class IndexController extends Controller
|
|
|
{
|
|
|
- public function index()
|
|
|
+ public function testOpreation()
|
|
|
{
|
|
|
-//$domain = 'https://cd.lianjia.com/xiaoqu';
|
|
|
- set_time_limit(1800);
|
|
|
- for($i=1;$i<100;$i++){
|
|
|
- $areas = QueryList::get('https://cd.lianjia.com/xiaoqu'.$i,null,[
|
|
|
- 'headers' => [
|
|
|
- 'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36',
|
|
|
- 'Accept-Encoding' => 'gzip, deflate, br',
|
|
|
- ]
|
|
|
- ])->find('.position a')->attrs('href');
|
|
|
- dd($areas);
|
|
|
- foreach ($areas as $area){
|
|
|
- Communite::insert(['links'=>$area]);
|
|
|
+
|
|
|
+ $id = request('id');
|
|
|
+ $device = DeviceInfo::where(['id'=>$id])->first();
|
|
|
+ $rule = json_decode($device->lock_rule);
|
|
|
+ foreach ($rule as $key=>$box){
|
|
|
+ $device_box[] = $key;
|
|
|
+ }
|
|
|
+ return view('test_opreation',['box'=>$device_box,'device'=>$device]);
|
|
|
+ }
|
|
|
+
|
|
|
+ function object_array($array) {
|
|
|
+ if(is_object($array)) {
|
|
|
+ $array = (array)$array;
|
|
|
+ }
|
|
|
+ if(is_array($array)) {
|
|
|
+ foreach($array as $key=>$value) {
|
|
|
+ $array[$key] = object_array($value);
|
|
|
}
|
|
|
}
|
|
|
-dd($area);
|
|
|
- $link = QueryList::get('https://cd.lianjia.com/xiaoqu/1611043165264', null, [
|
|
|
- 'headers' => [
|
|
|
- 'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36',
|
|
|
- 'Accept-Encoding' => 'gzip, deflate, br',
|
|
|
- ]
|
|
|
- ])->getHtml();
|
|
|
- if($link)
|
|
|
- dd($link->getHtml());
|
|
|
- $info = QueryList::get('https://cd.lianjia.com/xiaoqu/1611043165264', null, [
|
|
|
- 'headers' => [
|
|
|
- 'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36',
|
|
|
- 'Accept-Encoding' => 'gzip, deflate, br',
|
|
|
- ]
|
|
|
- ])->find('.xiaoquDescribe')->htmls();
|
|
|
-
|
|
|
- dd($info);
|
|
|
+ return $array;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //下发协议
|
|
|
+ public function send_protocol()
|
|
|
+ {
|
|
|
+ $type = request('type');
|
|
|
+ $id = request('id');
|
|
|
+ $box_name = request('box_name');
|
|
|
+ $device = DeviceInfo::where('id',$id)->first();
|
|
|
+ if(empty($type) || empty($id)){
|
|
|
+ return json_encode(['code'=>601,'msg'=>'缺少必要参数']);
|
|
|
+ }
|
|
|
+ if(empty($device)){
|
|
|
+ return json_encode(['code'=>602,'msg'=>'设备不存在']);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $lock_rule = json_decode($device->lock_rule);
|
|
|
+ switch ($type){
|
|
|
+ case 1;
|
|
|
+ $rule = ['cmd'=>'start_test'];
|
|
|
+ break;
|
|
|
+ case 2;
|
|
|
+ $rule = ['cmd'=>'stop_test'];
|
|
|
+ break;
|
|
|
+ case 3;
|
|
|
+ $open_time = date('Y-m-d H:i:s',(time() + 180));
|
|
|
+ $close_time = date('Y-m-d H:i:s',(time() + 240));
|
|
|
+ $start_time = date('Y-m-d H:i:s',(time() - 60));
|
|
|
+ foreach ($lock_rule as $box_name){
|
|
|
+ sleep(22);
|
|
|
+ $rule = [$box_name=>['type'=>1,'start_time'=>$start_time,'open_time'=>$open_time,'close_time'=>$close_time,'value'=>'','query'=>3600]];
|
|
|
+ $res = (new DeviceServer())->sendMsg($device->device_name ,$rule);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 4;
|
|
|
+ $open_time = date('Y-m-d H:i:s',(time() + 180));
|
|
|
+ $close_time = date('Y-m-d H:i:s',(time() + 240));
|
|
|
+ $start_time = date('Y-m-d H:i:s',(time() - 60));
|
|
|
+ $rule = [$box_name=>['type'=>1,'start_time'=>$start_time,'open_time'=>$open_time,'close_time'=>$close_time,'value'=>'','query'=>3600]];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(type != 3){
|
|
|
+ $res = (new DeviceServer())->sendMsg($device->device_name,$rule);
|
|
|
+ }
|
|
|
+ if($res['Success'] == true){
|
|
|
+ return json_encode(['code'=>200,'msg'=>'下发命令成功']);
|
|
|
+ } else {
|
|
|
+ return json_encode(['code'=>400,'msg'=>'下发命令失败']);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //获取设备信息
|
|
|
+ public function get_boxname()
|
|
|
+ {
|
|
|
+
|
|
|
+ $id = request('id');
|
|
|
+ $box_name = request('box_name');
|
|
|
+ $device = DeviceInfo::where('id',$id)->first();
|
|
|
+ $rule = json_decode($device->lock_rule);
|
|
|
+ foreach ($rule as $key=>$box){
|
|
|
+ $device_box['box'][] = ['name'=>$key];
|
|
|
+ }
|
|
|
+ $device_box['id'] = $id;
|
|
|
+ $device_box['device_name'] = $device->device_name;
|
|
|
+ return json_encode(['code'=>200,'msg'=>'ok','data'=>$device_box]);
|
|
|
}
|
|
|
}
|