update sync data to serrver

This commit is contained in:
2020-09-25 12:34:10 +07:00
parent db801e7d96
commit 1196ad712b
2 changed files with 39 additions and 9 deletions

View File

@@ -10,6 +10,8 @@ namespace app\commands;
use yii\console\Controller;
use yii\console\ExitCode;
use yii\log\Logger;
use Yii;
/**
* This command echoes the first argument that you have entered.
@@ -32,17 +34,37 @@ class SyncController extends Controller {
if ($sync) {
$logs = \app\models\WaitingReq::find()->all();
foreach ($logs as $key => $value) {
// $start = round(microtime(true) * 1000);
$contentJSON = json_decode($value->content);
$imgPath = $contentJSON->image;
$imgBase64 = base64_encode(file_get_contents($imgPath));
$contentJSON->image = $imgBase64;
$newValue = json_encode($contentJSON);
$options = [
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",
'content' => $value->content
'content' => $newValue
]
];
$res = json_decode(file_get_contents($sync->data, false, stream_context_create($options)), true);
$modelRes = new \app\models\ResponseReq();
$modelRes->create(json_encode($res));
$value->delete();
if ($res['status'] == 1000) {
$modelRes = new \app\models\ResponseReq();
$modelRes->create(json_encode($res));
$value->delete();
// Delete image
unlink($imgPath);
}
// $end = round(microtime(true) * 1000);
// $timeDuration = $end - $start;
// Yii::info("Time:" . $timeDuration . " - " . $res, "cloud-response");
// var_dump($res);
// var_dump($timeDuration);
}
}
}