You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.5 KiB
62 lines
1.5 KiB
<?php
|
|
|
|
namespace App\TaskWorker;
|
|
|
|
use App\Commons\Log;
|
|
use Hyperf\Utils\ApplicationContext;
|
|
use Hyperf\Task\Annotation\Task;
|
|
use AlibabaCloud\Client\AlibabaCloud;
|
|
use AlibabaCloud\Client\Exception\ClientException;
|
|
use AlibabaCloud\Client\Exception\ServerException;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
|
|
class AliIotTask
|
|
{
|
|
/**
|
|
* @Inject
|
|
* @var Log
|
|
*/
|
|
protected $log;
|
|
|
|
/**
|
|
* @var DefaultAcsClient
|
|
*/
|
|
public $client = null;
|
|
|
|
|
|
/**
|
|
* @Task
|
|
*/
|
|
public function exec($device_name, $msg)
|
|
{
|
|
AlibabaCloud::accessKeyClient('LTAI4GJEWrN6dVh7HmPKHMyF', 'wMae4ckfVGwMQPVw5ZlVDDpihVeUap')
|
|
->regionId('cn-shanghai')
|
|
->asDefaultClient();
|
|
|
|
try {
|
|
AlibabaCloud::rpc()
|
|
->product('Iot')
|
|
->version('2018-01-20')
|
|
->action('Pub')
|
|
->method('POST')
|
|
->host('iot.cn-shanghai.aliyuncs.com')
|
|
->options([
|
|
'query' => [
|
|
'RegionId' => "cn-shanghai",
|
|
'TopicFullName' => "/a1ZSurIJmO0/".$device_name."/user/get",
|
|
'MessageContent' => base64_encode($msg),
|
|
'ProductKey' => "a1ZSurIJmO0",
|
|
],
|
|
])
|
|
->request();
|
|
} catch (ClientException $e) {
|
|
echo $e->getErrorMessage() . PHP_EOL;
|
|
} catch (ServerException $e) {
|
|
echo $e->getErrorMessage() . PHP_EOL;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
}
|
|
|