Files
fdesk/app/common/service/AuthService.php
T

89 lines
2.1 KiB
PHP
Raw Normal View History

2025-07-01 19:39:13 +08:00
<?php
namespace app\common\service;
use app\common\logic\AuthLogic;
use app\common\model\User;
2025-07-07 18:34:21 +08:00
use app\common\utils\Feishu;
2025-07-01 19:39:13 +08:00
use support\Db;
class AuthService
{
2025-07-07 18:34:21 +08:00
/**
* 飞书授权
*/
2026-01-04 16:27:20 +08:00
public function feishuAuthorize(string $corpAbbr, string $systemCcode, $mobile)
2025-07-07 18:34:21 +08:00
{
2025-07-09 17:58:30 +08:00
$logic = new AuthLogic();
$certificate = $logic->feishuAppInfo($corpAbbr, $systemCcode);
$feishu = new Feishu($certificate['app_id'], $certificate['app_secret'], $certificate['abbr']);
2026-01-04 16:27:20 +08:00
return ['auth_url' => $feishu->authorize($certificate, $mobile)];
2025-07-07 18:34:21 +08:00
}
2025-07-01 19:39:13 +08:00
/**
* 登录,支持多类型
*/
public function login(array $data): array
{
$loginType = $data['login_type'] ?? 'upwd';
$logic = new AuthLogic();
return match ($loginType) {
'feishu' => $logic->feishuLogin($data),
2025-07-25 18:10:11 +08:00
// 'qrcode' => $logic->qrCodeLogin($data),
2025-07-01 19:39:13 +08:00
default => $logic->uPwdLogin($data),
};
}
/**
* 用户注册
*/
public function register(array $data)
{
$logic = new AuthLogic();
try {
Db::beginTransaction();
$result = $logic->register($data);
Db::commit();
return $result;
} catch (\Throwable $e) {
Db::rollback();
throw $e;
}
}
/**
* 校验token
*/
public function verifyToken(string $token, string $systemCode): array
{
return (new AuthLogic())->verifyToken($token, $systemCode);
}
/**
* 刷新token
* @param string $refreshToken
* @param string|null $systemCode
*/
public function refreshToken(string $refreshToken, string $systemCode): array
{
return (new AuthLogic())->refreshToken($refreshToken, $systemCode);
}
/**
* 登出(失效token)
*/
public function logout(?string $token, string $systemCode): void
{
(new AuthLogic())->logout($token, $systemCode);
}
/**
* 强制拉黑token
*/
public function blockToken(string $token, string $systemCode): void
{
(new AuthLogic())->blockToken($token, $systemCode);
}
}