<?php
namespace isc;
use isc\Token;
use fast\Http;
class Api extends Token
{
     /* 查询资源列表v2
      * $name  设备名称
      */
      public function resourcesByParams($name){
          $url = '/api/irds/v2/resource/resourcesByParams';
          $data['name'] = $name;
          $data['resourceType'] = 'camera';
          $res = $this->posturl($url,$data);
          return json_decode($res,true);
      }

      /* 根据监控点编号获取萤石云设备
       * $cameraIndexCode  设备编号
       */
      public function ezvizSafeWatchKey($cameraIndexCode){
          $url = '/api/video/v1/cameras/ezvizSafeWatchKey';
          $data['cameraIndexCode'] = $cameraIndexCode;
          $res = $this->posturl($url,$data);
          return json_decode($res,true);
      }

      /* 获取监控流地址
       * $cameraIndexCode  设备编号
       * $protocol 取流协议 默认flv
       * $streamType 0:主码流 1:子码流 2:第三码流
       */
      public function getPreviewUrl($cameraIndexCode,$protocol='rtsp',$streamType=0){
          $url = '/api/video/v2/cameras/previewURLs';
          $data['cameraIndexCode'] = $cameraIndexCode;
          $data['streamType'] = $streamType;
          //$data['expand'] = "transcode=1&resolution=720P";
          $data['protocol'] = $protocol;
          $res = $this->posturl($url,$data);
          return json_decode($res,true);
      }

    /* 获取监控流地址
  * $cameraIndexCode  设备编号
  * $protocol 取流协议 默认flv
  * $streamType 0:主码流 1:子码流 2:第三码流
  */

    public function playbackUrl($cameraIndexCode,$beginTime,$endTime){

        $url = '/api/video/v2/cameras/playbackURLs';
        $data['cameraIndexCode'] = $cameraIndexCode;
        $data['beginTime'] = $beginTime;
        $data['endTime'] = $endTime;
        $data['recordLocation'] = "1";
        $data['expand'] = "transcode=1&streamform=rtp";
        $res = $this->posturl($url,$data);
        return json_decode($res,true);
    }
      /* 查询对讲URL
       * $cameraIndexCode  设备编号
       */
      public function getTalkUrl($cameraIndexCode){
          $url = '/api/video/v1/cameras/talkURLs';
          $data['cameraIndexCode'] = $cameraIndexCode;
          //$data['streamType'] = 0;
          //$data['expand'] = "transcode=1&resolution=720P";
          //$data['protocol'] = $protocol;
          $res = $this->posturl($url,$data);
          return json_decode($res,true);
      }

      /* 云台操作
       * $cameraIndexCode  设备编号
       * $action 0-开始 ,1-停止
       * $command 转向
       * $speed 云台速度,取值范围为1-100,默认50
       * $presetIndex 预置点编号
       */
      public function controlling($cameraIndexCode,$action,$command,$speed=50){
          $url = '/api/video/v1/ptzs/controlling';
          $data['cameraIndexCode'] = $cameraIndexCode;
          $data['action'] = $action;
          $data['command'] = $command;
          $data['speed'] = $speed;
          $res = $this->posturl($url,$data);
          return json_decode($res,true);
      }

      /**
       * 手动抓图
       */
      public function manualCapture($cameraIndexCode){
          $url = '/api/video/v1/manualCapture';
          $data['cameraIndexCode'] = $cameraIndexCode;
          $res = $this->posturl($url,$data);
          return json_decode($res,true);
      }
}