task: encode RSA data sync to server

CR: sonhh (fake)
This commit is contained in:
dongpd 2021-09-09 17:08:56 +07:00
parent a27bf65303
commit 66357b25d5
2 changed files with 47 additions and 20 deletions

View File

@ -95,18 +95,21 @@ class ApiController extends Controller {
$token = \app\models\SyncUrl::findOne(['key_config' => 'token']);
if ($token)
$tk = $token->data;
$res = json_decode(file_get_contents($ip . "/api/oem/face_recognition?token=" . $tk, false, stream_context_create([
$data = [];
$data[] = strval($id_camera); //camera_id
$data[] = date("Y-m-d H:i:s", $time); //frametime
$data[] = $staffInfo ? strval($staffInfo->code) : "0"; //idCard
$data[] = $staffInfo ? $staffInfo->staff_id : ""; //idObject
$data[] = "123"; //person_id
$data[] = "+7"; //timezone
$text = implode("|", $data);
$res = json_decode(file_get_contents($ip . "/api/box/face_recognition_auth_v2?token=" . $tk, false, stream_context_create([
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",
'content' => json_encode([
'image' => base64_encode(file_get_contents("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $fileName)),
'camera_id' => strval($id_camera),
'frametime' => date("Y-m-d H:i:s", $time),
'idCard' => $staffInfo ? strval($staffInfo->code) : "0",
'idObject' => $staffInfo ? $staffInfo->staff_id : "",
"person_id" => "123",
"timezone" => "+7"
'data' => common::rsaEncode($text)
])
]
])), true);
@ -348,18 +351,21 @@ class ApiController extends Controller {
$tk = $token->data;
foreach ($ls as $key => $value) {
$staffInfo = ListManagement::findOne($value->staff_id);
$res = json_decode(file_get_contents($ip . "/api/oem/face_recognition?token=" . $tk, false, stream_context_create([
$data = [];
$data[] = strval($id_camera); //camera_id
$data[] = date("Y-m-d H:i:s", $value->time); //frametime
$data[] = $staffInfo ? strval($staffInfo->code) : "0"; //idCard
$data[] = $staffInfo ? $staffInfo->staff_id : ""; //idObject
$data[] = "123"; //person_id
$data[] = "+7"; //timezone
$text = implode("|", $data);
$res = json_decode(file_get_contents($ip . "/api/box/face_recognition_auth_v2?token=" . $tk, false, stream_context_create([
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",
'content' => json_encode([
'image' => base64_encode(file_get_contents("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $value->image)),
'camera_id' => strval($id_camera),
'frametime' => date("Y-m-d H:i:s", $value->time),
'idCard' => $staffInfo ? strval($staffInfo->code) : "0",
'idObject' => $staffInfo ? $staffInfo->staff_id : "",
"person_id" => "123",
"timezone" => "+7"
'data' => common::rsaEncode($text)
])
]
])), true);
@ -474,12 +480,26 @@ class ApiController extends Controller {
}
public function actionTest() {
// $updating = \app\models\SyncUrl::findOne(['key_config' => 'token']);
$updating = \app\models\SyncUrl::find()->all();
foreach ($updating as $key => $value) {
echo $value->key_config . " " . $value->data . "<br>";
}
exit();
// $key = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDCXB8c44cboYsGG6IzISqxf8W7q3AN0mGmekDYpBWpz9udif+jwK6h7NuOZvFDeB/32TVrtvaGDmExCeBerpcoOvGh4eUXyke2lSLzrg7pc/wD0KproEGoAAFDB0Pr5bZhg6ELp3Sk++0MPyxH6u1pgtHDxEnMwXV8cxw/rSCM+wIDAQAB';
// $rsa = new \phpseclib3\Crypt\RSA;
// $rsa->loadKey($key);
// $rsa->setPublicKey($key);
//
// echo $rsa->getPublicKey();
// exit();
$test = "10|2021-07-27 19:16:25|211155|1|2021-07-27 19:16:25";
$encode = common::rsaEncode($test);
$res = json_decode(file_get_contents("http://192.168.0.9:6004/api/box/face_recognition_auth_v2", false, stream_context_create([
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",
'content' => json_encode([
'image' => 'abc',
'data' => $encode
])
]
])), true);
return var_dump($res);
}
public function actionReGenFeature() {

View File

@ -231,4 +231,11 @@ class common extends \yii\db\ActiveRecord {
];
}
public static function rsaEncode($text) {
$publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDCXB8c44cboYsGG6IzISqxf8W7q3AN0mGmekDYpBWpz9udif+jwK6h7NuOZvFDeB/32TVrtvaGDmExCeBerpcoOvGh4eUXyke2lSLzrg7pc/wD0KproEGoAAFDB0Pr5bZhg6ELp3Sk++0MPyxH6u1pgtHDxEnMwXV8cxw/rSCM+wIDAQAB";
$publicKey = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($publicKey, 64, "\n", true) . "\n-----END PUBLIC KEY-----";
openssl_public_encrypt($text, $encrypted, $publicKey, OPENSSL_PKCS1_PADDING);
return base64_encode($encrypted);
}
}