123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- <?php
- namespace App\Support\Sdk\Ai;
- use GuzzleHttp\Client;
- class AiGate
- {
- private static $instance;
- public function __construct()
- {
- }
- private function __clone()
- {
- }
- public static function getInstance()
- {
- if (null === static::$instance) {
- static::$instance = new static();
- }
- return static::$instance;
- }
- const URL = 'http://120.76.128.30:8082/';
- const USER_NAME = 'ximeng';
- const USER_PWD = '888888';
- private static function post($url, $getParam = [], $postParam = [])
- {
- $client = new Client();
- $getParam['Uid'] = self::USER_NAME;
- $getParam['Pwd'] = self::USER_PWD;
- $queryString = http_build_query($getParam);
- $url = self::URL . "{$url}?{$queryString}";
- $response = $client->request('POST', $url, [
- 'json' => $postParam,
- 'headers' => [
- 'Content-Type' => 'application/json'
- ],
- ]);
- if ($response->getStatusCode() == 200) {
- $result = $response->getBody()->getContents();
- $result = str_replace('', '', $result);
- $result = js2php($result);
- return $result;
- }
- return false;
- }
- /**
- * 获取 AIBox 列表
- * @return false|mixed
- */
- public function getHosts()
- {
- $response = self::post('AiBoxDevice_GetList');
- return $response;
- }
- /**
- * 添加 AIBox
- * @param $name
- * @param $code
- * @return false|mixed
- */
- public function addHost($name, $code)
- {
- $response = self::post('AiBoxDevice_Add', [
- 'HostCode' => $code,
- 'Name' => $name,
- ]);
- return $response;
- }
- /**
- * 添加 AIBox
- * @param $name
- * @param $code
- * @return false|mixed
- */
- public function delHost($deviceId)
- {
- $response = self::post('AiBoxDevice_Delete', [
- 'AiBoxDeviceId' => $deviceId,
- ]);
- return $response;
- }
- /**
- * @param $code
- * @return false|mixed]
- */
- public function getHost($code)
- {
- $response = self::post('AiBoxDevice_GetModelByHostCode', [
- 'HostCode' => $code,
- ]);
- return $response;
- }
- /**
- * 获得盒子下面的通道
- * @param $deviceId
- * @return false|mixed
- */
- public function getHostChannels($deviceId)
- {
- $response = self::post('AiChannel_GetListByAiBoxDeviceID', [
- 'AiBoxDeviceId' => $deviceId,
- ]);
- return $response;
- }
- /**
- * 获取通道和规则
- * @param $code
- * @return false|mixed
- */
- public function getHostChannelsAndRules($code)
- {
- $response = self::post('AiBoxDevice_GetChannels', [
- 'HostCode' => $code,
- ]);
- return $response;
- }
- /**
- * 重启盒子
- * @param $code
- * @return false|mixed
- */
- public function reboot($code)
- {
- $response = self::post('AiBoxDevice_Reboot', [
- 'HostCode' => $code,
- ]);
- return $response;
- }
- /**
- * 重启盒子内核程序
- * @param $code
- * @return false|mixed
- */
- public function reStartup($code)
- {
- $response = self::post('AiBoxDevice_ReStartup', [
- 'HostCode' => $code,
- ]);
- return $response;
- }
- /**
- * 通道下面的AI规则
- * @param $channelId
- * @return false|mixed
- */
- public function getChannelsRules($channelId)
- {
- $response = self::post('AiChannelRule_GetListByAiChannelID', [
- 'AiChannelId' => $channelId,
- ]);
- return $response;
- }
- /**
- * 抓拍图片
- * @param $code
- * @param $channelId
- * @return false|mixed
- */
- public function takePicture($code, $channelId)
- {
- $response = self::post('GetAiBoxChannelOneLiveFrameJpegResponse', [
- 'HostCode' => $code,
- 'ChannelId' => $channelId,
- ]);
- return $response;
- }
- /**
- * 获取抓拍历史纪录
- * @param $code
- * @param $param
- * @return false|mixed
- */
- public function getEvents($code, $param = [])
- {
- $response = self::post('AiBoxDevice_GetEventRecord', [
- 'HostCode' => $code,
- ], $param);
- return $response;
- }
- /**
- * @param $code
- * @param $param
- * @return false|mixed
- */
- public function getOutBoxs($code)
- {
- $response = self::post('AiBoxDevice_GetOutputDb', [
- 'HostCode' => $code,
- ]);
- return $response;
- }
- }
|