|
@@ -8,11 +8,14 @@
|
|
|
|
|
|
namespace Modules\Camera\Http\Controllers\Api;
|
|
|
|
|
|
+use Illuminate\Http\Request;
|
|
|
use App\Http\Controllers\Api\BaseController;
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Input;
|
|
|
use Modules\Camera\Enum\CameraEnum;
|
|
|
use Modules\Mine\Entities\MineList;
|
|
|
+use Modules\Mine\Enum\MineEnum;
|
|
|
use Modules\Mine\Services\MineServices;
|
|
|
|
|
|
|
|
@@ -226,4 +229,234 @@ class TdwyController extends BaseController
|
|
|
curl_close($ch);
|
|
|
return $data;
|
|
|
}
|
|
|
+
|
|
|
+ //同步大华视频服务器摄像头
|
|
|
+ public function dahuaCamera(Request $request){
|
|
|
+ //大华需要同步的区域
|
|
|
+ $dahua_ext = DB::table('mine_list_ext')
|
|
|
+ ->where('is_hak',MineEnum::IS_HAK_DH)
|
|
|
+ ->where('deleted_at',null)->get();
|
|
|
+ if(count($dahua_ext) > 0){
|
|
|
+ for($i=0;$i<count($dahua_ext);$i++){
|
|
|
+ $ip = $dahua_ext[$i]->ip.':'.$dahua_ext[$i]->port;
|
|
|
+
|
|
|
+ //获取public_key
|
|
|
+ $url = '/evo-apigw/evo-oauth/1.0.0/oauth/public-key';
|
|
|
+ $result = $this->httpRequest($ip.$url);
|
|
|
+ if($result['data']['publicKey']){
|
|
|
+ $public_key = $result['data']['publicKey'];
|
|
|
+ }else{
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取access_token
|
|
|
+ $url2 = '/evo-apigw/evo-oauth/1.0.0/oauth/extend/token';
|
|
|
+ $username_password = explode('|',$dahua_ext[$i]->sOrgId);
|
|
|
+ if(count($username_password) != 2){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $password = $this->rsaEncode($username_password[1],$public_key);
|
|
|
+ $params = [
|
|
|
+ 'grant_type'=>'password',
|
|
|
+ 'username'=>$username_password[0],
|
|
|
+ 'password'=>$password,
|
|
|
+ 'client_id'=>$dahua_ext[$i]->key,
|
|
|
+ 'client_secret'=>$dahua_ext[$i]->secret,
|
|
|
+ 'public_key'=>$public_key
|
|
|
+ ];
|
|
|
+ $result2 = $this->httpRequest($ip.$url2,'post',$params);
|
|
|
+ if($result2['data']['access_token']){
|
|
|
+ $access_token = $result2['data']['access_token'];
|
|
|
+ }else{
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取摄像头列表
|
|
|
+ $url3 = '/evo-apigw/evo-brm/1.2.0/device/channel/subsystem/page';
|
|
|
+ $params2 = [
|
|
|
+ 'pageNum'=>1,
|
|
|
+ 'pageSize'=>1000,
|
|
|
+ 'sortType'=>'ASC',
|
|
|
+ 'sort'=>'channelSn',
|
|
|
+ ];
|
|
|
+ $result3 = $this->httpRequest($ip.$url3,'post',$params2,$access_token);
|
|
|
+
|
|
|
+ DB::table('camera_list')->where('mine_id',$dahua_ext[$i]->mine_id)->delete();
|
|
|
+ if($result3['data']['pageData']){
|
|
|
+ $camera_list = $result3['data']['pageData'];
|
|
|
+ if(count($camera_list) > 0){
|
|
|
+ for($j=0;$j<count($camera_list);$j++){
|
|
|
+ $param['mine_id'] = $dahua_ext[$i]->mine_id;
|
|
|
+ $param['revert_id'] = 'NullId';
|
|
|
+ $param['sort'] = 1;
|
|
|
+ $param['camera_name'] = $camera_list[$j]['channelName'];
|
|
|
+ $param['camera_source'] = 2;
|
|
|
+ $param['index_code'] = $camera_list[$j]['channelCode'];
|
|
|
+ $param['video_recorder'] = 2;
|
|
|
+ $param['created_at'] = date('Y-m-d H:i:s');
|
|
|
+ $param['updated_at'] = date('Y-m-d H:i:s');
|
|
|
+ DB::table('camera_list')->insert($param);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //大华rtsp
|
|
|
+ public function dahuaRtsp($camera_id,$parent_id){
|
|
|
+ $dahua_ext = DB::table('mine_list_ext')
|
|
|
+ ->where('mine_id',$parent_id)
|
|
|
+ ->where('deleted_at',null)->get();
|
|
|
+ if(count($dahua_ext) > 0){
|
|
|
+ $ip = $dahua_ext[0]->ip.':'.$dahua_ext[0]->port;
|
|
|
+
|
|
|
+ //获取public_key
|
|
|
+ $url = '/evo-apigw/evo-oauth/1.0.0/oauth/public-key';
|
|
|
+ $result = $this->httpRequest($ip.$url);
|
|
|
+ if($result['data']['publicKey']){
|
|
|
+ $public_key = $result['data']['publicKey'];
|
|
|
+ }else{
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取access_token
|
|
|
+ $url2 = '/evo-apigw/evo-oauth/1.0.0/oauth/extend/token';
|
|
|
+ $username_password = explode('|',$dahua_ext[0]->sOrgId);
|
|
|
+ if(count($username_password) != 2){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $password = $this->rsaEncode($username_password[1],$public_key);
|
|
|
+ $params = [
|
|
|
+ 'grant_type'=>'password',
|
|
|
+ 'username'=>$username_password[0],
|
|
|
+ 'password'=>$password,
|
|
|
+ 'client_id'=>$dahua_ext[0]->key,
|
|
|
+ 'client_secret'=>$dahua_ext[0]->secret,
|
|
|
+ 'public_key'=>$public_key
|
|
|
+ ];
|
|
|
+ $result2 = $this->httpRequest($ip.$url2,'post',$params);
|
|
|
+ if($result2['data']['access_token']){
|
|
|
+ $access_token = $result2['data']['access_token'];
|
|
|
+ }else{
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $camera = DB::table('camera_list')->where('id',$camera_id)->get();
|
|
|
+
|
|
|
+ $url4 = '/evo-apigw/admin/API/MTS/Video/StartVideo';
|
|
|
+ $params3['data'] = [
|
|
|
+ 'channelId'=>$camera[0]->index_code,
|
|
|
+ 'dataType'=>'1',
|
|
|
+ 'streamType'=>'1'
|
|
|
+ ];
|
|
|
+ $result4 = $this->httpRequest($ip.$url4,'post',$params3,$access_token);
|
|
|
+ if($result4['data']['url'] && $result4['data']['token']){
|
|
|
+ $rtsp = explode('|',$result4['data']['url']);
|
|
|
+ if($rtsp[1]){
|
|
|
+ $result['data'] = [
|
|
|
+ 'camera_id' => $camera_id,
|
|
|
+ 'url' => $rtsp[1].'?token='.$result4['data']['token']
|
|
|
+ ];
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //大华摄像头
|
|
|
+ public function geturl(Request $request){
|
|
|
+ $ip = 'https://222.75.25.198:8443';
|
|
|
+ $url = '/evo-apigw/evo-oauth/1.0.0/oauth/public-key';
|
|
|
+ $result = $this->httpRequest($ip.$url);
|
|
|
+ $public_key = $result['data']['publicKey'];
|
|
|
+
|
|
|
+ $url2 = '/evo-apigw/evo-oauth/1.0.0/oauth/extend/token';
|
|
|
+ $password = $this->rsaEncode("xxzx!#%246",$public_key);
|
|
|
+ $params = [
|
|
|
+ 'grant_type'=>'password',
|
|
|
+ 'username'=>'system',
|
|
|
+ 'password'=>$password,
|
|
|
+ 'client_id'=>'dahua',
|
|
|
+ 'client_secret'=>'45815ebb-300c-416f-8adf-da07a07fab8a',
|
|
|
+ 'public_key'=>$public_key
|
|
|
+ ];
|
|
|
+ $result2 = $this->httpRequest($ip.$url2,'post',$params);
|
|
|
+ $access_token = $result2['data']['access_token'];
|
|
|
+
|
|
|
+ $url3 = '/evo-apigw/evo-brm/1.2.0/device/channel/subsystem/page';
|
|
|
+ $params2 = [
|
|
|
+ 'pageNum'=>1,
|
|
|
+ 'pageSize'=>1000,
|
|
|
+ 'sortType'=>'ASC',
|
|
|
+ 'sort'=>'channelSn',
|
|
|
+// 'isOnline'=>0,
|
|
|
+// 'stat'=>1
|
|
|
+ ];
|
|
|
+// dd($params2);
|
|
|
+ $result3 = $this->httpRequest($ip.$url3,'post',$params2,$access_token);
|
|
|
+// dd($result3);
|
|
|
+// 1000006$1$0$0 1000012$1$0$0
|
|
|
+
|
|
|
+ $url4 = '/evo-apigw/admin/API/MTS/Video/StartVideo';
|
|
|
+ $params3['data'] = [
|
|
|
+ 'channelId'=>'1000006$1$0$0',
|
|
|
+ 'dataType'=>'1',
|
|
|
+ 'streamType'=>'1'
|
|
|
+ ];
|
|
|
+// dd($params3);
|
|
|
+ $result4 = $this->httpRequest($ip.$url4,'post',$params3,$access_token);
|
|
|
+ $result4['access_token'] = $access_token;
|
|
|
+ dd($result4);
|
|
|
+ }
|
|
|
+
|
|
|
+ //接口第三方调用
|
|
|
+ public function httpRequest($url, $format = 'get', $data = null, $token = null){
|
|
|
+ //设置头信息
|
|
|
+ $headerArray =array("Content-type:application/json;","Accept:application/json");
|
|
|
+
|
|
|
+ if ($token) {
|
|
|
+ $headerArray[] = "Authorization:bearer " . $token;
|
|
|
+ }
|
|
|
+
|
|
|
+ $curl=curl_init();
|
|
|
+ curl_setopt($curl, CURLOPT_URL, $url);
|
|
|
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
|
|
+ curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
|
|
|
+ if ($format == 'post') {
|
|
|
+ //post传值设置post传参
|
|
|
+ curl_setopt($curl, CURLOPT_POST, 1);
|
|
|
+ if ($data) {
|
|
|
+ $data = json_encode($data);
|
|
|
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
|
+ curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
|
|
|
+ $data=json_decode(curl_exec($curl), true);
|
|
|
+ curl_close($curl);
|
|
|
+ //返回接口返回数据
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function rsaEncode($password,$rsa_public_key)
|
|
|
+ {
|
|
|
+ // 要执行的代码
|
|
|
+ $rsa_public = "-----BEGIN PUBLIC KEY-----\n";
|
|
|
+ $rsa_public = $rsa_public.$rsa_public_key;
|
|
|
+ $rsa_public = $rsa_public."\n-----END PUBLIC KEY-----";
|
|
|
+ $key = openssl_pkey_get_public($rsa_public);
|
|
|
+ if (!$key) {
|
|
|
+ echo "公钥不可用\n";
|
|
|
+ echo $rsa_public;
|
|
|
+ }
|
|
|
+ //openssl_public_encrypt 第一个参数只能是string
|
|
|
+ //openssl_public_encrypt 第二个参数是处理后的数据
|
|
|
+ //openssl_public_encrypt 第三个参数是openssl_pkey_get_public返回的资源类型
|
|
|
+ $return_en = openssl_public_encrypt($password, $crypted, $key);
|
|
|
+ if (!$return_en) {
|
|
|
+ echo "加密失败,请检查RSA秘钥";
|
|
|
+ }
|
|
|
+ return base64_encode($crypted);
|
|
|
+ }
|
|
|
}
|