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

  1. <?php
  2. namespace App\TaskWorker;
  3. use Hyperf\Utils\ApplicationContext;
  4. use Hyperf\Task\Annotation\Task;
  5. use AlibabaCloud\Client\AlibabaCloud;
  6. use AlibabaCloud\Client\Exception\ClientException;
  7. use AlibabaCloud\Client\Exception\ServerException;
  8. class AliIotTask
  9. {
  10. /**
  11. * @var DefaultAcsClient
  12. */
  13. public $client = null;
  14. /**
  15. * @Task
  16. */
  17. public function exec($method,...$args)
  18. {
  19. AlibabaCloud::accessKeyClient('LTAI4GJEWrN6dVh7HmPKHMyF', 'wMae4ckfVGwMQPVw5ZlVDDpihVeUap')
  20. ->regionId('cn-shanghai')
  21. ->asDefaultClient();
  22. $result2 = '';
  23. $msg = "{\"msg\":\"收款123元\"}";
  24. try{
  25. AlibabaCloud::rpc()
  26. ->product('Iot')
  27. // ->scheme('https') // https | http
  28. ->version('2018-01-20')
  29. ->action('Pub')
  30. ->method('POST')
  31. ->host('iot.cn-shanghai.aliyuncs.com')
  32. ->options([
  33. 'query' => [
  34. 'RegionId' => "cn-shanghai",
  35. 'TopicFullName' => "/a1ZSurIJmO0/BOX0000000000003/user/get",
  36. 'MessageContent' => base64_encode($msg),
  37. 'ProductKey' => "a1ZSurIJmO0",
  38. ],
  39. ])
  40. ->request();
  41. //var_dump($result2->toArray());
  42. } catch (ClientException $e) {
  43. echo $e->getErrorMessage() . PHP_EOL;
  44. } catch (ServerException $e) {
  45. echo $e->getErrorMessage() . PHP_EOL;
  46. }
  47. //print_r($response);
  48. return "";
  49. }
  50. // protected function getClient(){
  51. // AlibabaCloud::accessKeyClient('LTAI4GJEWrN6dVh7HmPKHMyF', 'wMae4ckfVGwMQPVw5ZlVDDpihVeUap')
  52. // ->regionId('cn-shanghai')
  53. // ->asDefaultClient();
  54. // $result = '';
  55. // $msg = "{\"msg\":\"收款123元\"}";
  56. // try{
  57. // $result = AlibabaCloud::rpc()
  58. // ->product('Iot')
  59. // // ->scheme('https') // https | http
  60. // ->version('2018-01-20')
  61. // ->action('Pub')
  62. // ->method('POST')
  63. // ->host('iot.cn-shanghai.aliyuncs.com')
  64. // ->options([
  65. // 'query' => [
  66. // 'RegionId' => "cn-shanghai",
  67. // 'TopicFullName' => "/a1ZSurIJmO0/BOX0000000000003/user/get",
  68. // 'MessageContent' => base64_encode($msg),
  69. // 'ProductKey' => "a1ZSurIJmO0",
  70. // ],
  71. // ])
  72. // ->request();
  73. // var_dump($result->toArray());
  74. // } catch (ClientException $e) {
  75. // echo $e->getErrorMessage() . PHP_EOL;
  76. // } catch (ServerException $e) {
  77. // echo $e->getErrorMessage() . PHP_EOL;
  78. // }
  79. // return $result;
  80. // }
  81. }