帮你快速理解、总结文档立即下载

文档审核

最近更新时间:2025-07-18 10:27:32
我的收藏

简介

本文档提供关于文档审核的 API 概览和 SDK 示例代码。
注意
需要 COS PHP SDK v2.4.4 及以上版本。旧版本可能存在 bug,使用时建议升级到 最新版本。
API
操作描述
用于提交一个文档审核任务。
用于查询指定的文档审核任务。

提交文档审核任务

功能说明

用于提交一个文档审核任务。

方法原型

public Guzzle\\Service\\Resource\\Model detectDocument(array $args = array());

请求示例

示例一:存储桶文档文件审核
<?php

require dirname(__FILE__) . '/../vendor/autoload.php';

$secretId = "SECRETID"; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region,已创建桶归属的 region 可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\\Cos\\Client(
array(
'region' => $region,
'schema' => 'https', // 审核时必须为 https
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));

try {
// 存储桶文档审核
$result = $cosClient->detectDocument(array(
'Bucket' => 'examplebucket-1250000000', //存储桶名称,由 BucketName-Appid 组成,可以在 COS 控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Input' => array(
'Object' => 'test01.docx',
// 'Type' => 'docx',
// 'DataId' => '', // 选填 该字段在审核结果中会返回原始内容,长度限制为512字节。您可以使用该字段对待审核的数据进行唯一业务标识。
// 'UserInfo' => array(
// 'TokenId' => '',
// 'Nickname' => '',
// 'DeviceId' => '',
// 'AppId' => '',
// 'Room' => '',
// 'IP' => '',
// 'Type' => '',
// 'ReceiveTokenId' => '',
// 'Gender' => '',
// 'Level' => '',
// 'Role' => '',
// ),
),
// 'Conf' => array(
// 'BizType' => '',
// 'Callback' => '', // 回调URL 选填
// 'Freeze' => array(
// 'PornScore' => 90,
// 'AdsScore' => 90,
// 'PoliticsScore' => 90,
// 'TerrorismScore' => 90,
// ), // 选填 可通过该字段,设置根据审核结果给出的不同分值,对文档进行自动冻结。仅当`input`中审核的文档为`object`时有效。
// ), // 选填 在 BizType 不传的情况下,走默认策略及默认审核场景。
));
// 请求成功
print_r($result);
} catch (\\Exception $e) {
// 请求失败
echo($e);
}
示例二:文档URL审核
<?php

require dirname(__FILE__) . '/../vendor/autoload.php';

$secretId = "SECRETID"; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region,已创建桶归属的 region 可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\\Cos\\Client(
array(
'region' => $region,
'schema' => 'https', // 审核时必须为https
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));

try {
// 文档URL审核
$result = $cosClient->detectDocument(array(
'Bucket' => 'examplebucket-1250000000', //存储桶名称,由 BucketName-Appid 组成,可以在 COS 控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Input' => array(
'Url' => 'https://example.com/test01.docx',
// 'Type' => 'docx',
// 'DataId' => '', // 选填 该字段在审核结果中会返回原始内容,长度限制为512字节。您可以使用该字段对待审核的数据进行唯一业务标识。
),
// 'Conf' => array(
// 'BizType' => '',
// 'Callback' => '', // 回调URL 选填
// ), // 选填 在 BizType 不传的情况下,走默认策略及默认审核场景。
));
// 请求成功
print_r($result);
} catch (\\Exception $e) {
// 请求失败
echo($e);
}

参数说明

