TestsController.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: qiuzijian
  5. * Date: 2021-05-18
  6. * Time: 15:09
  7. */
  8. namespace App\Http\Controllers;
  9. use Illuminate\Support\Facades\Config;
  10. use Illuminate\Support\Facades\DB;
  11. use Illuminate\Support\Facades\Input;
  12. use Illuminate\Support\Facades\Log;
  13. use Illuminate\Support\Facades\Redis;
  14. use Modules\Camera\Entities\CameraList;
  15. use Modules\Camera\Enum\CameraEnum;
  16. use Modules\Camera\Http\Controllers\Api\HaiKangController;
  17. use Modules\Camera\Http\Controllers\Api\TdwyController;
  18. use Modules\Camera\Jobs\CameraDownload;
  19. use Modules\Camera\Services\CameraServices;
  20. use Modules\Mine\Entities\MineList;
  21. use Modules\Mine\Entities\MineListExt;
  22. use Modules\Mine\Services\MineServices;
  23. use Modules\Mine\Enum\MineEnum;
  24. use GuzzleHttp\Client;
  25. class TestsController {
  26. public function test()
  27. {
  28. //宁煤洗选重复摄像头
  29. //$this->xixuan_repeat();
  30. //新接入摄像头接口测试
  31. //$this->new_joggle();
  32. //乐橙token
  33. // $this->token();
  34. //乐橙直播列表
  35. // $this->list();
  36. //根据序列号获取直播地址和直播状态
  37. // $this->address();
  38. //区域下摄像头接口测试
  39. // $this->camera_list();
  40. //区域列表接口测试
  41. // $this->mine_list();
  42. //区域下(包含子区域)摄像头接口测试
  43. // $this->camera_all_list();
  44. }
  45. //区域列表接口测试
  46. public function mine_list(){
  47. $result = MineServices::getHaiKangArea(968, CameraEnum::REQUEST_TYPE_LOCAL);
  48. dd($result);
  49. }
  50. //区域下摄像头接口测试
  51. public function camera_list(){
  52. $camera = DB::table('mine_list')->where('id',4840)->get();
  53. $result = CameraServices::getHaiKangCamera(968, $camera[0]->index_code, CameraEnum::CAMERA_TYPE_ALL);
  54. dd($result);
  55. //同步区域下摄像头
  56. if ($result['status']) {
  57. $trans_arr = [];
  58. $index_code_arr = [];
  59. foreach ($result['data'] as $k => $v) {
  60. $ip = '';
  61. $port = '';
  62. $com_number = '';
  63. //当前摄像头index_code数组
  64. $index_code_arr[$k] = $v['camera_id'];
  65. $params = [
  66. 'mine_id' => $camera[0]->id,
  67. 'camera_name' => $this->transformCameraName($v['camera_name']),
  68. 'index_code' => $v['camera_id'],
  69. 'revert_id' => CameraEnum::CAMERA_DEFAULT_REVERT_ID,
  70. 'camera_source' => CameraEnum::CAMERA_SOURCE_2,
  71. 'ip' => $ip,
  72. 'port' => $port,
  73. 'com_number' => $com_number,
  74. ];
  75. CameraList::updateOrCreate(['index_code' => $v['camera_id']], $params);
  76. }
  77. //删除不存在的摄像头
  78. CameraList::where('mine_id', $camera[0]->id)->where('index_code', '!=', NULL)->whereNotIn('index_code', $index_code_arr)->delete();
  79. }
  80. dd('success');
  81. }
  82. //区域下摄像头接口测试
  83. public function camera_all_list(){
  84. $parent_id = 7004;
  85. $mine_id = 7004;
  86. $mine_list = DB::table('mine_list')->where('degree','like',$mine_id.'|%')->get();
  87. dd($mine_list);
  88. if(count($mine_list) > 0){
  89. for($i=0;$i<count($mine_list);$i++){
  90. $camera = DB::table('mine_list')->where('id',$mine_list[$i]->id)->get();
  91. $result = CameraServices::getHaiKangCamera($parent_id, $camera[0]->index_code, CameraEnum::CAMERA_TYPE_ALL);
  92. dd($result);
  93. //同步区域下摄像头
  94. if ($result['status']) {
  95. $trans_arr = [];
  96. $index_code_arr = [];
  97. foreach ($result['data'] as $k => $v) {
  98. $ip = '';
  99. $port = '';
  100. $com_number = '';
  101. //当前摄像头index_code数组
  102. $index_code_arr[$k] = $v['camera_id'];
  103. $params = [
  104. 'mine_id' => $camera[0]->id,
  105. 'camera_name' => $this->transformCameraName($v['camera_name']),
  106. 'index_code' => $v['camera_id'],
  107. 'revert_id' => CameraEnum::CAMERA_DEFAULT_REVERT_ID,
  108. 'camera_source' => CameraEnum::CAMERA_SOURCE_2,
  109. 'ip' => $ip,
  110. 'port' => $port,
  111. 'com_number' => $com_number,
  112. ];
  113. CameraList::updateOrCreate(['index_code' => $v['camera_id']], $params);
  114. }
  115. //删除不存在的摄像头
  116. CameraList::where('mine_id', $camera[0]->id)->where('index_code', '!=', NULL)->whereNotIn('index_code', $index_code_arr)->delete();
  117. }
  118. }
  119. }
  120. dd('success');
  121. }
  122. //转义摄像头名称中的特殊字符
  123. public function transformCameraName($camera_name)
  124. {
  125. $camera_name = trim($camera_name);
  126. $camera_name = str_replace('#', '号', $camera_name);
  127. $camera_name = str_replace(' ', '-', $camera_name);
  128. $camera_name = str_replace('+', '', $camera_name);
  129. return $camera_name;
  130. }
  131. //直播列表
  132. public function list(){
  133. // At_0000bd7f06fa796842778d92b50d4d2d
  134. $url = 'https://openapi.lechange.cn/openapi/liveList';
  135. //当前的UTC时间戳
  136. $time= strtotime(date('Y-m-d H:i:s',time()));
  137. //随机字符串
  138. $nonce = md5(time());
  139. //授权信息之appid
  140. $appId='lc753b03152e3b4f1e';
  141. //授权信息之appSecret
  142. $appSecret='cc9b1224acd24571a5daf18e8c7f94';
  143. //拼接计算“签名原始串”
  144. $signStr="time:$time,nonce:$nonce,appSecret:$appSecret";
  145. //计算摘要 sign
  146. $sign=md5($signStr);
  147. //业务参数
  148. $params = [
  149. 'token'=>'At_0000bd7f06fa796842778d92b50d4d2d',
  150. 'queryRange'=>"1-99"
  151. ];
  152. //组装调用接口的body体内容
  153. $data = json_encode([
  154. 'system'=>
  155. [
  156. 'ver'=>'1.0',
  157. 'sign'=>$sign,
  158. 'appId'=>$appId,
  159. 'time'=>$time,
  160. 'nonce'=>$nonce
  161. ],
  162. 'params'=>empty($params)? new \stdClass():$params,
  163. 'id'=>'88'
  164. ]);
  165. //http调用
  166. $ret = $this->curl_post($data, $url);
  167. $utf8 = iconv('utf-8', 'UTF-8', $ret);
  168. //调用后返回输出
  169. // dd(nl2br($utf8));
  170. $aa = json_decode(nl2br($utf8), true);
  171. dd($aa['result']['data']);
  172. }
  173. //根据序列号获取直播地址和直播状态
  174. public function address(){
  175. // At_0000bd7f06fa796842778d92b50d4d2d
  176. $url = 'https://openapi.lechange.cn/openapi/getLiveStreamInfo';
  177. //当前的UTC时间戳
  178. $time= strtotime(date('Y-m-d H:i:s',time()));
  179. //随机字符串
  180. $nonce = md5(time());
  181. //授权信息之appid
  182. $appId='lc753b03152e3b4f1e';
  183. //授权信息之appSecret
  184. $appSecret='cc9b1224acd24571a5daf18e8c7f94';
  185. //拼接计算“签名原始串”
  186. $signStr="time:$time,nonce:$nonce,appSecret:$appSecret";
  187. //计算摘要 sign
  188. $sign=md5($signStr);
  189. //业务参数
  190. $params = [
  191. 'token'=>'At_0000bd7f06fa796842778d92b50d4d2d',
  192. 'deviceId'=>'6J0C716PAZ6CF87',
  193. 'channelId'=>22
  194. ];
  195. //组装调用接口的body体内容
  196. $data = json_encode([
  197. 'system'=>
  198. [
  199. 'ver'=>'1.0',
  200. 'sign'=>$sign,
  201. 'appId'=>$appId,
  202. 'time'=>$time,
  203. 'nonce'=>$nonce
  204. ],
  205. 'params'=>empty($params)? new \stdClass():$params,
  206. 'id'=>'88'
  207. ]);
  208. //http调用
  209. $ret = $this->curl_post($data, $url);
  210. $utf8 = iconv('utf-8', 'UTF-8', $ret);
  211. //调用后返回输出
  212. dd(nl2br($utf8 ));
  213. }
  214. public function token(){
  215. // At_0000bd7f06fa796842778d92b50d4d2d
  216. $url = 'https://openapi.lechange.cn:443/openapi/accessToken';
  217. //当前的UTC时间戳
  218. $time= strtotime(date('Y-m-d H:i:s',time()));
  219. //随机字符串
  220. $nonce = md5(time());
  221. //授权信息之appid
  222. $appId='lc753b03152e3b4f1e';
  223. //授权信息之appSecret
  224. $appSecret='cc9b1224acd24571a5daf18e8c7f94';
  225. //拼接计算“签名原始串”
  226. $signStr="time:$time,nonce:$nonce,appSecret:$appSecret";
  227. //计算摘要 sign
  228. $sign=md5($signStr);
  229. //业务参数
  230. $params = [];
  231. //组装调用接口的body体内容
  232. $data = json_encode([
  233. 'system'=>
  234. [
  235. 'ver'=>'1.0',
  236. 'sign'=>$sign,
  237. 'appId'=>$appId,
  238. 'time'=>$time,
  239. 'nonce'=>$nonce
  240. ],
  241. 'params'=>empty($params)? new \stdClass():$params,
  242. 'id'=>'88'
  243. ]);
  244. //http调用
  245. $ret = $this->curl_post($data, $url);
  246. $utf8 = iconv('utf-8', 'UTF-8', $ret);
  247. //调用后返回输出
  248. echo 'result:<br>'.nl2br($utf8 ).'<br>';
  249. }
  250. function curl_post($data,$url)
  251. {
  252. $ch = curl_init();
  253. $res= curl_setopt ($ch, CURLOPT_URL,$url);
  254. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  255. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  256. curl_setopt ($ch, CURLOPT_HEADER, 0);
  257. curl_setopt($ch, CURLOPT_POST, 1);
  258. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  259. curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  260. $result = curl_exec ($ch);
  261. curl_close($ch);
  262. if ($result == NULL) {
  263. return 0;
  264. }
  265. return $result;
  266. }
  267. //新接入摄像头接口测试
  268. public function new_joggle(){
  269. $mine_id_list = MineListExt::where('is_hak', 1)->pluck('mine_id')->all();
  270. // dd($mine_id_list);
  271. $result = MineServices::getHaiKangArea(4569, CameraEnum::REQUEST_TYPE_LOCAL);//配合修改mineext和haikangcontroller里打印
  272. dd($result);
  273. }
  274. //宁煤洗选重复摄像头
  275. public function xixuan_repeat(){
  276. $mine_all = DB::table('mine_list')->where('deleted_at',null)->get();//所有区域
  277. //宁煤下各矿在离线数量
  278. $mine_list = DB::table('mine_list')->where('parent_id',968)->where('deleted_at',null)->get();
  279. $mine_use = [];//宁煤下每个矿所有区域
  280. foreach($mine_all as $key=>$value){
  281. if(count(explode('|',$value->degree)) > 1){
  282. if(explode('|',$value->degree)[0] == 968 && explode('|',$value->degree)[1] == 2429){
  283. $mine_use[] = $value->id;
  284. }
  285. }
  286. }
  287. $total = DB::table('camera_list')
  288. ->select('camera_list.camera_name','camera_list.camera_status','mine_list.title')
  289. ->leftJoin('mine_list','mine_list.id','=','camera_list.mine_id')
  290. ->whereIn('camera_list.mine_id',$mine_use)
  291. ->where('camera_list.deleted_at',null)
  292. ->where('mine_list.deleted_at',null)
  293. ->orderBy('mine_list.title')
  294. ->get();
  295. // dd($total);
  296. $aa = [];
  297. foreach($total as $k=>$v){
  298. $aa[] = $v->camera_name;
  299. }
  300. $unique_arr = array_unique ( $aa );
  301. // dd($unique_arr);
  302. $repeat_arr = array_diff_assoc ( $aa, $unique_arr );
  303. return $repeat_arr;
  304. }
  305. public function getDcsApiData() {
  306. $apiUrl = "http://7.250.4.3:4300/v1/common/GetPointRealDataByPageV3";
  307. $client = new Client();
  308. $r = request()->all();
  309. if(isset($r['p'])) {
  310. $p = $r['p'];
  311. $k = $r['k'];
  312. } else {
  313. $p = $r;
  314. }
  315. $body = [
  316. 'headers' => [
  317. 'Authorization' => 'Bearer appkey_100100',
  318. 'Content-Type'=>'application/json; charset=utf-8',
  319. // 其他头部信息
  320. ],
  321. 'json' =>[
  322. 'PageNum'=>"-1",
  323. "PointIds"=>$p
  324. ]
  325. ];
  326. // 发送 HTTP POST 请求
  327. $response = $client->post($apiUrl, $body);
  328. // 获取 API 响应的 JSON 数据
  329. $res = json_decode($response->getBody(), true);
  330. if($res['IsSuccessful'] == 0) {
  331. return $res;
  332. }
  333. $data = isset($res['Data'])? $res['Data']: null;
  334. $transformedData['data']=[];
  335. for ($i = 0; $i < count($data); $i++) {
  336. $dic = $data[$i];
  337. $trans['v'][] = $dic['V'];
  338. $trans['list'][$i] = [
  339. 'id'=>$dic['ID'],
  340. 'nm'=>$dic['PointName'],
  341. 'v'=>$dic['V'],
  342. ];
  343. $trans['kv'][$dic['ID']] = $dic['V'];
  344. }
  345. if (!empty($k) && isset($trans[$k])) {
  346. return $trans[$k];
  347. }
  348. return $trans;
  349. }
  350. public function getDcsOpcData() {
  351. // $shell = "echo 'success' ";
  352. // $shellExec = shell_exec($shell);
  353. // // var_dump($shellExec);
  354. // if($shellExec){echo 'ok';} else {echo 'error'}
  355. $pids = [
  356. "ns=12380;s=九八零变电所80Z004照明回路_Ia",
  357. "ns=12380;s=九八零变电所5105_IA",
  358. "ns=12380;s=九八零变电所5101_UB",
  359. # 添加其他节点地址...
  360. ];
  361. $pyPath = "/home/python_proj/python_custom_script/zaoquan/dcs/";
  362. $pyFName = "test1.py";
  363. $pyKeyWord = "/usr/bin/python311";
  364. $pidsJson = json_encode($pids);
  365. $command = "$pyKeyWord {$pyPath}{$pyFName}". ' ' . escapeshellarg("{$pidsJson}");
  366. // $output = shell_exec($command);
  367. // return shell_exec($command);
  368. try {
  369. // 调用Python脚本
  370. $output = shell_exec($command);
  371. // 解析Python脚本返回的JSON数据
  372. $data = json_decode($output, true);
  373. // $data['a'] = 'aaa';
  374. // 返回JSON格式的数据给前端
  375. header('Content-Type: application/json');
  376. echo json_encode($data);
  377. } catch (Exception $e) {
  378. // 返回错误消息给前端
  379. header('Content-Type: application/json');
  380. echo json_encode(array("error" => $e->getMessage()));
  381. }
  382. }
  383. }