4 changed files with 156 additions and 5 deletions
-
10app/Controller/TestController.php
-
91app/TaskWorker/AliIotTask.php
-
56app/TaskWorker/PubRequest.php
-
4composer.json
@ -0,0 +1,91 @@ |
|||
<?php |
|||
namespace App\TaskWorker; |
|||
|
|||
use Hyperf\Utils\ApplicationContext; |
|||
use Hyperf\Task\Annotation\Task; |
|||
use AlibabaCloud\Client\AlibabaCloud; |
|||
use AlibabaCloud\Client\Exception\ClientException; |
|||
use AlibabaCloud\Client\Exception\ServerException; |
|||
|
|||
class AliIotTask |
|||
{ |
|||
/** |
|||
* @var DefaultAcsClient |
|||
*/ |
|||
public $client = null; |
|||
|
|||
|
|||
/** |
|||
* @Task |
|||
*/ |
|||
public function exec($method,...$args) |
|||
{ |
|||
AlibabaCloud::accessKeyClient('LTAI4GJEWrN6dVh7HmPKHMyF', 'wMae4ckfVGwMQPVw5ZlVDDpihVeUap') |
|||
->regionId('cn-shanghai') |
|||
->asDefaultClient(); |
|||
$result2 = ''; |
|||
|
|||
$msg = "{\"msg\":\"收款123元\"}"; |
|||
try{ |
|||
AlibabaCloud::rpc() |
|||
->product('Iot') |
|||
// ->scheme('https') // https | http
|
|||
->version('2018-01-20') |
|||
->action('Pub') |
|||
->method('POST') |
|||
->host('iot.cn-shanghai.aliyuncs.com') |
|||
->options([ |
|||
'query' => [ |
|||
'RegionId' => "cn-shanghai", |
|||
'TopicFullName' => "/a1ZSurIJmO0/BOX0000000000003/user/get", |
|||
'MessageContent' => base64_encode($msg), |
|||
'ProductKey' => "a1ZSurIJmO0", |
|||
], |
|||
]) |
|||
->request(); |
|||
//var_dump($result2->toArray());
|
|||
} catch (ClientException $e) { |
|||
echo $e->getErrorMessage() . PHP_EOL; |
|||
} catch (ServerException $e) { |
|||
echo $e->getErrorMessage() . PHP_EOL; |
|||
} |
|||
|
|||
//print_r($response);
|
|||
return ""; |
|||
} |
|||
|
|||
// protected function getClient(){
|
|||
// AlibabaCloud::accessKeyClient('LTAI4GJEWrN6dVh7HmPKHMyF', 'wMae4ckfVGwMQPVw5ZlVDDpihVeUap')
|
|||
// ->regionId('cn-shanghai')
|
|||
// ->asDefaultClient();
|
|||
// $result = '';
|
|||
|
|||
// $msg = "{\"msg\":\"收款123元\"}";
|
|||
// try{
|
|||
// $result = AlibabaCloud::rpc()
|
|||
// ->product('Iot')
|
|||
// // ->scheme('https') // https | http
|
|||
// ->version('2018-01-20')
|
|||
// ->action('Pub')
|
|||
// ->method('POST')
|
|||
// ->host('iot.cn-shanghai.aliyuncs.com')
|
|||
// ->options([
|
|||
// 'query' => [
|
|||
// 'RegionId' => "cn-shanghai",
|
|||
// 'TopicFullName' => "/a1ZSurIJmO0/BOX0000000000003/user/get",
|
|||
// 'MessageContent' => base64_encode($msg),
|
|||
// 'ProductKey' => "a1ZSurIJmO0",
|
|||
// ],
|
|||
// ])
|
|||
// ->request();
|
|||
// var_dump($result->toArray());
|
|||
// } catch (ClientException $e) {
|
|||
// echo $e->getErrorMessage() . PHP_EOL;
|
|||
// } catch (ServerException $e) {
|
|||
// echo $e->getErrorMessage() . PHP_EOL;
|
|||
// }
|
|||
// return $result;
|
|||
|
|||
// }
|
|||
} |
|||
|
|||
@ -0,0 +1,56 @@ |
|||
<?php |
|||
namespace App\TaskWorker; |
|||
use AlibabaCloud\Client\Request\RpcRequest; |
|||
class PubRequest extends RpcRequest |
|||
{ |
|||
function __construct() |
|||
{ |
|||
parent::__construct("Iot", "2017-04-20", "Pub"); |
|||
$this->setMethod("POST"); |
|||
} |
|||
|
|||
private $topicFullName; |
|||
|
|||
private $qos; |
|||
|
|||
private $messageContent; |
|||
|
|||
private $productKey; |
|||
|
|||
public function getTopicFullName() { |
|||
return $this->topicFullName; |
|||
} |
|||
|
|||
public function setTopicFullName($topicFullName) { |
|||
$this->topicFullName = $topicFullName; |
|||
$this->queryParameters["TopicFullName"]=$topicFullName; |
|||
} |
|||
|
|||
public function getQos() { |
|||
return $this->qos; |
|||
} |
|||
|
|||
public function setQos($qos) { |
|||
$this->qos = $qos; |
|||
$this->queryParameters["Qos"]=$qos; |
|||
} |
|||
|
|||
public function getMessageContent() { |
|||
return $this->messageContent; |
|||
} |
|||
|
|||
public function setMessageContent($messageContent) { |
|||
$this->messageContent = $messageContent; |
|||
$this->queryParameters["MessageContent"]=$messageContent; |
|||
} |
|||
|
|||
public function getProductKey() { |
|||
return $this->productKey; |
|||
} |
|||
|
|||
public function setProductKey($productKey) { |
|||
$this->productKey = $productKey; |
|||
$this->queryParameters["ProductKey"]=$productKey; |
|||
} |
|||
|
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue