TestsController.php 11 KB

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