API接口-初版
This commit is contained in:
@@ -10,6 +10,7 @@ use app\common\facade\Token;
|
||||
use app\common\model\UserScoreLog;
|
||||
use app\common\model\UserMoneyLog;
|
||||
use app\common\controller\Frontend;
|
||||
use app\common\facade\Token as TokenFacade;
|
||||
use support\validation\Validator;
|
||||
use support\validation\ValidationException;
|
||||
use Webman\Http\Request;
|
||||
@@ -20,6 +21,51 @@ class Account extends Frontend
|
||||
protected array $noNeedLogin = ['retrievePassword'];
|
||||
protected array $noNeedPermission = ['verification', 'changeBind'];
|
||||
|
||||
public function userProfile(Request $request): Response
|
||||
{
|
||||
$response = $this->initializeFrontend($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$authToken = trim((string) $request->header('auth-token', ''));
|
||||
if ($authToken === '') {
|
||||
return $this->mobileResult(1101, 'Missing auth-token');
|
||||
}
|
||||
$tokenData = TokenFacade::get($authToken);
|
||||
$type = $tokenData['type'] ?? '';
|
||||
$expireTime = $tokenData['expire_time'] ?? 0;
|
||||
if ($type !== 'auth-token' || !is_numeric($expireTime) || $expireTime < time()) {
|
||||
return $this->mobileResult(1101, 'auth-token is invalid or expired');
|
||||
}
|
||||
|
||||
$user = $this->auth->getUser();
|
||||
$payload = [
|
||||
'code' => 1,
|
||||
'message' => __('ok'),
|
||||
'data' => [
|
||||
'id' => $user->id,
|
||||
'username' => $user->username,
|
||||
'head_image' => $user->avatar ?? '',
|
||||
'coin' => $user->coin,
|
||||
'current_streak' => $user->current_streak ?? 0,
|
||||
'channel_id' => $user->channel_id,
|
||||
'risk_flags' => $user->risk_flags ?? 0,
|
||||
],
|
||||
];
|
||||
return \response(json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), 200, ['Content-Type' => 'application/json']);
|
||||
}
|
||||
|
||||
private function mobileResult(int $code, string $message, array $data = []): Response
|
||||
{
|
||||
$payload = [
|
||||
'code' => $code,
|
||||
'message' => __($message),
|
||||
'data' => $data,
|
||||
];
|
||||
return \response(json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), 200, ['Content-Type' => 'application/json']);
|
||||
}
|
||||
|
||||
public function overview(Request $request): Response
|
||||
{
|
||||
$response = $this->initializeFrontend($request);
|
||||
|
||||
Reference in New Issue
Block a user