Request 中的具体数据描述如下:
节点名称(关键字)
父节点
描述
类型
是否必选
Input
Request
需要审核的内容。
Container
是
Conf
Request
审核规则配置。
Container
是
Container 类型 Input 的具体数据描述如下:
节点名称(关键字)
父节点
描述
类型
是否必选
Object
Request.Input
存储在 COS 存储桶中的文件名称,例如在目录 test 中的文件 test.doc,则文件名称为 test/test.doc。Object 和 Url 只能选择其中一种。
String
否
Url
Request.Input
文档文件的链接地址,例如 http://www.example.com/doctest.doc,Object 和 Url 只能选择其中一种。
String
否
Type
Request.Input
指定文档文件的类型,如未指定则默认以文件的后缀为类型。 如果文件没有后缀,该字段必须指定,否则会审核失败。例如:doc、docx、ppt、pptx 等
String
否
DataId
Request.Input
该字段在审核结果中会返回原始内容,长度限制为512字节。您可以使用该字段对待审核的数据进行唯一业务标识。
String
否
UserInfo
Request.Input
用户业务字段。
Container
否
Container 节点 UserInfo 的内容:
节点名称(关键字)
父节点
描述
类型
是否必选
TokenId
Request.Input.UserInfo
用户业务 TokenId,长度不超过128字节。
String
否
Nickname
Request.Input.UserInfo
用户业务 Nickname,长度不超过128字节。
String
否
DeviceId
Request.Input.UserInfo
用户业务 DeviceId,长度不超过128字节。
String
否
AppId
Request.Input.UserInfo
用户业务 AppId,长度不超过128字节。
String
否
Room
Request.Input.UserInfo
用户业务 Room,长度不超过128字节。
String
否
IP
Request.Input.UserInfo
用户业务 IP,长度不超过128字节。
String
否
Type
Request.Input.UserInfo
用户业务 Type,长度不超过128字节。
String
否
ReceiveTokenId
Request.Input.UserInfo
用户业务 ReceiveTokenId,长度不超过128字节。
String
否
Gender
Request.Input.UserInfo
用户业务 Gender,长度不超过128字节。
String
否
Level
Request.Input.UserInfo
用户业务 Level,长度不超过128字节。
String
否
Role
Request.Input.UserInfo
用户业务 Role,长度不超过128字节。
String
否
Container 类型 Conf 的具体数据描述如下:
节点名称(关键字)
父节点
描述
类型
是否必选
BizType
Request.Conf
表示审核策略的唯一标识,您可以通过控制台上的审核策略页面,配置您希望审核的场景,如涉黄、广告、违法违规等,配置指引: 设置审核策略。您可以在控制台上获取到 BizType。BizType 填写时,此条审核请求将按照该审核策略中配置的场景进行审核。 BizType 不填写时,将自动使用默认的审核策略。
String
否
Callback
Request.Conf
审核结果可以回调形式发送至您的回调地址,支持以 http:// 或者 https:// 开头的地址,例如:http://www.callback.com
String
否
CallbackType
Request.Conf
回调片段类型,有效值:1(回调全部分页)、2(回调违规分页)。默认为 1。
Integer
否
Freeze
Request.Conf
可通过该字段,设置根据审核结果给出的不同分值,对文档进行自动冻结。仅当input中审核的文档为object时有效。
Container
否
Container 类型 Freeze 的具体数据描述如下:
节点名称(关键字)
父节点
描述
类型
是否必选
PornScore
Request.Conf.Freeze
取值为[0,100],表示当色情审核结果大于或等于该分数时,自动进行冻结操作。不填写则表示不自动冻结,默认值为空。
Integer
否
AdsScore
Request.Conf.Freeze
取值为[0,100],表示当广告审核结果大于或等于该分数时,自动进行冻结操作。不填写则表示不自动冻结,默认值为空。
Integer
否

返回结果示例

GuzzleHttp\\Command\\Result Object
(
[RequestId] => NjEzZTBjMmRfNzgwYzdkNjRfMThiOV8zZTY4ZGE=
[ContentType] => application/xml
[ContentLength] => 357
[JobsDetail] => Array
(
[Url] => https://example.com/test01.pdf
[JobId] => sd48e1ea1213d411ec953452540024deb5
[State] => Submitted
[CreationTime] => 2021-09-12T22:18:21+08:00
)

[Bucket] => examplebucket-1250000000
[Location] => examplebucket-1250000000.ci.ap-guangzhou.myqcloud.com/document/auditing
)

