105 lines
2.7 KiB
PHP
105 lines
2.7 KiB
PHP
<?php
|
||
|
||
namespace app\common\service;
|
||
|
||
use app\common\logic\AuthLogic;
|
||
use app\common\model\User;
|
||
use app\common\utils\Feishu;
|
||
use support\Db;
|
||
|
||
class AuthService
|
||
{
|
||
|
||
/**
|
||
* 飞书授权
|
||
*/
|
||
public function feishuAuthorize(string $corpAbbr, string $systemCcode, $mobile)
|
||
{
|
||
$logic = new AuthLogic();
|
||
$certificate = $logic->feishuAppInfo($corpAbbr, $systemCcode);
|
||
$feishu = new Feishu($certificate['app_id'], $certificate['app_secret'], $certificate['abbr']);
|
||
return ['auth_url' => $feishu->authorize($certificate, $mobile)];
|
||
}
|
||
|
||
/**
|
||
* 登录,支持多类型
|
||
*/
|
||
public function login(array $data): array
|
||
{
|
||
$loginType = $data['login_type'] ?? 'upwd';
|
||
$logic = new AuthLogic();
|
||
|
||
return match ($loginType) {
|
||
'feishu' => $logic->feishuLogin($data),
|
||
// 'qrcode' => $logic->qrCodeLogin($data),
|
||
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);
|
||
}
|
||
|
||
/**
|
||
* 获取jsapi配置
|
||
* @param string $corpAbbr
|
||
* @param string $systemCcode
|
||
* @param string $url 当前页面完整 URL(不包含 # 后面的内容)
|
||
* @return array
|
||
*/
|
||
public function getJsApiConfig(string $corpAbbr, string $systemCcode, string $url)
|
||
{
|
||
$logic = new AuthLogic();
|
||
$certificate = $logic->feishuAppInfo($corpAbbr, $systemCcode);
|
||
$feishu = new Feishu($certificate['app_id'], $certificate['app_secret'], $certificate['abbr']);
|
||
$jsApi = $feishu->getJsApiConfig($url);
|
||
return $jsApi;
|
||
}
|
||
} |