mirror of
http://124.126.16.154:8888/singularity/hdk-auth.git
synced 2026-01-15 05:55:07 +08:00
perf(user.rpc): 将成功时返回的数据结构改为了User 资源
This commit is contained in:
@@ -9,8 +9,8 @@ use GuzzleHttp\RequestOptions;
|
||||
use Hyperf\Codec\Json;
|
||||
use Hyperf\Contract\TranslatorInterface;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Http\Client\ClientExceptionInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Hyperf\Resource\Json\AnonymousResourceCollection;
|
||||
use Singularity\HDK\Auth\Resource\User;
|
||||
use Singularity\HDK\Core\Service\HttpRequestService;
|
||||
|
||||
use function Hyperf\Config\config;
|
||||
@@ -58,10 +58,10 @@ class UserRpc
|
||||
|
||||
/**
|
||||
* @param $uid
|
||||
* @return array
|
||||
* @return User
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function detail($uid): array
|
||||
public function detail($uid): User
|
||||
{
|
||||
$response = $this->requestService
|
||||
->setOptions([
|
||||
@@ -74,15 +74,16 @@ class UserRpc
|
||||
->requestGet('/rpc/user/detail', ['uid' => $uid]);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
return Json::decode($content);
|
||||
$user = Json::decode($content);
|
||||
return User::make($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return array
|
||||
* @return User
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function create($data): array
|
||||
public function create($data): User
|
||||
{
|
||||
$response = $this->requestService
|
||||
->setOptions([
|
||||
@@ -95,16 +96,18 @@ class UserRpc
|
||||
->requestPost('/rpc/user/create', $data);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
return Json::decode($content);
|
||||
$user = Json::decode($content);
|
||||
|
||||
return new User($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $uid
|
||||
* @param $data
|
||||
* @return array
|
||||
* @return User
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function update($uid, $data): array
|
||||
public function update($uid, $data): User
|
||||
{
|
||||
$response = $this->requestService
|
||||
->setOptions([
|
||||
@@ -121,15 +124,16 @@ class UserRpc
|
||||
);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
return Json::decode($content);
|
||||
$user = Json::decode($content);
|
||||
return new User($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $uid_arr
|
||||
* @return array
|
||||
* @return AnonymousResourceCollection<User>
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function list($uid_arr): array
|
||||
public function list($uid_arr): AnonymousResourceCollection
|
||||
{
|
||||
$response = $this->requestService
|
||||
->setOptions([
|
||||
@@ -142,28 +146,32 @@ class UserRpc
|
||||
->requestGet('/rpc/user', $uid_arr);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
return Json::decode($content);
|
||||
$users = Json::decode($content);
|
||||
|
||||
return User::collection($users);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return array
|
||||
* @return bool
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function checkNamePass($data): array
|
||||
public function checkNamePass($data): bool
|
||||
{
|
||||
$response = $this->requestService
|
||||
->setOptions([
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
try {
|
||||
$response = $this->requestService
|
||||
->setOptions([
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
],
|
||||
],
|
||||
],
|
||||
])
|
||||
->requestPost('/rpc/user/signIn', $data);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
return Json::decode($content);
|
||||
])
|
||||
->requestPost('/rpc/user/signIn', $data);
|
||||
return true;
|
||||
} catch (ClientException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user