TestsController.php 12 KB

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