Feature: auto get server_api & device_id from engine.json
CR: sonhh (fake)
This commit is contained in:
parent
6c4190372e
commit
b207d54462
|
@ -409,6 +409,34 @@ class ConfigController extends Controller {
|
|||
|
||||
public function actionCauHinhThietBi() {
|
||||
$this->view->title = Yii::t("app", "CAU_HINH_THIET_BI");
|
||||
|
||||
$tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create([
|
||||
'http' => [
|
||||
'header' => "Content-Type: application/json",
|
||||
'method' => "POST"
|
||||
]
|
||||
])), true);
|
||||
if (!$tempConfig['status'])
|
||||
return $this->redirect(['/config']);
|
||||
|
||||
$engineConfig = json_decode($tempConfig['data'], true);
|
||||
|
||||
$server_api = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
|
||||
if (!$server_api) {
|
||||
$model = new \app\models\SyncUrl();
|
||||
$model->create([
|
||||
'key_config' => 'server_api',
|
||||
'data' => $engineConfig['data']['engines'][0]['url']
|
||||
]);
|
||||
}
|
||||
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
|
||||
if (!$device_id) {
|
||||
$model = new \app\models\SyncUrl();
|
||||
$model->create([
|
||||
'key_config' => 'device_id',
|
||||
'data' => $engineConfig['data']['engines'][0]['id']
|
||||
]);
|
||||
}
|
||||
return $this->render('device', [
|
||||
"server_api" => \app\models\SyncUrl::findOne(['key_config' => 'server_api']),
|
||||
"device_id" => \app\models\SyncUrl::findOne(['key_config' => 'device_id'])
|
||||
|
|
Loading…
Reference in New Issue
Block a user