mirror of
http://124.126.16.154:8888/singularity/hdk-auth.git
synced 2026-01-15 03:35:05 +08:00
perf(user.rpc): 将成功时返回的数据结构改为了数据
This commit is contained in:
@@ -5,12 +5,15 @@ namespace Singularity\HDK\Auth\Sdk;
|
||||
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
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 Singularity\HDK\Core\Service\HttpRequestService;
|
||||
|
||||
use function Hyperf\Config\config;
|
||||
|
||||
class AddressRpc
|
||||
{
|
||||
#[Inject]
|
||||
@@ -22,11 +25,6 @@ class AddressRpc
|
||||
public function __construct()
|
||||
{
|
||||
$this->requestService->setOptions([
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
],
|
||||
],
|
||||
'base_uri' => config('common.http_request.account.rpc_base_uri'),
|
||||
RequestOptions::ALLOW_REDIRECTS => true,
|
||||
]);
|
||||
@@ -34,13 +32,23 @@ class AddressRpc
|
||||
|
||||
/**
|
||||
* @param $uid
|
||||
* @return ResponseInterface
|
||||
* @return array
|
||||
* @throws GuzzleException
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function list($uid): ResponseInterface
|
||||
public function list($uid): array
|
||||
{
|
||||
return $this->requestService->requestGet('/address', params: ['uid' => $uid]);
|
||||
$response = $this->requestService
|
||||
->setOptions([
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
],
|
||||
],
|
||||
])
|
||||
->requestGet('/rpc/address', params: ['uid' => $uid]);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
return Json::decode($content);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,9 +57,20 @@ class AddressRpc
|
||||
* @return ResponseInterface
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function create($uid, $data): ResponseInterface
|
||||
public function create($uid, $data): array
|
||||
{
|
||||
return $this->requestService->requestPost('/address/create', $data, ['uid' => $uid]);
|
||||
$response = $this->requestService
|
||||
->setOptions([
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
],
|
||||
],
|
||||
])
|
||||
->requestPost('/rpc/address/create', $data, ['uid' => $uid]);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
return Json::decode($content);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,62 +80,115 @@ class AddressRpc
|
||||
* @return ResponseInterface
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function update($uid, $addrId, $data): ResponseInterface
|
||||
public function update($uid, $addrId, $data): array
|
||||
{
|
||||
return $this->requestService->requestPost(
|
||||
'/address/update',
|
||||
$data,
|
||||
[
|
||||
'uid' => $uid,
|
||||
'addr-id' => $addrId,
|
||||
]
|
||||
);
|
||||
$response = $this->requestService
|
||||
->setOptions([
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
],
|
||||
],
|
||||
])
|
||||
->requestPost(
|
||||
'/rpc/address/update',
|
||||
$data,
|
||||
[
|
||||
'uid' => $uid,
|
||||
'addr-id' => $addrId,
|
||||
]
|
||||
);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
return Json::decode($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $uid
|
||||
* @param $addrId
|
||||
* @return ResponseInterface
|
||||
* @return void
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function del($uid, $addrId): ResponseInterface
|
||||
public function del($uid, $addrId): void
|
||||
{
|
||||
return $this->requestService->requestPost('/address/delete', params: [
|
||||
'uid' => $uid,
|
||||
'addr-id' => $addrId,
|
||||
]);
|
||||
$this->requestService
|
||||
->setOptions([
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
],
|
||||
],
|
||||
])
|
||||
->requestPost(
|
||||
'/address/delete',
|
||||
params: [
|
||||
'uid' => $uid,
|
||||
'addr-id' => $addrId,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $uid
|
||||
* @return ResponseInterface
|
||||
* @throws ClientExceptionInterface
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function getDefault($uid): ResponseInterface
|
||||
public function getDefault($uid): array
|
||||
{
|
||||
return $this->requestService->requestGet('/address/getDefault', ['uid' => $uid]);
|
||||
$response = $this->requestService
|
||||
->setOptions([
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
],
|
||||
],
|
||||
])
|
||||
->requestGet('/address/getDefault', ['uid' => $uid]);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
return Json::decode($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $uid
|
||||
* @param $addrId
|
||||
* @return ResponseInterface
|
||||
* @return array
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function setDefault($uid, $addrId): ResponseInterface
|
||||
public function setDefault($uid, $addrId): array
|
||||
{
|
||||
return $this->requestService->requestPost('/address/setDefault', ['uid' => $uid, 'addrId' => $addrId]);
|
||||
$response = $this->requestService
|
||||
->setOptions([
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
],
|
||||
],
|
||||
])
|
||||
->requestPost('/address/setDefault', ['uid' => $uid, 'addrId' => $addrId]);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
return Json::decode($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $addrId
|
||||
* @return ResponseInterface
|
||||
* @throws ClientExceptionInterface
|
||||
* @return array
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function detail($addrId): ResponseInterface
|
||||
public function detail($addrId): array
|
||||
{
|
||||
return $this->requestService->requestGet('/address/detail', ['addr-id' => $addrId]);
|
||||
$response = $this->requestService
|
||||
->setOptions([
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
],
|
||||
],
|
||||
])
|
||||
->requestGet('/address/detail', ['addr-id' => $addrId]);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
return Json::decode($content);
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,10 @@
|
||||
namespace Singularity\HDK\Auth\Sdk;
|
||||
|
||||
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Hyperf\Codec\Json;
|
||||
use Hyperf\Contract\TranslatorInterface;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Http\Client\ClientExceptionInterface;
|
||||
@@ -33,32 +35,35 @@ class UserRpc
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @return ResponseInterface
|
||||
* @return bool
|
||||
* @throws GuzzleException
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function alive($name): ResponseInterface
|
||||
public function alive($name): bool
|
||||
{
|
||||
return $this->requestService
|
||||
->setOptions([
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
try {
|
||||
$this->requestService
|
||||
->setOptions([
|
||||
[
|
||||
'headers' => [
|
||||
'Accept-Language' => $this->translator->getLocale(),
|
||||
],
|
||||
],
|
||||
],
|
||||
])
|
||||
->requestGet('/rpc/user/alive?username=' . urlencode($name));
|
||||
])
|
||||
->requestGet('/rpc/user/alive?username=' . urlencode($name));
|
||||
return true;
|
||||
} catch (ClientException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $uid
|
||||
* @return ResponseInterface
|
||||
* @throws ClientExceptionInterface
|
||||
* @return array
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function detail($uid): ResponseInterface
|
||||
public function detail($uid): array
|
||||
{
|
||||
return $this->requestService
|
||||
$response = $this->requestService
|
||||
->setOptions([
|
||||
[
|
||||
'headers' => [
|
||||
@@ -66,17 +71,20 @@ class UserRpc
|
||||
],
|
||||
],
|
||||
])
|
||||
->requestGet('/rpc/user/detail?uid=' . $uid);
|
||||
->requestGet('/rpc/user/detail', ['uid' => $uid]);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
return Json::decode($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return ResponseInterface
|
||||
* @return array
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function create($data): ResponseInterface
|
||||
public function create($data): array
|
||||
{
|
||||
return $this->requestService
|
||||
$response = $this->requestService
|
||||
->setOptions([
|
||||
[
|
||||
'headers' => [
|
||||
@@ -85,17 +93,20 @@ class UserRpc
|
||||
],
|
||||
])
|
||||
->requestPost('/rpc/user/create', $data);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
return Json::decode($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $uid
|
||||
* @param $data
|
||||
* @return ResponseInterface
|
||||
* @return array
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function update($uid, $data): ResponseInterface
|
||||
public function update($uid, $data): array
|
||||
{
|
||||
return $this->requestService
|
||||
$response = $this->requestService
|
||||
->setOptions([
|
||||
[
|
||||
'headers' => [
|
||||
@@ -103,18 +114,24 @@ class UserRpc
|
||||
],
|
||||
],
|
||||
])
|
||||
->requestPost('/rpc/user/update', $data, params: ['uid' => $uid]);
|
||||
->requestPost(
|
||||
'/rpc/user/update',
|
||||
data: $data,
|
||||
params: ['uid' => $uid]
|
||||
);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
return Json::decode($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $uid_arr
|
||||
* @return ResponseInterface
|
||||
* @throws ClientExceptionInterface
|
||||
* @return array
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function list($uid_arr): ResponseInterface
|
||||
public function list($uid_arr): array
|
||||
{
|
||||
return $this->requestService
|
||||
$response = $this->requestService
|
||||
->setOptions([
|
||||
[
|
||||
'headers' => [
|
||||
@@ -123,16 +140,19 @@ class UserRpc
|
||||
],
|
||||
])
|
||||
->requestGet('/rpc/user', $uid_arr);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
return Json::decode($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return ResponseInterface
|
||||
* @return array
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function checkNamePass($data): ResponseInterface
|
||||
public function checkNamePass($data): array
|
||||
{
|
||||
return $this->requestService
|
||||
$response = $this->requestService
|
||||
->setOptions([
|
||||
[
|
||||
'headers' => [
|
||||
@@ -141,6 +161,9 @@ class UserRpc
|
||||
],
|
||||
])
|
||||
->requestPost('/rpc/user/signIn', $data);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
return Json::decode($content);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user