查询文档审核任务

功能说明

用于查询文档审核任务执行情况和结果。

方法原型

public Guzzle\\Service\\Resource\\Model getDetectDocumentResult(array $args = array());

请求示例

<?php

require dirname(__FILE__) . '/../vendor/autoload.php';

$secretId = "SECRETID"; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region,已创建桶归属的 region 可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\\Cos\\Client(
array(
'region' => $region,
'schema' => 'https', // 审核时必须为https
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));
try {
$result = $cosClient->getDetectDocumentResult(array(
'Bucket' => 'examplebucket-1250000000', //存储桶名称,由 BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => 'examplejobid', // JobId
));
// 请求成功
print_r($result);
} catch (\\Exception $e) {
// 请求失败
echo($e);
}

参数说明

参数名称
类型
描述
是否必填
Bucket
String
存储桶名称,格式:BucketName-APPID。
是
Key
String
需要查询的任务 ID。
是

返回结果示例

GuzzleHttp\\Command\\Result Object
(
[RequestId] => NjEzZTBjZWRfZmNjYTNiMGFfNGM2M18zZGUzNzc=
[ContentType] => application/xml
[ContentLength] => 4382
[JobsDetail] => Array
(
[JobId] => sd48e1ea1213d411ec953452540024deb5
[State] => Success
[Suggestion] => 1
[Label] => Politics
[CreationTime] => 2023-05-15T16:27:18+08:00
[Object] => test01.docx
[PageCount] => 2
[ForbidState] => 1
[Labels] => Array
(
[PornInfo] => Array
(
[HitFlag] => 2
[Score] => 61
)

[TerrorismInfo] => Array
(
[HitFlag] => 2
[Score] => 90
)

[PoliticsInfo] => Array
(
[HitFlag] => 1
[Score] => 98
)

[AdsInfo] => Array
(
[HitFlag] => 0
[Score] => 0
)

)

[PageSegment] => Array
(
[Results] => Array
(

[0] => Array
(
[Url] => https://auditing-gz-1258125638.cos.ap-guangzhou.myqcloud.com/document/franktest-1251704708/sd4e26dbf8f2fa11edbe96525400d89c2c/output/1.jpg?q-sign-algorithm=sha1&q-ak=************************************&q-sign-time=1688030%3B16215230&q-key-time=1684208030%3B1684215230&q-header-list=host&q-url-param-list=&q-signature=********************************************
[Text] => 这里是一条测试数据。
[PageNumber] => 1
[Label] => Porn
[Suggestion] => 2
[PornInfo] => Array
(
[HitFlag] => 2
[Category] => PornOCR
[SubLabel] =>
[Score] => 61
[OcrResults] => Array
(
[0] => Array
(
[Text] => 这里是一条测试数据。
[SubLabel] =>
[Keywords] => Array
(
[0] => Keyword
)

[Location] => Array
(
[X] => 0
[Y] => 0
[Height] => 0
[Width] => 0
[Rotate] => 0
)

)

)

)

[TerrorismInfo] => Array
(
[HitFlag] => 2
[Category] => Firearms
[SubLabel] => Gun
[Score] => 90
)

[PoliticsInfo] => Array
(
[HitFlag] => 0
[Category] =>
[SubLabel] =>
[Score] => 43
)

[AdsInfo] => Array
(
[HitFlag] => 0
[Category] =>
[SubLabel] =>
[Score] => 0
)

)

)

)

)

[Key] => sd48e1ea1213d411ec953452540024deb5
[Bucket] => examplebucket-1250000000
[Location] => examplebucket-1250000000.ci.ap-guangzhou.myqcloud.com/document/auditing/sd48e1ea1213d411ec953452540024deb5
)