AiCAS.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <?php
  2. namespace App\Support\Sdk\Ai;
  3. use GuzzleHttp\Client;
  4. class AiCAS
  5. {
  6. private static $instance;
  7. public function __construct()
  8. {
  9. }
  10. private function __clone()
  11. {
  12. }
  13. public static function getInstance()
  14. {
  15. if (null === static::$instance) {
  16. static::$instance = new static();
  17. }
  18. return static::$instance;
  19. }
  20. const URL = 'http://120.76.128.30:8082/';
  21. const USER_NAME = 'ximeng';
  22. const USER_PWD = '888888';
  23. private static function post($url, $getParam = [], $postParam = [])
  24. {
  25. $client = new Client();
  26. $getParam['Uid'] = self::USER_NAME;
  27. $getParam['Pwd'] = self::USER_PWD;
  28. $queryString = http_build_query($getParam);
  29. $url = self::URL . "{$url}?{$queryString}";
  30. $response = $client->request('POST', $url, [
  31. 'json' => $postParam,
  32. 'headers' => [
  33. 'Content-Type' => 'application/json'
  34. ],
  35. ]);
  36. if ($response->getStatusCode() == 200) {
  37. $result = $response->getBody()->getContents();
  38. $result = str_replace('', '', $result);
  39. $result = js2php($result);
  40. return $result;
  41. }
  42. return false;
  43. }
  44. /**
  45. * 获取 AIBox 列表
  46. * @return false|mixed
  47. */
  48. public function getHosts()
  49. {
  50. $response = self::post('AiBoxDevice_GetList');
  51. return $response;
  52. }
  53. /**
  54. * 添加 AIBox
  55. * @param $name
  56. * @param $code
  57. * @return false|mixed
  58. */
  59. public function addHost($name, $code)
  60. {
  61. $response = self::post('AiBoxDevice_Add', [
  62. 'HostCode' => $code,
  63. 'Name' => $name,
  64. ]);
  65. return $response;
  66. }
  67. /**
  68. * 添加 AIBox
  69. * @param $name
  70. * @param $code
  71. * @return false|mixed
  72. */
  73. public function delHost($deviceId)
  74. {
  75. $response = self::post('AiBoxDevice_Delete', [
  76. 'AiBoxDeviceId' => $deviceId,
  77. ]);
  78. return $response;
  79. }
  80. /**
  81. * @param $code
  82. * @return false|mixed]
  83. */
  84. public function getHost($code)
  85. {
  86. $response = self::post('AiBoxDevice_GetModelByHostCode', [
  87. 'HostCode' => $code,
  88. ]);
  89. return $response;
  90. }
  91. /**
  92. * 获得盒子下面的通道
  93. * @param $deviceId
  94. * @return false|mixed
  95. */
  96. public function getHostChannels($deviceId)
  97. {
  98. $response = self::post('AiChannel_GetListByAiBoxDeviceID', [
  99. 'AiBoxDeviceId' => $deviceId,
  100. ]);
  101. return $response;
  102. }
  103. /**
  104. * 获取通道和规则
  105. * @param $code
  106. * @return false|mixed
  107. */
  108. public function getHostChannelsAndRules($code)
  109. {
  110. $response = self::post('AiBoxDevice_GetChannels', [
  111. 'HostCode' => $code,
  112. ]);
  113. return $response;
  114. }
  115. /**
  116. * 重启盒子
  117. * @param $code
  118. * @return false|mixed
  119. */
  120. public function reboot($code)
  121. {
  122. $response = self::post('AiBoxDevice_Reboot', [
  123. 'HostCode' => $code,
  124. ]);
  125. return $response;
  126. }
  127. /**
  128. * 重启盒子内核程序
  129. * @param $code
  130. * @return false|mixed
  131. */
  132. public function reStartup($code)
  133. {
  134. $response = self::post('AiBoxDevice_ReStartup', [
  135. 'HostCode' => $code,
  136. ]);
  137. return $response;
  138. }
  139. /**
  140. * 通道下面的AI规则
  141. * @param $channelId
  142. * @return false|mixed
  143. */
  144. public function getChannelsRules($channelId)
  145. {
  146. $response = self::post('AiChannelRule_GetListByAiChannelID', [
  147. 'AiChannelId' => $channelId,
  148. ]);
  149. return $response;
  150. }
  151. /**
  152. * 抓拍图片
  153. * @param $code
  154. * @param $channelId
  155. * @return false|mixed
  156. */
  157. public function takePicture($code, $channelId)
  158. {
  159. $response = self::post('GetAiBoxChannelOneLiveFrameJpegResponse', [
  160. 'HostCode' => $code,
  161. 'ChannelId' => $channelId,
  162. ]);
  163. return $response;
  164. }
  165. /**
  166. * 获取抓拍历史纪录
  167. * @param $code
  168. * @param $param
  169. * @return false|mixed
  170. */
  171. public function getEvents($code, $param = [])
  172. {
  173. $response = self::post('AiBoxDevice_GetEventRecord', [
  174. 'HostCode' => $code,
  175. ], $param);
  176. return $response;
  177. }
  178. /**
  179. * @param $code
  180. * @param $param
  181. * @return false|mixed
  182. */
  183. public function getOutBoxs($code)
  184. {
  185. $response = self::post('AiBoxDevice_GetOutputDb_Json', [
  186. 'HostCode' => $code,
  187. ]);
  188. return $response;
  189. }
  190. /**
  191. * 播放语音
  192. * @param $code
  193. * @param $outputDeviceID
  194. * @param $text
  195. * @param $volume
  196. * @return false|mixed
  197. */
  198. public function playVoice($code, $outputDeviceID, $text, $volume = 100)
  199. {
  200. $response = self::post('AiBoxDevice_TextToTtsVoice', [
  201. "HostCode" => $code,
  202. ], [
  203. "HostCode" => $code,
  204. "OutputDeviceID" => $outputDeviceID,
  205. "Text" => $text,
  206. "Volume" => $volume,
  207. ]);
  208. return $response;
  209. }
  210. /**
  211. * 控制继电器
  212. * @param $code
  213. * @param $outputDeviceID
  214. * @param $Channel
  215. * @param $Value
  216. * @param $DelaySec
  217. * @param $OutputType
  218. * @return false|mixed
  219. */
  220. public function openGate($code, $outputDeviceID, $Channel, $Value, $DelaySec = 0, $OutputType = 2)
  221. {
  222. $response = self::post('AiBoxDevice_RelayOutputControl', [
  223. "HostCode" => $code,
  224. ], [
  225. "OutputType" => $OutputType,
  226. "OutputDeviceID" => $outputDeviceID,
  227. "Channel" => $Channel,
  228. "Value" => $Value,
  229. "DelaySec" => $DelaySec,
  230. ]);
  231. return $response;
  232. }
  233. }