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.
 
 

91 lines
2.8 KiB

<?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;
// }
}