78 lines
2.2 KiB
PHP
78 lines
2.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace app\smt\controller\v1;
|
|
|
|
use app\smt\common\Response;
|
|
use app\smt\controller\BaseController;
|
|
use app\smt\service\AuthService;
|
|
use think\App;
|
|
|
|
class Auth extends BaseController
|
|
{
|
|
protected $authService;
|
|
|
|
public function __construct(App $app)
|
|
{
|
|
parent::__construct($app);
|
|
$this->authService = new AuthService();
|
|
}
|
|
|
|
public function login()
|
|
{
|
|
try {
|
|
return Response::success($this->authService->loginWithCode($this->request->post()), '登录成功');
|
|
} catch (\Throwable $e) {
|
|
return Response::error($e->getMessage(), $e->getCode() ?: 500);
|
|
}
|
|
}
|
|
|
|
public function devLogin()
|
|
{
|
|
try {
|
|
return Response::success(
|
|
$this->authService->devLogin((int) ($this->request->post('mini_program_id', 2))),
|
|
'登录成功'
|
|
);
|
|
} catch (\Throwable $e) {
|
|
return Response::error($e->getMessage(), $e->getCode() ?: 500);
|
|
}
|
|
}
|
|
|
|
public function me()
|
|
{
|
|
try {
|
|
return Response::success($this->authService->getUserInfo($this->getCurrentSmtUserId()));
|
|
} catch (\Throwable $e) {
|
|
return Response::error($e->getMessage(), $e->getCode() ?: 500);
|
|
}
|
|
}
|
|
|
|
public function profile()
|
|
{
|
|
try {
|
|
return Response::success($this->authService->updateProfile($this->getCurrentSmtUserId(), $this->request->post()), '更新成功');
|
|
} catch (\Throwable $e) {
|
|
return Response::error($e->getMessage(), $e->getCode() ?: 500);
|
|
}
|
|
}
|
|
|
|
public function miniProgramTestCode()
|
|
{
|
|
try {
|
|
$image = $this->authService->getMiniProgramTestCode(
|
|
$this->getCurrentSmtUserId(),
|
|
(string) $this->request->get('path', ''),
|
|
(int) $this->request->get('width', 280)
|
|
);
|
|
|
|
return response($image)
|
|
->code(200)
|
|
->contentType('image/png')
|
|
->header(['Cache-Control' => 'no-store']);
|
|
} catch (\Throwable $e) {
|
|
return Response::error('获取小程序码失败', $e->getCode() ?: 500);
|
|
}
|
|
}
|
|
}
|