螢石雲、海康 攝像頭對接+雲台控制控制


注:雲台控制只支持帶有該功能設備,例如螢石雲c6系列

支持平台:通用

不建議多人同時觀看的項目,適合單人觀看,多人建議升級套餐

套餐價格:

 

1.登錄螢石雲開發平台 獲取AppKey、Secret

官網地址:open.ys7.com/

2.添加購買的設備到螢石雲賬號

3.對接接口

注:本文章已對接功能 關閉設備視頻加密、獲取設備直播地址、雲台控制設備開始轉動、雲台控制設備停止轉動、設備開通直播、設備關閉直播、設備設置預置點、設備調用預置點、設備清除預置點,其他功能還支持例如設備抓拍圖片、設配在線添加、配置等功能,其他詳細功能可參考下方接口文檔

接口地址:open.ys7.com/doc/zh/book…

代碼:

 

 

 

<?php
namespace app\common\logic;


use think\Cache;

class Broadcast extends Base
{
    //螢石雲 appKey
    protected $appKey = "f777f08665f8438db7871f90899bad10"; //螢石雲 appSecret protected $appSecret = "50b5736bd6900001f0bf2db305b26b20"; //請求頭部 protected $header=['Content-Type: application/x-www-form-urlencoded']; //雲台控制 轉動速度 0-慢,1-適中,2-快,海康設備參數不可為0 protected $speed = 1; /** * 獲取授權的accessToken */ public function getAccessToken() { $url = 'https://open.ys7.com/api/lapp/token/get'; $content = "appKey=$this->appKey&appSecret=$this->appSecret"; $accessToken = Cache::get('accessToken'); if(!$accessToken){// 緩存 不存在 if($accessToken['expireTime'] < time()){//緩存 accessToken 已過期 $accessToken = $this->httpPost($url,$this->header,$content); Cache::set('accessToken',$accessToken['data']); return $accessToken['data']['accessToken']; } } return $accessToken['accessToken']; } /** * 關閉設備視頻加密 */ public function deviceDecrypt($device_number,$verification_code){ $accessToken = $this->getAccessToken(); $url='https://open.ys7.com/api/lapp/device/encrypt/off'; $content = "accessToken=$accessToken&deviceSerial=$device_number&validateCode=$verification_code"; $res=$this->httpPost($url,$this->header,$content); return $res; } /** * 獲取設備直播地址 * hlsHd 直播地址 * @param $device_number 設備號 數組形式 * @return mixed */ public function getAddress($device_number=[],$channel_number=1) { $accessToken = $this->getAccessToken(); $url='https://open.ys7.com/api/lapp/live/address/get'; $source = ''; foreach ($device_number as $key=>$value){ $source .= $value.':'.$channel_number.','; } $content = "accessToken=$accessToken&source=$source"; $res=$this->httpPost($url,$this->header,$content); return $res; } /** * 雲台控制設備開始轉動 * @param $device_number 設備序列號 * @param $direction 操作命令:0-上,1-下,2-左,3-右,4-左上,5-左下,6-右上,7-右下,8-放大,9-縮小,10-近焦距,11-遠焦距 * @return mixed */ public function startTurn($device_number,$direction) { $accessToken = $this->getAccessToken(); $url='https://open.ys7.com/api/lapp/device/ptz/start'; $content = "accessToken=$accessToken&deviceSerial=$device_number&channelNo=1&direction=$direction&speed=$this->speed"; $res=$this->httpPost($url,$this->header,$content); return $res; } /** * 雲台控制設備停止轉動 * @param $device_number 設備序列號 * @param $direction 操作命令:0-上,1-下,2-左,3-右,4-左上,5-左下,6-右上,7-右下,8-放大,9-縮小,10-近焦距,11-遠焦距 * @return mixed */ public function stopTurn($device_number,$direction=1) { $accessToken = $this->getAccessToken(); $url='https://open.ys7.com/api/lapp/device/ptz/stop'; $content = "accessToken=$accessToken&deviceSerial=$device_number&channelNo=1&direction=$direction&speed=$this->speed"; $res=$this->httpPost($url,$this->header,$content); return $res; } /** * 設備開通直播 * @param $device_number 設備號 數組 * @param int $channel_number * @return mixed */ public function openDevice($device_number,$channel_number=1) { $accessToken = $this->getAccessToken(); $url='https://open.ys7.com/api/lapp/live/video/open'; $source = ''; foreach ($device_number as $key=>$value){ $source .= $value.':'.$channel_number.','; } $content = "accessToken=$accessToken&source=$source"; $res=$this->httpPost($url,$this->header,$content); return $res; } /** * 設備關閉直播 * @param $device_number * @param int $channel_number * @return mixed */ public function closeDevice($device_number,$channel_number=1) { $accessToken = $this->getAccessToken(); $url='https://open.ys7.com/api/lapp/live/video/close'; $source = ''; foreach ($device_number as $key=>$value){ $source .= $value.':'.$channel_number.','; } $content = "accessToken=$accessToken&source=$source"; $res=$this->httpPost($url,$this->header,$content); return $res; } /** * 設備設置預置點 * @param $device_number * @param int $channel_number * @return mixed */ public function setPreset($device_number,$channel_number=1) { $accessToken = $this->getAccessToken(); $url='https://open.ys7.com/api/lapp/device/preset/add'; $content = "accessToken=$accessToken&deviceSerial=$device_number&channelNo=$channel_number"; $res=$this->httpPost($url,$this->header,$content); return $res; } /** * 設備調用預置點 * @param $device_number * @param int $channel_number * @return mixed */ public function callPreset($device_number,$index,$channel_number=1) { $accessToken = $this->getAccessToken(); $url='https://open.ys7.com/api/lapp/device/preset/move'; $content = "accessToken=$accessToken&deviceSerial=$device_number&channelNo=$channel_number&index=$index"; $res=$this->httpPost($url,$this->header,$content); return $res; } /** * 設備清除預置點 * @param $device_number * @param int $channel_number * @return mixed */ public function clearPreset($device_number,$index,$channel_number=1) { $accessToken = $this->getAccessToken(); $url='https://open.ys7.com/api/lapp/device/preset/clear'; $content = "accessToken=$accessToken&deviceSerial=$device_number&channelNo=$channel_number&index=$index"; $res=$this->httpPost($url,$this->header,$content); return $res; } /** * post 請求 * @param $url * @param $header * @param array $data * @return mixed */ public function httpPost($url,$header ,$data=array()) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); curl_setopt($ch, CURLOPT_AUTOREFERER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $status = curl_exec($ch); curl_close($ch); $res = json_decode($status, true); return $res; } }

文章轉載自:https://www.juchengvi.com/looknews/78


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM