电信监控设备
parent
5e19467e8d
commit
a0b2bf0ce6
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class MoJingException extends RuntimeException
|
||||
{
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ use App\Helpers\Paginator;
|
|||
use App\Http\Requestes\DeviceRequest;
|
||||
use App\Http\Resources\DeviceResource;
|
||||
use App\Http\Resources\WormPhotoResource;
|
||||
use App\Iot\MoJing\HttpClient as MoJingHttpClient;
|
||||
use App\Iot\Qly\HttpClient as QlyHttpClient;
|
||||
use App\Models\AgriculturalBase;
|
||||
use App\Models\Device;
|
||||
|
|
@ -747,7 +748,7 @@ class DeviceController extends Controller
|
|||
];
|
||||
|
||||
// 中国移动千里眼
|
||||
case 'device-supplier-ydqly':
|
||||
case 'device-supplier-yidong':
|
||||
$client = new QlyHttpClient(
|
||||
config('services.ydqly.appid'),
|
||||
config('services.ydqly.secret'),
|
||||
|
|
@ -763,7 +764,25 @@ class DeviceController extends Controller
|
|||
return [
|
||||
'type' => 'iframe',
|
||||
'address' => (string) data_get($result, 'data.url'),
|
||||
// 'expires' => (int) data_get($result, 'data.expiresIn'),
|
||||
];
|
||||
|
||||
// 中国电信魔镜
|
||||
case 'device-supplier-dianxin':
|
||||
$client = new MoJingHttpClient(
|
||||
config('services.dxmj.app_id'),
|
||||
config('services.dxmj.app_secret'),
|
||||
);
|
||||
$result = $client->get(
|
||||
"/api/v3/channel/RealTimeVideo/{$device->sn}",
|
||||
[
|
||||
'transType' => 4,
|
||||
'natType' => 1,
|
||||
],
|
||||
);
|
||||
|
||||
return [
|
||||
'type' => 'flv',
|
||||
'address' => (string) data_get($result, 'data.playUrl'),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace App\Iot\MoJing;
|
||||
|
||||
use App\Exceptions\MoJingException;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
/**
|
||||
* 电信魔镜
|
||||
*/
|
||||
class HttpClient
|
||||
{
|
||||
const ENDPOINT_URL = 'https://mojing.sctel.com.cn';
|
||||
|
||||
public function __construct(
|
||||
protected readonly string $appId,
|
||||
protected readonly string $appSecret,
|
||||
) {
|
||||
}
|
||||
|
||||
public function get(string $url, array $query = []): array
|
||||
{
|
||||
return $this->request('GET', $url, [
|
||||
'query' => $query,
|
||||
]);
|
||||
}
|
||||
|
||||
protected function request(string $method, string $url, array $options = []): array
|
||||
{
|
||||
$timestamp = now()->getTimestampMs();
|
||||
|
||||
$sign = md5($this->appId.$this->appSecret.$timestamp);
|
||||
|
||||
/** @var \Illuminate\Http\Client\Response */
|
||||
$response = Http::baseUrl(static::ENDPOINT_URL)->withHeaders([
|
||||
'Authorization' => base64_encode(
|
||||
json_encode([
|
||||
'appId' => $this->appId,
|
||||
'time' => $timestamp,
|
||||
'sign' => $sign,
|
||||
])
|
||||
),
|
||||
])->send($method, $url, $options);
|
||||
|
||||
$result = $response->throw()->json();
|
||||
|
||||
$code = data_get($result, 'code', '-1');
|
||||
if ($code === 200) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
throw new MoJingException(
|
||||
data_get($result, 'message', '请求失败').', 错误码: '.$code,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -43,4 +43,9 @@ return [
|
|||
'rsa' => env('YDQLY_RSA'),
|
||||
],
|
||||
|
||||
// 中国电信魔镜
|
||||
'dxmj' => [
|
||||
'app_id' => env('DXMJ_APP_ID'),
|
||||
'app_secret' => env('DXMJ_APP_SECRET'),
|
||||
],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -53,7 +53,8 @@ class KeywordsTableSeeder extends Seeder
|
|||
['key' => 'device-supplier-linkos', 'name' => '慧联无限', 'value' => ''],
|
||||
['key' => 'device-supplier-biang', 'name' => '比昂', 'value' => ''],
|
||||
['key' => 'device-supplier-yunfei', 'name' => '云飞', 'value' => ''],
|
||||
['key' => 'device-supplier-ydqly', 'name' => '移动千里眼', 'value' => ''],
|
||||
['key' => 'device-supplier-yidong', 'name' => '移动', 'value' => ''],
|
||||
['key' => 'device-supplier-dianxing', 'name' => '电信', 'value' => ''],
|
||||
['key' => 'device-supplier-other', 'name' => '其它', 'value' => ''],
|
||||
],
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in New Issue