UploadLog.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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\UploadLogRequest;
  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. use Cls\LogGroup;
  13. use Cls\Log\Content;
  14. use Cls\Log;
  15. use Cls\LogGroupList;
  16. $logGroupList = new LogGroupList();
  17. $logGroup = new LogGroup();
  18. $log = new Log();
  19. $content = new Content();
  20. $content ->setKey("name");
  21. $content ->setValue("zhangsan");
  22. $log->setContents([$content]);
  23. $log->setTime(time());
  24. $logGroup->setLogs([$log]);
  25. $logGroupList ->setLogGroupList([$logGroup]);
  26. $pb_str = $logGroupList->serializeToString();
  27. try {
  28. // 实例化一个证书对象,入参需要传入腾讯云账户secretId,secretKey
  29. $cred = new Credential("【secretId】", "【secretKey】");
  30. // 实例化一个http选项,可选的,没有特殊需求可以跳过
  31. $httpProfile = new HttpProfile();
  32. $httpProfile->setReqMethod("POST"); // post请求(默认为post请求)
  33. $httpProfile->setReqTimeout(60); // 请求超时时间,单位为秒(默认60秒)
  34. $httpProfile->setEndpoint("cls.tencentcloudapi.com"); // 指定接入地域域名(默认就近接入)
  35. // 实例化一个client选项,可选的,没有特殊需求可以跳过
  36. $clientProfile = new ClientProfile();
  37. $clientProfile->setSignMethod("TC3-HMAC-SHA256"); // 指定签名算法(默认为HmacSHA256)
  38. $clientProfile->setHttpProfile($httpProfile);
  39. // 实例化要请求产品(以cls为例)的client对象,clientProfile是可选的
  40. $client = new ClsClient($cred, "ap-guangzhou", $clientProfile);
  41. $resp = $client->call_octet_stream("UploadLog", array(
  42. "X-CLS-TopicId" => "[TopicID]",
  43. ), $pb_str);
  44. // 输出json格式的字符串回包
  45. print_r($resp->toJsonString());
  46. }
  47. catch(TencentCloudSDKException $e) {
  48. echo $e;
  49. }