CreateTopic.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. require_once __DIR__.'/../../../vendor/autoload.php';
  3. // 导入对应产品模块的client
  4. use TencentCloud\Cls\V20201016\ClsClient;
  5. // 导入要请求接口对应的Request类
  6. use TencentCloud\Cls\V20201016\Models\CreateTopicRequest;
  7. use TencentCloud\Common\Exception\TencentCloudSDKException;
  8. use TencentCloud\Common\Credential;
  9. // 导入可选配置类
  10. use TencentCloud\Common\Profile\ClientProfile;
  11. use TencentCloud\Common\Profile\HttpProfile;
  12. try {
  13. // 实例化一个证书对象,入参需要传入腾讯云账户secretId,secretKey
  14. $cred = new Credential("【secretId】", "【secretKey】");
  15. // 实例化一个http选项,可选的,没有特殊需求可以跳过
  16. $httpProfile = new HttpProfile();
  17. $httpProfile->setReqMethod("POST"); // post请求(默认为post请求)
  18. $httpProfile->setReqTimeout(60); // 请求超时时间,单位为秒(默认60秒)
  19. $httpProfile->setEndpoint("cls.tencentcloudapi.com"); // 指定接入地域域名(默认就近接入)
  20. // 实例化一个client选项,可选的,没有特殊需求可以跳过
  21. $clientProfile = new ClientProfile();
  22. $clientProfile->setSignMethod("TC3-HMAC-SHA256"); // 指定签名算法(默认为HmacSHA256)
  23. $clientProfile->setHttpProfile($httpProfile);
  24. // 实例化要请求产品(以cls为例)的client对象,clientProfile是可选的
  25. $client = new ClsClient($cred, "ap-guangzhou", $clientProfile);
  26. $req = new CreateTopicRequest();
  27. $req ->setLogsetId("【LogSetID】");
  28. $req ->setAutoSplit(true);
  29. $req ->setTopicName("cls_php_test_demo");
  30. $resp = $client->CreateTopic($req);
  31. // 输出json格式的字符串回包
  32. print_r($resp->toJsonString());
  33. }
  34. catch(TencentCloudSDKException $e) {
  35. echo $e;
  36. }