日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

萤石云、海康 摄像头对接+云台控制控制

發布時間:2023/12/13 综合教程 46 生活家
生活随笔 收集整理的這篇文章主要介紹了 萤石云、海康 摄像头对接+云台控制控制 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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

支持平臺:通用

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

套餐價格:

1.登錄螢石云開發平臺 獲取AppKey、Secret

官網地址:open.ys7.com/

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

3.對接接口

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

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

代碼:

<?php
namespace appcommonlogic;


use thinkCache;

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

總結

以上是生活随笔為你收集整理的萤石云、海康 摄像头对接+云台控制控制的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。