mirror of
http://124.126.16.154:8888/singularity/hdk-auth.git
synced 2026-01-15 05:35: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\Codec\Json;
|
||||||
use Hyperf\Contract\TranslatorInterface;
|
use Hyperf\Contract\TranslatorInterface;
|
||||||
use Hyperf\Di\Annotation\Inject;
|
use Hyperf\Di\Annotation\Inject;
|
||||||
use Psr\Http\Client\ClientExceptionInterface;
|
use Hyperf\Resource\Json\AnonymousResourceCollection;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Singularity\HDK\Auth\Resource\User;
|
||||||
use Singularity\HDK\Core\Service\HttpRequestService;
|
use Singularity\HDK\Core\Service\HttpRequestService;
|
||||||
|
|
||||||
use function Hyperf\Config\config;
|
use function Hyperf\Config\config;
|
||||||
@@ -58,10 +58,10 @@ class UserRpc
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $uid
|
* @param $uid
|
||||||
* @return array
|
* @return User
|
||||||
* @throws GuzzleException
|
* @throws GuzzleException
|
||||||
*/
|
*/
|
||||||
public function detail($uid): array
|
public function detail($uid): User
|
||||||
{
|
{
|
||||||
$response = $this->requestService
|
$response = $this->requestService
|
||||||
->setOptions([
|
->setOptions([
|
||||||
@@ -74,15 +74,16 @@ class UserRpc
|
|||||||
->requestGet('/rpc/user/detail', ['uid' => $uid]);
|
->requestGet('/rpc/user/detail', ['uid' => $uid]);
|
||||||
|
|
||||||
$content = $response->getBody()->getContents();
|
$content = $response->getBody()->getContents();
|
||||||
return Json::decode($content);
|
$user = Json::decode($content);
|
||||||
|
return User::make($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $data
|
* @param $data
|
||||||
* @return array
|
* @return User
|
||||||
* @throws GuzzleException
|
* @throws GuzzleException
|
||||||
*/
|
*/
|
||||||
public function create($data): array
|
public function create($data): User
|
||||||
{
|
{
|
||||||
$response = $this->requestService
|
$response = $this->requestService
|
||||||
->setOptions([
|
->setOptions([
|
||||||
@@ -95,16 +96,18 @@ class UserRpc
|
|||||||
->requestPost('/rpc/user/create', $data);
|
->requestPost('/rpc/user/create', $data);
|
||||||
|
|
||||||
$content = $response->getBody()->getContents();
|
$content = $response->getBody()->getContents();
|
||||||
return Json::decode($content);
|
$user = Json::decode($content);
|
||||||
|
|
||||||
|
return new User($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $uid
|
* @param $uid
|
||||||
* @param $data
|
* @param $data
|
||||||
* @return array
|
* @return User
|
||||||
* @throws GuzzleException
|
* @throws GuzzleException
|
||||||
*/
|
*/
|
||||||
public function update($uid, $data): array
|
public function update($uid, $data): User
|
||||||
{
|
{
|
||||||
$response = $this->requestService
|
$response = $this->requestService
|
||||||
->setOptions([
|
->setOptions([
|
||||||
@@ -121,15 +124,16 @@ class UserRpc
|
|||||||
);
|
);
|
||||||
|
|
||||||
$content = $response->getBody()->getContents();
|
$content = $response->getBody()->getContents();
|
||||||
return Json::decode($content);
|
$user = Json::decode($content);
|
||||||
|
return new User($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $uid_arr
|
* @param $uid_arr
|
||||||
* @return array
|
* @return AnonymousResourceCollection<User>
|
||||||
* @throws GuzzleException
|
* @throws GuzzleException
|
||||||
*/
|
*/
|
||||||
public function list($uid_arr): array
|
public function list($uid_arr): AnonymousResourceCollection
|
||||||
{
|
{
|
||||||
$response = $this->requestService
|
$response = $this->requestService
|
||||||
->setOptions([
|
->setOptions([
|
||||||
@@ -142,28 +146,32 @@ class UserRpc
|
|||||||
->requestGet('/rpc/user', $uid_arr);
|
->requestGet('/rpc/user', $uid_arr);
|
||||||
|
|
||||||
$content = $response->getBody()->getContents();
|
$content = $response->getBody()->getContents();
|
||||||
return Json::decode($content);
|
$users = Json::decode($content);
|
||||||
|
|
||||||
|
return User::collection($users);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $data
|
* @param $data
|
||||||
* @return array
|
* @return bool
|
||||||
* @throws GuzzleException
|
* @throws GuzzleException
|
||||||
*/
|
*/
|
||||||
public function checkNamePass($data): array
|
public function checkNamePass($data): bool
|
||||||
{
|
{
|
||||||
$response = $this->requestService
|
try {
|
||||||
->setOptions([
|
$response = $this->requestService
|
||||||
[
|
->setOptions([
|
||||||
'headers' => [
|
[
|
||||||
'Accept-Language' => $this->translator->getLocale(),
|
'headers' => [
|
||||||
|
'Accept-Language' => $this->translator->getLocale(),
|
||||||
|
],
|
||||||
],
|
],
|
||||||
],
|
])
|
||||||
])
|
->requestPost('/rpc/user/signIn', $data);
|
||||||
->requestPost('/rpc/user/signIn', $data);
|
return true;
|
||||||
|
} catch (ClientException) {
|
||||||
$content = $response->getBody()->getContents();
|
return false;
|
||||||
return Json::decode($content);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user