有奖捉虫:云通信与企业服务文档专题,速来> HOT

简介

内容审核功能是由 数据万象(Cloud Infinite,CI)提供的,数据万象将处理能力与 COS SDK 完全结合,您可以直接按照本篇文档指引进行使用。
说明
使用内容审核服务需拥有数据万象使用权限:
主账号请 单击此处 进行角色授权。
子账号请参见 授权子账号接入数据万象服务 文档。
本文档提供关于文档审核的相关的 API 概览以及 SDK 示例代码。
API
操作描述
用于提交一个文档审核任务
用于查询指定的文档审核任务

创建任务

PutDocumentAuditingJob 接口用来提交一个文档审核任务。您可以通过主动设置回调地址接收审核信息,也可以通过 JobId 进行查询。

方法原型

func (s *CIService) PutDocumentAuditingJob(ctx context.Context, opt *PutDocumentAuditingJobOptions) (*PutDocumentAuditingJobResult, *Response, error)

请求示例

// 将 examplebucket-1250000000 和 COS_REGION修改为真实的信息
// CI 任务需要提供CIURL
bu, _ := url.Parse("https://examplebucket-1250000000.cos.COS_REGION.myqcloud.com")
cu, _ := url.Parse("https://examplebucket-1250000000.ci.COS_REGION.myqcloud.com")
b := &cos.BaseURL{BucketURL: bu, CIURL: cu}
c := cos.NewClient(b, &http.Client{
Transport: &cos.AuthorizationTransport{
SecretID: os.Getenv("SECRETID"),
SecretKey: os.Getenv("SECRETKEY"),
}
})
opt := &cos.PutDocumentAuditingJobOptions{
InputUrl: "http://www.example.com/doctest.docx",
InputType: "docx",
Conf: &cos.DocumentAuditingJobConf{
},
}
res, _, err := c.CI.PutDocumentAuditingJob(context.Background(), opt)

参数说明

type PutDocumentAuditingJobOptions struct {
InputObject string
InputUrl string
InputType string
InputDataId string
InputUserInfo *UserExtraInfo
Conf *DocumentAuditingJobConf
}
type UserExtraInfo struct {
TokenId string
Nickname string
DeviceId string
AppId string
Room string
IP string
Type string
}
type DocumentAuditingJobConf struct {
Callback string
BizType string
}
参数名称
参数描述
类型
是否必填
InputObject
存储在 COS 存储桶中的文件名称,例如在目录 test 中的文件 test.doc,则文件名称为 test/test.doc。Object 和 Url 只能选择其中一种。
String
InputUrl
文档文件的链接地址,例如 http://www.example.com/doctest.doc,Object 和 Url 只能选择其中一种。
String
InputType
指定文档文件的类型,如未指定则默认以文件的后缀为类型。如果文件没有后缀,该字段必须指定,否则会审核失败。例如:doc、docx、ppt、pptx 等。
String
InputDataId
文档标识,该字段在结果中返回原始内容,长度限制为512字节。
String
InputUserInfo
用户业务字段。
Object
Conf
审核规则配置。
Struct
BizType
审核策略,不填写则使用默认策略。可在控制台进行配置,详情请参见 设置审核策略
String
Callback
审核结果可以回调形式发送至您的回调地址,支持以 http:// 或者 https:// 开头的地址,例如:http://www.callback.com
String

结果说明

调用 PutDocumentAuditingJob 函数,会解析 api 返回的 xml 内容到 PutDocumentAuditingJobResult 结构,具体返回参数可查看 提交文档审核任务 文档。

查询任务

GetDocumentAuditingJob 接口用来查询指定的文档审核任务。您可以根据文档审核任务的 JobId 来查询文档审核结果。

方法原型

func (s *CIService) GetDocumentAuditingJob(ctx context.Context, jobid string) (*GetDocumentAuditingJobResult, *Response, error)

请求示例

// 将 examplebucket-1250000000 和 COS_REGION修改为真实的信息
// CI 任务需要提供CIURL
bu, _ := url.Parse("https://examplebucket-1250000000.cos.COS_REGION.myqcloud.com")
cu, _ := url.Parse("https://examplebucket-1250000000.ci.COS_REGION.myqcloud.com")
b := &cos.BaseURL{BucketURL: bu, CIURL: cu}
c := cos.NewClient(b, &http.Client{
Transport: &cos.AuthorizationTransport{
SecretID: os.Getenv("SECRETID"),
SecretKey: os.Getenv("SECRETKEY"),
}
})
jobId := "sdce25f391a72e11eb99f********"
res, _, err := c.CI.GetDocumentAuditingJob(context.Background(), jobId)

参数说明

参数名称
参数描述
类型
jobId
任务 ID。
String

结果说明

调用 GetDocumentAuditingJob 函数,会解析 api 返回的 xml 内容到 GetDocumentAuditingJobResult 结构,具体返回参数可查看 查询文档审核任务结果 文档。