detectDocument.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. require dirname(__FILE__, 2) . '/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', // 审核时必须为https
  10. 'credentials'=> array(
  11. 'secretId' => $secretId ,
  12. 'secretKey' => $secretKey)));
  13. try {
  14. // 存储桶文档审核
  15. $result = $cosClient->detectDocument(array(
  16. 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
  17. 'Input' => array(
  18. 'Object' => 'test01.docx',
  19. // 'Type' => 'docx',
  20. // 'DataId' => '', // 选填 该字段在审核结果中会返回原始内容,长度限制为512字节。您可以使用该字段对待审核的数据进行唯一业务标识。
  21. // 'UserInfo' => array(
  22. // 'TokenId' => '',
  23. // 'Nickname' => '',
  24. // 'DeviceId' => '',
  25. // 'AppId' => '',
  26. // 'Room' => '',
  27. // 'IP' => '',
  28. // 'Type' => '',
  29. // 'ReceiveTokenId' => '',
  30. // 'Gender' => '',
  31. // 'Level' => '',
  32. // 'Role' => '',
  33. // ),
  34. ),
  35. // 'Conf' => array(
  36. // 'BizType' => '',
  37. // 'DetectType' => 'Porn,Terrorism,Politics,Ads', // 选填,在只有BizType时走设定策略的审核场景
  38. // 'Callback' => '', // 回调URL 选填
  39. // ), // 选填 在DetectType/BizType都不传的情况下,走默认策略及默认审核场景。
  40. ));
  41. // 文档URL审核
  42. $result = $cosClient->detectDocument(array(
  43. 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
  44. 'Input' => array(
  45. 'Url' => 'https://example.com/test01.docx',
  46. // 'Type' => 'docx',
  47. // 'DataId' => '', // 选填 该字段在审核结果中会返回原始内容,长度限制为512字节。您可以使用该字段对待审核的数据进行唯一业务标识。
  48. ),
  49. // 'Conf' => array(
  50. // 'BizType' => '',
  51. // 'DetectType' => 'Porn,Terrorism,Politics,Ads', // 选填,在只有BizType时走设定策略的审核场景
  52. // 'Callback' => '', // 回调URL 选填
  53. // ), // 选填 在DetectType/BizType都不传的情况下,走默认策略及默认审核场景。
  54. ));
  55. // 请求成功
  56. print_r($result);
  57. } catch (\Exception $e) {
  58. // 请求失败
  59. echo($e);
  60. }