通过阅读本文,您可以了解通过服务端SDK调用OpenAPI审核智能媒体服务媒资信息的示例代码。

示例代码

您可以通过阿里云OpenAPI开发者门户在线调试。

<?php

require_once '../vendor/autoload.php';

use AlibabaCloud\SDK\ICE\V20201109\ICE;
use AlibabaCloud\SDK\ICE\V20201109\Models;
use AlibabaCloud\SDK\ICE\V20201109\Models\QueryMediaCensorJobListRequest;
use AlibabaCloud\SDK\ICE\V20201109\Models\QueryMediaCensorJobDetailRequest;
use AlibabaCloud\SDK\ICE\V20201109\Models\CreateCustomTemplateRequest;
use AlibabaCloud\SDK\ICE\V20201109\Models\SubmitMediaCensorJobRequest;
use AlibabaCloud\SDK\ICE\V20201109\Models\SubmitMediaCensorJobRequest\input;

use Darabonba\OpenApi\Models\Config;

try {

    // 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
    // 本示例以将AccessKey ID和 AccessKey Secret保存在环境变量为例说明。配置方法请参见:https://help.aliyun.com/document_detail/311677.html。
    $credential = new Credential([]);
    $config = new Config([
     'credential' => $credential,
     'endpoint' => 'ice.cn-shanghai.aliyuncs.com'
    ]);
    // 如需硬编码AccessKey ID和AccessKey Secret,代码如下,但强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
    // $config->accessKeyId = '<yourAccessKeyId>';
    // $config->accessKeySecret = '<yourAccessKeySecret>';
    $client = new ICE($config);

    // 创建审核模板。
    $censorTemplateConfig = "{\"Scene\":[\"porn\",\"terrorism\"],\"Scope\":[\"title\",\"video\",\"audio\",\"cover\"]}";
    $request = new CreateCustomTemplateRequest();
    $request->name = "sdk_sample_censor_template";
    $request->type = 7;
    $request->subtype = 1;
    $request->templateConfig = $censorTemplateConfig;
    $response = $client->createCustomTemplate($request);
    echo json_encode($response->body);

    // 提交媒体审核作业。
    $request = new SubmitMediaCensorJobRequest();
    $request->input = new input(["type" => "Media","media" => "3945e42d01823498****"]);
    $request->output = "oss://test_bucket/censor/snapshot-{Count}.jpg";
    $request->templateId = "4945e09631823498****";
    $response = $client->submitMediaCensorJob($request);
    echo json_encode($response->body);

    // 查询媒体审核任务作业详情。
    $request = new QueryMediaCensorJobDetailRequest();
    $request->jobId = "20b48fb04483915d4f2cd8ac****";
    $response = $client->queryMediaCensorJobDetail($request);
    echo json_encode($response->body);

    // 查询媒体审核任务作业列表。
    $request = new QueryMediaCensorJobListRequest();
    $request->jobIds = "20b48fb04483915d4f2cd8ac****";
    $response = $client->QueryMediaCensorJobList($request);
    echo json_encode($response->body);

} catch (TeaUnableRetryError $e) {
  var_dump($e->getMessage());
}

相关接口