Skip to content

Instantly share code, notes, and snippets.

@vibhavsinha
Last active September 10, 2022 21:40
Show Gist options
  • Save vibhavsinha/8e927c4055478cbe5a91 to your computer and use it in GitHub Desktop.
Save vibhavsinha/8e927c4055478cbe5a91 to your computer and use it in GitHub Desktop.
VdoCipher API implementation in PHP
<?php
/**
* This code can be used in your controller or view
* file to display the video player
* PHP Version 5.5
*
* @category Api
* @package Vdocipher
* @author Vibhav Sinha <[email protected]>
* @license MIT https://tldrlegal.com/license/mit-license
* @link https://gist.github.com/vibhavsinha/8e927c4055478cbe5a91
*/
require "vdocipher_api.php";
////Replace the caps VIDEO_ID with your video id.
vdo_play("VIDEO_ID", false);
?>
<?php
/**
* This file can be placed once in the project and can be included
* wherever necessary
* PHP Version 5.5
*
* @category Api
* @package Vdocipher
* @author Vibhav Sinha <[email protected]>
* @license MIT https://tldrlegal.com/license/mit-license
* @link https://gist.github.com/vibhavsinha/8e927c4055478cbe5a91
*/
/**
* Makes an API call
*
* @param string $action name of action
* @param array $params get parameters to be sent
* @param string $posts post parameter to be sent
*
* @return string api response
*/
function send($action, $params, $posts = false)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$getData = http_build_query($params);
////Replace the caps CLIENT_SECRET_KEY with your api secret key.
$postData = "clientSecretKey=CLIENT_SECRET_KEY";
if ($posts) {
$postData .= "&". $posts;
}
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
$url = "https://api.vdocipher.com/v2/$action/?$getData";
curl_setopt($curl, CURLOPT_URL, $url);
$html = curl_exec($curl);
curl_close($curl);
return $html;
}
/**
* Returns the embed code
*
* @param string $id video id
* @param string $posts post data
*
* @return {void}
*/
function Vdo_play($id, $posts = false)
{
$OTP = send(
"otp", array(
'video'=>$id
), $posts
);
$jsonObj = json_decode($OTP);
if (!isset($jsonObj->otp)) {
if (isset($jsonObj->error)) {
echo $jsonObj->error;
return;
}
echo 'Error loading video';
return;
}
$OTP = json_decode($OTP)->otp;
echo <<<EOF
<div id="vdo$OTP" style="width: 1280px; max-width:100%; height:auto;"></div>
<script>
(function(v,i,d,e,o){v[o]=v[o]||{}; v[o].add = v[o].add || function V(a){
(v[o].d=v[o].d||[]).push(a); };if(!v[o].l) { v[o].l=1*new Date();
a=i.createElement(d), m=i.getElementsByTagName(d)[0]; a.async=1; a.src=e;
m.parentNode.insertBefore(a,m); }})(window,document,"script",
"https://cdn-gce.vdocipher.com/playerAssets/1.5.0/vdo.js","vdo");
vdo.add({
otp: "$OTP",
playbackInfo: btoa(JSON.stringify({
videoId: "$id"
})),
theme: "9ae8bbe8dd964ddc9bdb932cca1cb59a",
container: document.querySelector( "#vdo$OTP" ),
});
</script>
EOF;
}
@deepakjan
Copy link

Do you have the code sample for Ionic 3 and angular4 please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment