ltidev / video-moderation
内容审查 SDK
3.3.1
2024-06-28 18:47 UTC
Requires
- verifymycontent/sdk: 2.4.0
README
PHP SDK 用于使用 VerifyMyContent 视频审查服务。
安装
composer require verifymycontent/video-moderation
入门
处理审查集成流程的主要类是 VerifyMyContent\VideoModeration\Moderation
。它将抽象 API 调用的 HMAC 生成。
开始审查
使用 start
方法创建审查,如下例所示
<?php require(__DIR__ . "/vendor/autoload.php"); $moderation = new VerifyMyContent\VideoModeration\Moderation(getenv('VMC_API_KEY'), getenv('VMC_API_SECRET')); //$moderation->useSandbox(); $response = $moderation->start(new \VerifyMyContent\SDK\ContentModeration\Entity\Requests\CreateStaticContentModerationRequest([ "content" => [ "type" => "video", "external_id" => "YOUR-VIDEO-ID", "url" => "https://example.com/video.mp4", "title" => "Uploaded video title", "description" => "Uploaded video description", ], "webhook" => "https://example.com/webhook", "customer" => [ "id" => "YOUR-CUSTOMER-UNIQUE-ID", "email" => "person@example.com", "phone" => "+4412345678" ] ])); // save $response->id if you want to call the moderation status endpoint later // redirect uploader to check identity header("Location: {$response->redirect_url}");
通过 ID 获取审查
检索特定的审查以获取当前状态。例如
<?php require(__DIR__ . "/vendor/autoload.php"); $moderation = new VerifyMyContent\VideoModeration\Moderation(getenv('VMC_API_KEY'), getenv('VMC_API_SECRET')); //$moderation->useSandbox(); $response = $moderation->get($moderationID); // Printing current status echo "Status: {$response->status}";
直播流
要审查直播流广播,您需要使用以下描述的不同 API。
创建直播流审查
使用 createLivestream
方法创建直播流审查,如下例所示
<?php require(__DIR__ . "/vendor/autoload.php"); $moderation = new VerifyMyContent\VideoModeration\Moderation(getenv('VMC_API_KEY'), getenv('VMC_API_SECRET')); //$moderation->useSandbox(); $response = $moderation->createLivestream(new \VerifyMyContent\SDK\ContentModeration\Entity\Requests\CreateLiveContentModerationRequest([ "external_id" => "YOUR-LIVESTREAM-ID", "embed_url" => "https://example.com/live/", "title" => "Live stream title", "description" => "Live stream description", "webhook" => "https://example.com/webhook", "stream" => [ "protocol" => "webrtc", "url" => "https://example.com/live/", ], "customer" => [ "id" => "YOUR-CUSTOMER-UNIQUE-ID", "email" => "person@example.com", "phone" => "+4412345678" ] ])); // save $response->id to start live stream later // redirect uploader to check identity header("Location: {$response->login_url");
开始创建的直播流审查
当您收到状态为 Authorised
的 webhook 时,这意味着您现在可以开始直播流广播,您可以使用 startLivestream
方法来触发审查。
<?php require(__DIR__ . "/vendor/autoload.php"); $moderation = new VerifyMyContent\VideoModeration\Moderation(getenv('VMC_API_KEY'), getenv('VMC_API_SECRET')); //$moderation->useSandbox(); $success = $moderation->startLivestream($_GET['id'], new \VerifyMyContent\SDK\ContentModeration\Entity\Requests\StartLiveContentModerationRequest([ "embed_url" => "https://example.com/live-stream-embed", "stream" => [ "protocol" => "rtmps", "url" => "rtmps://your-server:443/your-video-stream" ], ])); var_dump($success === true);
注意: 在收到用户被授权开始广播的通知 webhook 后,您将在一定时间内发送此请求。
更新直播流审查规则
此端点允许您更新特定直播流的审查规则。
<?php require(__DIR__ . "/vendor/autoload.php"); $moderation = new VerifyMyContent\VideoModeration\Moderation(getenv('VMC_API_KEY'), getenv('VMC_API_SECRET')); //$moderation->useSandbox(); $success = $moderation->changeLivestreamRule($_GET['id'], new \VerifyMyContent\SDK\ContentModeration\Entity\Requests\ChangeLiveContentRuleRequest([ "rule" => "no-nudity" ])); var_dump($success === true);
投诉处理
要为之前上传的内容发起投诉,您需要发送原始内容和用户提出的违规。
创建投诉审查
使用 createComplaintModeration
方法创建投诉审查,如下例所示
<?php require(__DIR__ . "/vendor/autoload.php"); $moderation = new VerifyMyContent\VideoModeration\Moderation(getenv('VMC_API_KEY'), getenv('VMC_API_SECRET')); //$moderation->useSandbox(); $response = $moderation->createComplaintModeration(new \VerifyMyContent\SDK\Complaint\Entity\Requests\CreateStaticContentComplaintRequest([ "content" => [ "description" => "Your description", "external_id" => "YOUR-VIDEO-ID", "tags" => [ "VIOLATION_1" ], "title" => "Your title", "type" => "video", "url" => "https://example.com/video.mp4" ], "customer" => [ "id" => "YOUR-USER-ID" ], "webhook" => "https://example.com/webhook" ])); var_dump($response);
创建直播流投诉审查
使用 createComplaintLivestream
方法创建直播流投诉审查,如下例所示
<?php require(__DIR__ . "/vendor/autoload.php"); $moderation = new VerifyMyContent\VideoModeration\Moderation(getenv('VMC_API_KEY'), getenv('VMC_API_SECRET')); //$moderation->useSandbox(); $response = $moderation->createComplaintLivestream(new \VerifyMyContent\SDK\Complaint\Entity\Requests\CreateLiveContentComplaintRequest([ "complained_at" => "2022-11-04T12:04:08.658Z", "customer" => [ "id" => "YOUR-USER-ID" ], "stream" => [ "external_id" => "YOUR-LIVESTREAM-ID", "tags" => [ "VIOLATION_1" ] ], "webhook" => "https://example.com/webhook" ])); var_dump($response);
创建同意投诉
使用 createComplaintConsent
方法创建同意投诉审查,如下例所示
<?php require(__DIR__ . "/vendor/autoload.php"); $moderation = new VerifyMyContent\VideoModeration\Moderation(getenv('VMC_API_KEY'), getenv('VMC_API_SECRET')); //$moderation->useSandbox(); $response = $moderation->createComplaintConsent(new \VerifyMyContent\SDK\Complaint\Entity\Requests\CreateConsentComplaintRequest([ "content" => [ "external_id" => "YOUR-VIDEO-ID" ], "customer" => [ "id" => "YOUR-USER-ID" ], "webhook" => "https://example.com/webhook" ])); var_dump($response);
Webhook 安全性
为了确认 webhook POST 是从 VerifyMyContent 发送的,我们提供了一个辅助类来验证 Authorization 标头是否正确发送。例如
<?php require(__DIR__ . "/vendor/autoload.php"); // get request body $body = file_get_contents('php://input'); // get headers $headers = getallheaders(); // instantiate VerifyMyContent helper class $hmac = new VerifyMyContent\Commons\Security\HMAC(getenv('VMC_API_KEY'), getenv('VMC_API_SECRET')); // validate hmac Authorization if(!array_key_exists('Authorization', $headers) || !$hmac->validate($headers['Authorization'], $body)) { die("This request did not come from VerifyMyContent"); } // you can do your logic now, the webhook was called from VerifyMyContent. var_dump($body);