detectText.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. require dirname(__FILE__) . '/../vendor/autoload.php';
  3. $secretId = "SECRETID"; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
  4. $secretKey = "SECRETKEY"; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
  5. $region = "ap-beijing"; //替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket
  6. $cosClient = new Qcloud\Cos\Client(
  7. array(
  8. 'region' => $region,
  9. 'schema' => 'https', //协议头部,默认为http
  10. 'credentials'=> array(
  11. 'secretId' => $secretId ,
  12. 'secretKey' => $secretKey)));
  13. try {
  14. // start --------------- 文本内容审核 ----------------- //
  15. $content = '敏感词';
  16. $result = $cosClient->detectText(array(
  17. 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
  18. 'Input' => array(
  19. 'Content' => base64_encode($content) // 文本需base64_encode
  20. ),
  21. 'Conf' => array(
  22. 'DetectType' => 'Porn,Terrorism,Politics,Ads', //Porn,Terrorism,Politics,Ads,Illegal,Abuse类型
  23. 'BizType' => '',
  24. ),
  25. ));
  26. // 请求成功
  27. print_r($result);
  28. // end --------------- 文本内容审核 ----------------- //
  29. // start --------------- 存储桶文本文件审核 ----------------- //
  30. $result = $cosClient->detectText(array(
  31. 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
  32. 'Input' => array(
  33. 'Object' => 'test01.txt'
  34. ),
  35. 'Conf' => array(
  36. 'DetectType' => 'Porn,Terrorism,Politics,Ads',
  37. // 'Callback' => 'https://example.callback.com/test/', // 回调URL
  38. // 'CallbackVersion' => 'Detail',
  39. // 'BizType' => '',
  40. ),
  41. ));
  42. // 请求成功
  43. print_r($result);
  44. // end --------------- 存储桶文本文件审核 ----------------- //
  45. } catch (\Exception $e) {
  46. // 请求失败
  47. echo($e);
  48. }