本帖最后由 pengxuanlan 于 2021-7-6 14:52 编辑
1、首先你需要去萤石开放平台,申请开发者帐号(这个我就不啰嗦了https://open.ys7.com/cn/s/index)
2、申请完之后,你会得到一个AccessToken,开发过程中,需要使用到这个,有效期一般为7天
3、AccessToken过期后可以使用AppKey和密钥生成新的Token
[PHP] 纯文本查看 复制代码 $appKey = "57ec14********62e254";
$secret = "6fd9****************dbb1f15c";
$url="https://open.ys7.com/api/lapp/token/get";
$data1 = ["appKey" => $appKey,"appSecret"=>"$secret"];
$myfile = fopen("time.txt", "r") or die("Unable to open file!");
$time2= fread($myfile,filesize("time.txt"));
$time = time();
if($time>$time2){ //失效了,重新获取,正常的话不执行操作
$content1 = posturl($url, $data1)['data'];
$accesstoken=$content1['accessToken'];
$expiretime = $content1['expireTime'];
$myfile = fopen("time.txt", "w") or die("Unable to open file!");
$txt = substr($expiretime,0,10);
fwrite($myfile, $txt);
fclose($myfile);
$myfile = fopen("accesstoken.txt", "w") or die("Unable to open file!");
$txt = $accesstoken;
fwrite($myfile, $txt);
fclose($myfile);
}
$myfile = fopen("accesstoken.txt", "r") or die("Unable to open file!");
$AccessToken= fread($myfile,filesize("accesstoken.txt"));
function posturl($url, $data)
{
//把数组形式的参数转为‘appkey=....&secret=...'这种形式;
$data = http_build_query($data);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);
//输出结果;
return json_decode($output, true);
}
保存好这个Token,方便下次调用
4、在线预览视频
[PHP] 纯文本查看 复制代码 $xlh =$_GET['xlh']; //序列号取过来
$myfile = fopen("accesstoken.txt", "r") or die("Unable to open file!"); //打开Token文件取出Token
$AccessToken= fread($myfile,filesize("accesstoken.txt"));
echo "<iframe src='https://open.ys7.com/ezopen/h5/iframe_se?url=ezopen://open.ys7.com/{$xlh}/1.live&autoplay=1&audio=0&accessToken={$AccessToken}&hd=1&templete=2' width='800' height='600' id='ysopen' allowfullscreen></iframe>";
还有一些操作的功能, 比如云台,加密,删除,改名之类的,接到对应的接口,直接POST就行了 |