本篇文章给大家分享的是有关cloudflare视频转码接口怎么弄,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
/** * 视频上传转码 * @param $video_url * @param $vide_name */ public static function postVideo($video_url, $vide_name) { require_once(__DIR__ . '/../../common/libs/requests/library/Requests.php'); \Requests::register_autoloader(); $headers = array( 'X-Auth-Key' => Yii::$app->params['cf_key'], 'X-Auth-Email' => Yii::$app->params['cf_email'] ); $url = "https://api.cloudflare.com/client/v4/accounts/".Yii::$app->params['cf_account_id']."/stream/copy"; $data = '{"url":"' . $video_url . '","meta":{"name":"' . $vide_name . '"}}'; $response = \Requests::post($url, $headers, $data); $postData = json_decode($response->body); if ($postData->success) { return $postData; } else { return false; } } /** * 获取视频转码后的状态 * @param string $videoCode * @return bool|mixed */ public static function getVideoStatus($videoCode) { require_once(__DIR__ . '/../../common/libs/requests/library/Requests.php'); \Requests::register_autoloader(); $headers = array( 'X-Auth-Key' => Yii::$app->params['cf_key'], 'X-Auth-Email' => Yii::$app->params['cf_email'], 'Content-Type' => 'application/json' ); $url = "https://api.cloudflare.com/client/v4/accounts/".Yii::$app->params['cf_account_id']."/media/{$videoCode}"; $response = \Requests::get($url, $headers); $postData = json_decode($response->body); if($postData->success){ return $postData; }else{ return false; } } /** * 删除转码后的视频 * @param string $videoCode * @return bool */ public static function delVideo($videoCode) { require_once(__DIR__ . '/../../common/libs/requests/library/Requests.php'); \Requests::register_autoloader(); $headers = array( 'X-Auth-Key' => Yii::$app->params['cf_key'], 'X-Auth-Email' => Yii::$app->params['cf_email'], 'Content-Type' => 'application/json' ); $url = "https://api.cloudflare.com/client/v4/zones/".Yii::$app->params['cf_zone_id']."/media/{$videoCode}"; $response = \Requests::delete($url, $headers); if($response->status_code == 200){ return true; }else{ return false; } }
以上就是cloudflare视频转码接口怎么弄,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。