fix : user site
This commit is contained in:
@@ -7,6 +7,7 @@ namespace App\Controller\Api;
|
||||
use App\Controller\AbstractController;
|
||||
use App\Middleware\Api\JwtAuthMiddleware;
|
||||
use App\Service\Api\IndexService;
|
||||
use App\Service\Api\System\AliStsService;
|
||||
use App\Service\Api\System\CityListService;
|
||||
use App\Service\Api\System\MiniWxConfigService;
|
||||
use App\Service\Api\System\SiteListService;
|
||||
@@ -56,4 +57,11 @@ class SystemController extends AbstractController
|
||||
{
|
||||
return (new IndexService)->handle();
|
||||
}
|
||||
|
||||
#[RequestMapping(path: "sts/accredit", methods: "GET")]
|
||||
#[Middleware(JwtAuthMiddleware::class)]
|
||||
public function aliSts()
|
||||
{
|
||||
return (new AliStsService)->handle();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,9 @@ use App\Service\Api\User\InviteListService;
|
||||
use App\Service\Api\User\MyPageService;
|
||||
use App\Service\Api\User\SiteService;
|
||||
use App\Service\Api\User\UnBindPhoneService;
|
||||
use App\Service\Api\User\UpdateProfileService;
|
||||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\Middleware;
|
||||
use Hyperf\HttpServer\Annotation\Middlewares;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
use Hyperf\Validation\Annotation\Scene;
|
||||
@@ -137,8 +139,15 @@ class UserController extends AbstractController
|
||||
return (new MyPageService)->handle();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: 'update_profile',methods: 'POST')]
|
||||
#[Scene(scene: 'update_profile')]
|
||||
public function updateProfile()
|
||||
{
|
||||
|
||||
return (new UpdateProfileService)->handle();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
114
app/Service/Api/System/AliStsService.php
Normal file
114
app/Service/Api/System/AliStsService.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Api\System;
|
||||
|
||||
use App\Exception\ErrException;
|
||||
use App\Extend\DateUtil;
|
||||
use App\Service\Api\BaseService;
|
||||
use App\Service\ServiceTrait\Common\AliStsTrait;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use function Hyperf\Config\config;
|
||||
|
||||
class AliStsService extends BaseService
|
||||
{
|
||||
use AliStsTrait;
|
||||
|
||||
/**
|
||||
* 过期时间 15分钟
|
||||
* @var int
|
||||
*/
|
||||
private int $seconds = DateUtil::MINUTE * 15;
|
||||
|
||||
/**
|
||||
* bucket
|
||||
* @var string
|
||||
*/
|
||||
private string $bucket;
|
||||
|
||||
/**
|
||||
* 角色
|
||||
* @var string
|
||||
*/
|
||||
private string $roleArn;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->bucket = config('ali.bucket');
|
||||
$this->roleArn = config('ali.role_arn'); //acs:ram::1987853712163999:role/video-access
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
$payload = [
|
||||
'durationSeconds' => $this->seconds,
|
||||
'roleArn' => $this->roleArn,
|
||||
'roleSessionName' => 'adminUpload',
|
||||
'policy' => [
|
||||
'Version' => '1',
|
||||
'Statement' => [
|
||||
[
|
||||
'Effect' => 'Allow',
|
||||
'Action' => [
|
||||
'oss:*'
|
||||
],
|
||||
'Resource' => [
|
||||
sprintf('acs:oss:*:*:%s', $this->bucket),
|
||||
sprintf('acs:oss:*:*:%s/*', $this->bucket),
|
||||
]
|
||||
],
|
||||
[
|
||||
'Effect' => 'Deny',
|
||||
'Action' => [
|
||||
'oss:DeleteBucket'
|
||||
],
|
||||
'Resource' => [
|
||||
sprintf('acs:oss:*:*:%s', $this->bucket),
|
||||
]
|
||||
],
|
||||
[
|
||||
'Effect' => 'Allow',
|
||||
'Action' => [
|
||||
'oss:DeleteObject'
|
||||
],
|
||||
'Resource' => [
|
||||
sprintf('acs:oss:*:*:%s/*', $this->bucket),
|
||||
]
|
||||
],
|
||||
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$res = $this->getAliStsControls($payload);
|
||||
$this->log->info(__CLASS__.':'.__FUNCTION__.':授权oss信息:'.json_encode($res));
|
||||
|
||||
$aliResponse = $res->body->credentials;
|
||||
if (empty($aliResponse)) throw new ErrException('授权失败');
|
||||
|
||||
return $this->return->success('success',[
|
||||
'access_key_id' => $aliResponse->accessKeyId,
|
||||
'access_key_secret' => $aliResponse->accessKeySecret,
|
||||
'expiration' => date('Y-m-d H:i:s',strtotime($aliResponse->expiration)),//UTC时间转为北京时间
|
||||
'security_token' => $aliResponse->securityToken,
|
||||
'callback_url' => config('ali.callback_url'),
|
||||
'bucket' => $this->bucket,
|
||||
'region' => config('ali.region'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
66
app/Service/Api/User/UpdateProfileService.php
Normal file
66
app/Service/Api/User/UpdateProfileService.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Api\User;
|
||||
|
||||
use App\Exception\ErrException;
|
||||
use App\Service\Api\BaseService;
|
||||
use App\Service\ServiceTrait\Api\GetUserInfoTrait;
|
||||
use App\Service\ServiceTrait\Common\OssTrait;
|
||||
|
||||
class UpdateProfileService extends BaseService
|
||||
{
|
||||
use GetUserInfoTrait;
|
||||
use OssTrait;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected mixed $userInfo;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
$this->userInfo = $this->getUserInfo($this->userId);
|
||||
if (empty($this->userInfo)) throw new ErrException('用户异常');
|
||||
|
||||
if (!empty($this->request->input('avatar_id'))) $this->updateAvatar();
|
||||
|
||||
if (!empty($this->request->input('nickname'))) $this->updateNickname();
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function updateNickname(): void
|
||||
{
|
||||
$this->userInfo->nickname = $this->request->input('nickname');
|
||||
|
||||
if (!$this->userInfo->save()) throw new ErrException('更新昵称失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function updateAvatar(): void
|
||||
{
|
||||
$avatar_id = $this->request->input('avatar_id');
|
||||
|
||||
$this->updateOssObjects([$avatar_id]);
|
||||
if ($this->userInfo->avatar_id > 0) $this->updateOssObjectsDisable([$this->userInfo->avatar_id]);
|
||||
$this->userInfo->avatar_id = $this->request->input('avatar_id');
|
||||
|
||||
if (!$this->userInfo->save()) throw new ErrException('更新头像失败');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user