33 lines
726 B
PHP
33 lines
726 B
PHP
<?php
|
|
header('Content-type: application/json');
|
|
|
|
use app\models\UserPublic;
|
|
use app\services\JWT;
|
|
|
|
$post = \Yii::$app->request->getRawBody();
|
|
|
|
|
|
$postDecode = json_decode($post);
|
|
|
|
if(!empty($postDecode->uid)) {
|
|
|
|
function loop($postDecode)
|
|
{
|
|
|
|
if (!$postDecode->uid) return;
|
|
$server_id = md5(time() . uniqid());
|
|
$uid = $postDecode->uid;
|
|
$token = JWT::encode(['server_id' => $server_id, 'uid' => $uid], JWT::SECRET_KEY);
|
|
$user = UserPublic::find()->where(['device_id' => $token])->exists();
|
|
if (!$user) {
|
|
echo json_encode(['device_id' => $token]);
|
|
exit;
|
|
} else {
|
|
loop($postDecode);
|
|
}
|
|
}
|
|
|
|
loop($postDecode);
|
|
}
|
|
exit;
|