TestsController.php 13 KB

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