verifymycontent / video-moderation
内容审核 SDK
3.3.2
2024-07-01 13:42 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");
开始创建的直播流审核
当您收到状态为 授权
的 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 安全性
为了确认从 VerifyMyContent 发送的 webhook POST,我们提供了一个辅助类来验证是否正确发送了 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);