通過閱讀本文,您可以了解通過服務端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保存在環境變量為例說明。配置方法請參見:http://bestwisewords.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());
}
相關接口
文檔內容是否對您有幫助?