| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353 |
- <?php
- /**
- * Created by PhpStorm.
- * User: qiuzijian
- * Date: 2021-05-18
- * Time: 15:09
- */
- namespace App\Http\Controllers;
- use Illuminate\Support\Facades\Config;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Input;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Redis;
- use Modules\Camera\Entities\CameraList;
- use Modules\Camera\Enum\CameraEnum;
- use Modules\Camera\Http\Controllers\Api\HaiKangController;
- use Modules\Camera\Http\Controllers\Api\TdwyController;
- use Modules\Camera\Jobs\CameraDownload;
- use Modules\Camera\Services\CameraServices;
- use Modules\Mine\Entities\MineList;
- use Modules\Mine\Entities\MineListExt;
- use Modules\Mine\Services\MineServices;
- use Modules\Mine\Enum\MineEnum;
- use GuzzleHttp\Client;
- class TestsController {
- public function test()
- {
- $res = DB::connection('etl_zaoquan')->select("select * from news_column_list")->get();
- dd($res);
- //宁煤洗选重复摄像头
- //$this->xixuan_repeat();
- //新接入摄像头接口测试
- //$this->new_joggle();
- //乐橙token
- // $this->token();
- //乐橙直播列表
- // $this->list();
- //根据序列号获取直播地址和直播状态
- // $this->address();
- //区域下摄像头接口测试
- // $this->camera_list();
- //区域列表接口测试
- // $this->mine_list();
- }
- //区域列表接口测试
- public function mine_list(){
- $result = MineServices::getHaiKangArea(968, CameraEnum::REQUEST_TYPE_LOCAL);
- dd($result);
- }
- //区域下摄像头接口测试
- public function camera_list(){
- $result = CameraServices::getHaiKangCamera(968, '64018112582160000010', CameraEnum::CAMERA_TYPE_ALL);
- dd($result);
- }
- //直播列表
- public function list(){
- // At_0000bd7f06fa796842778d92b50d4d2d
- $url = 'https://openapi.lechange.cn/openapi/liveList';
- //当前的UTC时间戳
- $time= strtotime(date('Y-m-d H:i:s',time()));
- //随机字符串
- $nonce = md5(time());
- //授权信息之appid
- $appId='lc753b03152e3b4f1e';
- //授权信息之appSecret
- $appSecret='cc9b1224acd24571a5daf18e8c7f94';
- //拼接计算“签名原始串”
- $signStr="time:$time,nonce:$nonce,appSecret:$appSecret";
- //计算摘要 sign
- $sign=md5($signStr);
- //业务参数
- $params = [
- 'token'=>'At_0000bd7f06fa796842778d92b50d4d2d',
- 'queryRange'=>"1-99"
- ];
- //组装调用接口的body体内容
- $data = json_encode([
- 'system'=>
- [
- 'ver'=>'1.0',
- 'sign'=>$sign,
- 'appId'=>$appId,
- 'time'=>$time,
- 'nonce'=>$nonce
- ],
- 'params'=>empty($params)? new \stdClass():$params,
- 'id'=>'88'
- ]);
- //http调用
- $ret = $this->curl_post($data, $url);
- $utf8 = iconv('utf-8', 'UTF-8', $ret);
- //调用后返回输出
- // dd(nl2br($utf8));
- $aa = json_decode(nl2br($utf8), true);
- dd($aa['result']['data']);
- }
- //根据序列号获取直播地址和直播状态
- public function address(){
- // At_0000bd7f06fa796842778d92b50d4d2d
- $url = 'https://openapi.lechange.cn/openapi/getLiveStreamInfo';
- //当前的UTC时间戳
- $time= strtotime(date('Y-m-d H:i:s',time()));
- //随机字符串
- $nonce = md5(time());
- //授权信息之appid
- $appId='lc753b03152e3b4f1e';
- //授权信息之appSecret
- $appSecret='cc9b1224acd24571a5daf18e8c7f94';
- //拼接计算“签名原始串”
- $signStr="time:$time,nonce:$nonce,appSecret:$appSecret";
- //计算摘要 sign
- $sign=md5($signStr);
- //业务参数
- $params = [
- 'token'=>'At_0000bd7f06fa796842778d92b50d4d2d',
- 'deviceId'=>'6J0C716PAZ6CF87',
- 'channelId'=>22
- ];
- //组装调用接口的body体内容
- $data = json_encode([
- 'system'=>
- [
- 'ver'=>'1.0',
- 'sign'=>$sign,
- 'appId'=>$appId,
- 'time'=>$time,
- 'nonce'=>$nonce
- ],
- 'params'=>empty($params)? new \stdClass():$params,
- 'id'=>'88'
- ]);
- //http调用
- $ret = $this->curl_post($data, $url);
- $utf8 = iconv('utf-8', 'UTF-8', $ret);
- //调用后返回输出
- dd(nl2br($utf8 ));
- }
- public function token(){
- // At_0000bd7f06fa796842778d92b50d4d2d
- $url = 'https://openapi.lechange.cn:443/openapi/accessToken';
- //当前的UTC时间戳
- $time= strtotime(date('Y-m-d H:i:s',time()));
- //随机字符串
- $nonce = md5(time());
- //授权信息之appid
- $appId='lc753b03152e3b4f1e';
- //授权信息之appSecret
- $appSecret='cc9b1224acd24571a5daf18e8c7f94';
- //拼接计算“签名原始串”
- $signStr="time:$time,nonce:$nonce,appSecret:$appSecret";
- //计算摘要 sign
- $sign=md5($signStr);
- //业务参数
- $params = [];
- //组装调用接口的body体内容
- $data = json_encode([
- 'system'=>
- [
- 'ver'=>'1.0',
- 'sign'=>$sign,
- 'appId'=>$appId,
- 'time'=>$time,
- 'nonce'=>$nonce
- ],
- 'params'=>empty($params)? new \stdClass():$params,
- 'id'=>'88'
- ]);
- //http调用
- $ret = $this->curl_post($data, $url);
- $utf8 = iconv('utf-8', 'UTF-8', $ret);
- //调用后返回输出
- echo 'result:<br>'.nl2br($utf8 ).'<br>';
- }
- function curl_post($data,$url)
- {
- $ch = curl_init();
- $res= curl_setopt ($ch, CURLOPT_URL,$url);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt ($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
- $result = curl_exec ($ch);
- curl_close($ch);
- if ($result == NULL) {
- return 0;
- }
- return $result;
- }
- //新接入摄像头接口测试
- public function new_joggle(){
- $mine_id_list = MineListExt::where('is_hak', 1)->pluck('mine_id')->all();
- // dd($mine_id_list);
- $result = MineServices::getHaiKangArea(4569, CameraEnum::REQUEST_TYPE_LOCAL);//配合修改mineext和haikangcontroller里打印
- dd($result);
- }
- //宁煤洗选重复摄像头
- public function xixuan_repeat(){
- $mine_all = DB::table('mine_list')->where('deleted_at',null)->get();//所有区域
- //宁煤下各矿在离线数量
- $mine_list = DB::table('mine_list')->where('parent_id',968)->where('deleted_at',null)->get();
- $mine_use = [];//宁煤下每个矿所有区域
- foreach($mine_all as $key=>$value){
- if(count(explode('|',$value->degree)) > 1){
- if(explode('|',$value->degree)[0] == 968 && explode('|',$value->degree)[1] == 2429){
- $mine_use[] = $value->id;
- }
- }
- }
- $total = DB::table('camera_list')
- ->select('camera_list.camera_name','camera_list.camera_status','mine_list.title')
- ->leftJoin('mine_list','mine_list.id','=','camera_list.mine_id')
- ->whereIn('camera_list.mine_id',$mine_use)
- ->where('camera_list.deleted_at',null)
- ->where('mine_list.deleted_at',null)
- ->orderBy('mine_list.title')
- ->get();
- // dd($total);
- $aa = [];
- foreach($total as $k=>$v){
- $aa[] = $v->camera_name;
- }
- $unique_arr = array_unique ( $aa );
- // dd($unique_arr);
- $repeat_arr = array_diff_assoc ( $aa, $unique_arr );
- return $repeat_arr;
- }
-
- public function getDcsApiData() {
- $apiUrl = "http://7.250.4.3:4300/v1/common/GetPointRealDataByPageV3";
-
- $client = new Client();
-
- $r = request()->all();
-
- if(isset($r['p'])) {
- $p = $r['p'];
- $k = $r['k'];
- } else {
- $p = $r;
- }
-
-
- $body = [
- 'headers' => [
- 'Authorization' => 'Bearer appkey_100100',
- 'Content-Type'=>'application/json; charset=utf-8',
- // 其他头部信息
- ],
- 'json' =>[
- 'PageNum'=>"-1",
- "PointIds"=>$p
- ]
- ];
- // 发送 HTTP POST 请求
- $response = $client->post($apiUrl, $body);
-
- // 获取 API 响应的 JSON 数据
- $res = json_decode($response->getBody(), true);
-
- if($res['IsSuccessful'] == 0) {
- return $res;
- }
- $data = isset($res['Data'])? $res['Data']: null;
-
- $transformedData['data']=[];
- for ($i = 0; $i < count($data); $i++) {
- $dic = $data[$i];
- $trans['v'][] = $dic['V'];
- $trans['list'][$i] = [
- 'id'=>$dic['ID'],
- 'nm'=>$dic['PointName'],
- 'v'=>$dic['V'],
- ];
- $trans['kv'][$dic['ID']] = $dic['V'];
- }
-
- if (!empty($k) && isset($trans[$k])) {
- return $trans[$k];
- }
-
- return $trans;
-
- }
-
-
- public function getDcsOpcData() {
-
- // $shell = "echo 'success' ";
- // $shellExec = shell_exec($shell);
- // // var_dump($shellExec);
- // if($shellExec){echo 'ok';} else {echo 'error'}
-
- $pids = [
- "ns=12380;s=九八零变电所80Z004照明回路_Ia",
- "ns=12380;s=九八零变电所5105_IA",
- "ns=12380;s=九八零变电所5101_UB",
- # 添加其他节点地址...
- ];
-
- $pyPath = "/home/python_proj/python_custom_script/zaoquan/dcs/";
- $pyFName = "test1.py";
- $pyKeyWord = "/usr/bin/python311";
-
- $pidsJson = json_encode($pids);
- $command = "$pyKeyWord {$pyPath}{$pyFName}". ' ' . escapeshellarg("{$pidsJson}");
- // $output = shell_exec($command);
- // return shell_exec($command);
-
- try {
- // 调用Python脚本
- $output = shell_exec($command);
-
- // 解析Python脚本返回的JSON数据
- $data = json_decode($output, true);
- // $data['a'] = 'aaa';
- // 返回JSON格式的数据给前端
- header('Content-Type: application/json');
- echo json_encode($data);
- } catch (Exception $e) {
- // 返回错误消息给前端
- header('Content-Type: application/json');
- echo json_encode(array("error" => $e->getMessage()));
- }
- }
- }
|