Yingshiyun.php 9.3 KB
<?php

namespace app\api\controller\reservoir\hkws;

use app\common\controller\Api;
use think\Request;
use think\Db;
use isc\Api as Iscapi;

/**
 * Class Displacement
 * @package app\api\controller
 */
class Yingshiyun extends Api
{
    protected $noNeedLogin = ['getTestCameraUrl','select_alarm_monitoring','playback','getCameraUrl','getToken', 'yuntaiStop','yuntaiCenter','getTestTalkUrl', 'take_pic', 'voice_zhanyong_username'];
    protected $noNeedRight = '*';
    public $api = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->api = new Iscapi();
    }

    /***
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 获得监控地址
     */
    public function getCameraUrl()
    {

        $cameraIndexCode = $this->request->param("cameraIndexCode");
        $protocol = $this->request->param("protocol");
        $streamType = $this->request->param("streamType");

        $type=2;
        if($streamType==0){
            $type=2;
        }else {
            $type=1;
        }
        //获得监控视频地址
        $api = new \app\api\controller\Ysyun();
        $token = $api->getaccessToken();
        //请求数据
        $post_data = [
            'accessToken' => $token,
            'deviceSerial' => $cameraIndexCode,
            'expireTime' => 600,//过期时间
            'protocol' => $protocol,//流播放协议,1-ezopen、2-hls、3-rtmp、4-flv,默认为1
            'quality' => $type,//视频清晰度,1-高清(主码流)、2-流畅(子码流)
        ];
        $res = $api->getHkAddress($post_data);
        //获得监控信息,经纬度查询天气预报
        $info = Db::name('reservoir_hkws_hardware')
            ->where(['scode' => $cameraIndexCode])
            ->field('id,latitude,longitude,indexCode,type_child_name')
            ->find();
        $res['data']['latitude'] = $info['latitude'];
        $res['data']['longitude'] = $info['longitude'];
        $res['data']['type_child_name'] = $info['type_child_name'];
        //判断是否在线 200在线
        if($res['code']=="200"){
            $res['data']['status'] = 1;

        }else{
            $res['data']['status'] = 2;

        }
        $data['camera'] = $res;
        //

        $res = $this->getTalkUrlFunc($cameraIndexCode);
        $data['talk'] = $res;


        $this->success('', $data);
    }



    /***
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 获得监控地址
     */
    public function getCameraoff()
    {
        $cameraIndexCode = $this->request->param("cameraIndexCode");
        //获得监控视频地址
        $api = new \app\api\controller\Ysyun();
        $token = $api->getaccessToken();
        //请求数据
        $post_data = [
            'accessToken' => $token,
            'deviceSerial' => $cameraIndexCode,
        ];
        $res = $api->Cameraoff($post_data);
        $data['camera'] = $res;
        $this->success('', $data);
    }

    /***
     * 云台操控开始
     */
    public function yuntaiCenter()
    {
        $cameraIndexCode = $this->request->param("cameraIndexCode");
        $action = $this->request->param("action","2");
        $speed = $this->request->param("speed","1");
        $api = new \app\api\controller\Ysyun();
        $token = $api->getaccessToken();
        //请求数据
        $post_data = [
            'accessToken' => $token,
            'deviceSerial' => $cameraIndexCode,
            'channelNo' => 1,//通道号
            'direction' => $action,//操作命令:0-上,1-下,2-左,3-右,4-左上,5-左下,6-右上,7-右下,8-放大,9-缩小,10-近焦距,11-远焦距,16-自动控制
            'speed' => $speed,//云台速度:1-适中,2-快
        ];
        $res = $api->ytCenterStart($post_data);

        $this->success('获取成功', $res);
    }
    /***
     * 云台操控结束
     */
    public function yuntaiStop()
    {
        $cameraIndexCode = $this->request->param("cameraIndexCode");
        $action = $this->request->param("action");
        $api = new \app\api\controller\Ysyun();
        $token = $api->getaccessToken();
        //请求数据
        $post_data = [
            'accessToken' => $token,
            'deviceSerial' => $cameraIndexCode,
            'channelNo' => 1,//通道号
            'direction' => $action,//操作命令:0-上,1-下,2-左,3-右,4-左上,5-左下,6-右上,7-右下,8-放大,9-缩小,10-近焦距,11-远焦距,16-自动控制
        ];
        $res = $api->ytCenterStop($post_data);

        $this->success('获取成功', $res);
    }

    public function gettoken(){
        $api = new \app\api\controller\Ysyun();
        $token = $api->getaccessToken();
        $this->success('获取成功', $token);
    }

    public function getTestCameraUrl()
    {
        $cameraIndexCode = input('get.cameraIndexCode');
        $protocol = 'rtsp';
        $streamType = 1;//input('post.streamType', 0);
        $res = $this->api->getPreviewUrl($cameraIndexCode, $protocol, $streamType);
        var_dump($res);
    }

    public function getTalkUrl()
    {
        $cameraIndexCode = input('post.cameraIndexCode');
        $res = $this->api->getTalkUrl($cameraIndexCode);
        $this->success('', $res);
    }

    public function getTalkUrlFunc($cameraIndexCode)
    {
        $res = $this->api->getTalkUrl($cameraIndexCode);
        return $res;
    }

    public function getTestTalkUrl()
    {
        $cameraIndexCode = input('get.cameraIndexCode');
        $res = $this->api->getTalkUrl($cameraIndexCode);
        $this->success('', $res);
    }

    public function yuntai()
    {
        $cameraIndexCode = input('post.cameraIndexCode');
        $action = input('post.action');
        $command = input('post.command');
        $speed = input('post.speed');
        $res = $this->api->controlling($cameraIndexCode, $action, $command, $speed);
        $this->success('', $res);
    }

    /**
     * 手动抓图
     */
    public function take_pic()
    {
        $cameraIndexCode = input('post.cameraIndexCode');
        $res = $this->api->manualCapture($cameraIndexCode);
        $this->success('', $res);
    }

    /**
     * 15. 语音通道占用与解除占用
     */
    public function operate_voice()
    {
        $param = $this->request->param();
        if (empty($param['cameraIndexCode'])) {
            $this->error("设备编码不能为空");
        }
        if (empty($param['type'])) {
            $this->error("操作类型不能为空");
        }
        $hardware = Db::name("reservoir_hkws_hardware")->where("indexCode", $param['cameraIndexCode'])->find();
        if (empty($hardware)) {
            $this->error("未找到有效设备");
        }
        if ($param['type'] == 1) {
            //开启占用
            Db::name("reservoir_hkws_hardware")->where("indexCode", $param['cameraIndexCode'])->update(["intercom_occupancy_userid" => $this->auth->id]);
            $uid = $this->auth->id;
        } elseif ($param['type'] == 2) {
            //解除占用
            Db::name("reservoir_hkws_hardware")->where("indexCode", $param['cameraIndexCode'])->update(["intercom_occupancy_userid" => ""]);
            $uid = "";
        }
        $this->success("操作成功", $uid);
    }

    /**
     * 16. 获取语音对讲占用人
     */
    public function voice_zhanyong_username()
    {
        $param = $this->request->param();
        if (empty($param['cameraIndexCode'])) {
            $this->error("设备编码不能为空");
        }

        $userid = Db::name("reservoir_hkws_hardware")->where("indexCode", $param['cameraIndexCode'])->value("intercom_occupancy_userid");
        if (empty($userid)) {
            $this->error("无人占用");
        } else {
            $staff_name = Db::name("inspection_staff")->where("user_id", $userid)->value("staff_name");
            $this->success("占用人姓名获取成功", $staff_name);
        }
    }
    public function playback(){

        $cameraIndexCode = input('post.cameraIndexCode');
        //获得监控视频地址
        $api = new \app\api\controller\Ysyun();
        $token = $api->getaccessToken();
        //请求数据
        $post_data = [
            'accessToken' => $token,
            'deviceSerial' => $cameraIndexCode,
        ];
        $res = $api->getplayback($post_data);
        $data['camera'] = $res;
        $this->success('', $data);
    }

    /**
     * 获取某个摄像头的报警信息
     * @return void
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function select_alarm_monitoring(){
        $cameraIndexCode = $this->request->param("cameraIndexCode");
        $res=Db::name("reservoir_hkws_alarm_monitoring")->where("cameraIndexCode",$cameraIndexCode)->select();
        if(!empty($res)){
            foreach ($res as $k=>$v){
                $res[$k]['alarmimage']=full_image($res[$k]['alarmimage']);
                $res[$k]['createtime']=date("Y-m-d H:i:s",$res[$k]['createtime']);
            }
        }
        $this->success("请求成功",$res);
    }
}