Compare commits
15 Commits
d9cf1f12b4
...
master
Author | SHA1 | Date | |
---|---|---|---|
9607f69e24 | |||
6d3709da51 | |||
1456b21f34 | |||
7343267d3c | |||
430af8aede | |||
9028a8c59d | |||
daefbe884c | |||
9ad385e044 | |||
9b926634cf | |||
320739411a | |||
cffc90dfc9 | |||
5b84406652 | |||
3c5020b80b | |||
e50eed84a2 | |||
41da8f6aee |
@@ -2,7 +2,7 @@
|
|||||||
"name": "maiyoule/mqttclient_author",
|
"name": "maiyoule/mqttclient_author",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"description": "MQTT管理模块操作库",
|
"description": "MQTT管理模块操作库",
|
||||||
"version": "1.1.0",
|
"version": "1.2.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
@@ -162,7 +162,7 @@ class AuthorServerClient
|
|||||||
return new BizResponse();
|
return new BizResponse();
|
||||||
}
|
}
|
||||||
$data = json_decode($content, true);
|
$data = json_decode($content, true);
|
||||||
return new BizResponse($data['code'] ?? 0, $data['message'] ?? '', $data['data'] ?? []);
|
return new BizResponse($data['code'] ?? 0, $data['message'] ?? '', $data['data'] ?? [], $data['err'] ?? '');
|
||||||
|
|
||||||
} catch (ClientException $e) {
|
} catch (ClientException $e) {
|
||||||
$body = $e->getResponse()->getBody()->getContents();
|
$body = $e->getResponse()->getBody()->getContents();
|
||||||
|
37
src/biz/AppUpdateCallbackRequest.php
Normal file
37
src/biz/AppUpdateCallbackRequest.php
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace cn\com\maiyoule\mqttclient\biz;
|
||||||
|
|
||||||
|
use cn\com\maiyoule\mqttclient\IRequest;
|
||||||
|
|
||||||
|
class AppUpdateCallbackRequest extends IRequest
|
||||||
|
{
|
||||||
|
|
||||||
|
public function path(): string
|
||||||
|
{
|
||||||
|
return 'app/callback/update';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function body(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'url' => $this->getUrl()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private string $url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getUrl(): string
|
||||||
|
{
|
||||||
|
return $this->url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUrl(string $url): void
|
||||||
|
{
|
||||||
|
$this->url = $url;
|
||||||
|
}
|
||||||
|
}
|
@@ -18,25 +18,60 @@ class AppUserCreateRequest extends IRequest
|
|||||||
'password' => $this->getPassword(),
|
'password' => $this->getPassword(),
|
||||||
'fettle' => $this->getFettle(),
|
'fettle' => $this->getFettle(),
|
||||||
'role' => $this->getRole(),
|
'role' => $this->getRole(),
|
||||||
'biz' => join(',', $this->getBiz())
|
'publish' => join(',', $this->getPublish()),
|
||||||
|
'subscribe' => join(',', $this->getSubscribe()),
|
||||||
|
'expire' => $this->expireAt
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private array $biz = [];
|
private array $subscribe = [];
|
||||||
|
|
||||||
public function getBiz(): array
|
public function getSubscribe(): array
|
||||||
{
|
{
|
||||||
return $this->biz;
|
return $this->subscribe;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBiz(array|string $biz): void
|
public function setSubscribe(array|string $subscribe): void
|
||||||
{
|
{
|
||||||
if (is_string($biz)) {
|
if (is_string($subscribe)) {
|
||||||
$biz = [$biz];
|
$subscribe = [$subscribe];
|
||||||
}
|
}
|
||||||
$this->biz = $biz;
|
$this->subscribe = $subscribe;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string 过期时间
|
||||||
|
*/
|
||||||
|
private string $expireAt = '';
|
||||||
|
|
||||||
|
public function getExpireAt(): string
|
||||||
|
{
|
||||||
|
return $this->expireAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setExpireAt(string $expireAt): void
|
||||||
|
{
|
||||||
|
$this->expireAt = $expireAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private array $publish = [];
|
||||||
|
|
||||||
|
public function getPublish(): array
|
||||||
|
{
|
||||||
|
return $this->publish;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPublish(array|string $publish): void
|
||||||
|
{
|
||||||
|
if (is_string($publish)) {
|
||||||
|
$publish = [$publish];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->publish = $publish;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private string $password = '';
|
private string $password = '';
|
||||||
private string $fettle = '';
|
private string $fettle = '';
|
||||||
private string $role = 'user';
|
private string $role = 'user';
|
||||||
|
@@ -29,23 +29,37 @@ class AppUserUpdateRequest extends IRequest
|
|||||||
if (!is_null($this->fettle)) {
|
if (!is_null($this->fettle)) {
|
||||||
$data['fettle'] = $this->fettle;
|
$data['fettle'] = $this->fettle;
|
||||||
}
|
}
|
||||||
if (!is_null($this->biz)) {
|
if (!empty($this->publish)) {
|
||||||
$data['biz'] = join(',', $this->biz);
|
$data['publish'] = join(',', $this->getPublish());
|
||||||
|
}
|
||||||
|
if (!empty($this->subscribe)) {
|
||||||
|
$data['subscribe'] = join(',', $this->getSubscribe());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ?array $biz = null;
|
private array $subscribe = [];
|
||||||
|
|
||||||
public function getBiz(): array
|
public function getSubscribe(): array
|
||||||
{
|
{
|
||||||
return $this->biz;
|
return $this->subscribe;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBiz(array $biz): void
|
public function setSubscribe(array|string $subscribe): void
|
||||||
{
|
{
|
||||||
$this->biz = $biz;
|
if (is_string($subscribe)) {
|
||||||
|
$subscribe = [$subscribe];
|
||||||
|
}
|
||||||
|
$this->subscribe = $subscribe;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private array $publish = [];
|
||||||
|
|
||||||
|
public function getPublish(): array
|
||||||
|
{
|
||||||
|
return $this->publish;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string $username;
|
private string $username;
|
||||||
|
@@ -6,19 +6,22 @@ class BizResponse
|
|||||||
{
|
{
|
||||||
private int $code;
|
private int $code;
|
||||||
private string $message;
|
private string $message;
|
||||||
private $data;
|
private mixed $data;
|
||||||
|
|
||||||
|
private string $errCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $code
|
* @param int $code
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param $data
|
* @param array $data
|
||||||
|
* @param string $errCode
|
||||||
*/
|
*/
|
||||||
public function __construct(int $code = -1, string $message = '', $data = [])
|
public function __construct(int $code = -1, string $message = '', mixed $data = [], string $errCode = '')
|
||||||
{
|
{
|
||||||
$this->code = $code;
|
$this->code = $code;
|
||||||
$this->message = $message;
|
$this->message = $message;
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
|
$this->errCode = $errCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isSuccess(): bool
|
public function isSuccess(): bool
|
||||||
@@ -49,7 +52,7 @@ class BizResponse
|
|||||||
/**
|
/**
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function getData()
|
public function getData(): mixed
|
||||||
{
|
{
|
||||||
return $this->data;
|
return $this->data;
|
||||||
}
|
}
|
||||||
@@ -62,5 +65,15 @@ class BizResponse
|
|||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getErrCode(): string
|
||||||
|
{
|
||||||
|
return $this->errCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setErrCode(string $errCode): void
|
||||||
|
{
|
||||||
|
$this->errCode = $errCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@@ -2,11 +2,13 @@
|
|||||||
|
|
||||||
namespace cn\com\maiyoule\mqttclient\test;
|
namespace cn\com\maiyoule\mqttclient\test;
|
||||||
|
|
||||||
|
use cn\com\maiyoule\mqttclient\biz\AppUpdateCallbackRequest;
|
||||||
use cn\com\maiyoule\mqttclient\biz\AppUserCreateRequest;
|
use cn\com\maiyoule\mqttclient\biz\AppUserCreateRequest;
|
||||||
use cn\com\maiyoule\mqttclient\biz\AppUserDeleteRequest;
|
use cn\com\maiyoule\mqttclient\biz\AppUserDeleteRequest;
|
||||||
use cn\com\maiyoule\mqttclient\biz\AppUserUpdateRequest;
|
use cn\com\maiyoule\mqttclient\biz\AppUserUpdateRequest;
|
||||||
use cn\com\maiyoule\mqttclient\exception\ApiException;
|
use cn\com\maiyoule\mqttclient\exception\ApiException;
|
||||||
use cn\com\maiyoule\mqttclient\AuthorServerClient;
|
use cn\com\maiyoule\mqttclient\AuthorServerClient;
|
||||||
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
use PHPUnit\Framework\Assert;
|
use PHPUnit\Framework\Assert;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
@@ -80,4 +82,16 @@ class AppManagerTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUpdateAppUrl()
|
||||||
|
{
|
||||||
|
$request = new AppUpdateCallbackRequest();
|
||||||
|
$request->setUrl('http://202.200.18.46:8000/api.php');
|
||||||
|
try {
|
||||||
|
$biz = $this->manager->exec($request);
|
||||||
|
$this->assertTrue($biz->isSuccess(), $biz->getMessage());
|
||||||
|
} catch (GuzzleException|ApiException $e) {
|
||||||
|
$this->fail($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user