天脉php,关于龙共山高的“天脉token直接算法 生成M3U8地址 PHP版本”

//ANONYMOUS("N","ANONYMOUS","匿名"),

//STB("O","STB","运营版机顶盒"),

//GESTB("Q","GESTB","通用版机顶盒"),

//MT("R","MT","移动应用"),

//WEIXIN("K","WEIXIN","微信应用"),

//WEB("V","WEB","网页应用"),

//PLUGIN("P","PLUGIN","插件应用"),

//SHOW_MANAGE("L","SHOW_MANAGE","秀场管理");

function currentTimeMillis() {

list($t1, $t2) = explode(' ', microtime());

return (float)sprintf('%.0f',(floatval($t1)+floatval($t2))*1000);

}

function base64UrlEncode($input){

return str_replace('=', '', strtr(base64_encode($input), '+/', '-_'));

}

function base64UrlDecode($input){

$remainder = strlen($input) % 4;

if ($remainder) {

$addlen = 4 - $remainder;

$input .= str_repeat('=', $addlen);

}

return base64_decode(strtr($input, '-_', '+/'));

}

function getRandomString($length){

$tostr = "";

$pattern = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ";

$n = strlen($pattern);

for($i=0;$i< $length;$i++) {

$tostr .= $pattern{mt_rand(0, $n - 1)};

}

return $tostr;

}

function pareNToken($acc_token){

$resp = array();

$clientIp = "";

$CODE_MAP = array();

$acinfo = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,1,2,3,4,5,6,7,8,9,0,-,_,@,.";

$CODE_ARRAY = explode(",", $acinfo);

for($i=0;$i < count($CODE_ARRAY);$i++){

$CODE_MAP[$CODE_ARRAY[$i]] = $i;

}

$s = base64UrlDecode($acc_token);

$code = substr($s, 0, 1);

$token = substr($s, 1);

$token_lenth = strlen($token);

$accountLength = intval(substr($token, 0, 2));

$encryptAccount = substr($token, 2, 2 + $accountLength);

$keys = substr($token, $token_lenth - $accountLength);

$version_tm = substr($token, $token_lenth - 13);

$encryptLoginIp = substr($token, 2 + $accountLength, -13);

for ($i = 0; $i < strlen($encryptLoginIp); $i++) {

if (is_numeric($encryptLoginIp[$i])) {

$clientIp  .= $encryptLoginIp[$i];

} else {

$clientIp  .= ".";

}

}

$accountStr = "";

for ($i = 0; $i < strlen($encryptAccount); $i++) {

$a = $encryptAccount[$i];

if (isset($CODE_MAP[$a]) && isset($keys[$i]) && isset($CODE_MAP[$keys[$i]])){

$aIndex = $CODE_MAP[$a];

$keyValue = $CODE_MAP[$keys[$i]];

$bIndex = $aIndex + $keyValue;

if($bIndex >= count($CODE_MAP)){

$bIndex = $bIndex - count($CODE_MAP);

}

$accountStr .= $CODE_ARRAY[$bIndex];

} else {

$accountStr .= $a;

}

}

$softwareVersion = substr($accountStr, strrpos($accountStr, "@") + 1);

$accountStr = substr($accountStr, 0, strrpos($accountStr, "@"));

$softwareCode = substr($accountStr, strrpos($accountStr, "@") + 1);

$accountStr = substr($accountStr, 0, strrpos($accountStr, "@"));

$resp['client_ip'] =  $clientIp;

$resp['version'] =  $version_tm;

$resp['account'] =  $accountStr;

$resp['software_code'] =  $softwareCode;

$resp['software_version'] =  $softwareVersion;

$resp['token'] =  $acc_token;

return $resp;

}

function getNToken($clientIp = "127.0.0.1", $account = "132020005012", $softwareCode = "SUNTV", $softwareVersion = "0.4.89", $prefix = "O"){

$ipbuf = array();

$CODE_MAP = array();

$acinfo = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,1,2,3,4,5,6,7,8,9,0,-,_,@,.";

$CODE_ARRAY = explode(",", $acinfo);

for($i=0;$i < count($CODE_ARRAY);$i++){

$CODE_MAP[$CODE_ARRAY[$i]] = $i;

}

$accountStr = $account."@".$softwareCode."@".$softwareVersion;

for($i=0;$i < strlen($clientIp);$i++){

if ("." == $clientIp[$i]){

$ipbuf[]= chr(rand(97, 122));

} else {

$ipbuf[] = $clientIp[$i];

}

}

$tm = currentTimeMillis();

$clientIp = join("", $ipbuf);

$suffix = $clientIp.$tm;

$accountLength = strlen($accountStr);

if($accountLength > strlen($suffix)){

$cLength = $accountLength - strlen($suffix);

$suffix = getRandomString($cLength) . $suffix;

}

$tokenbuf = "";

if($accountLength < 10){

$tokenbuf = $prefix."0".$accountLength;

} else {

$tokenbuf = $prefix.$accountLength;

}

$keys = substr($suffix, strlen($suffix) - $accountLength);

for ($i = 0; $i < strlen($accountStr); $i++) {

$a = $accountStr[$i];

if (isset($CODE_MAP[$a]) && isset($keys[$i]) && isset($CODE_MAP[$keys[$i]])){

$aIndex = $CODE_MAP[$a];

$keyValue = $CODE_MAP[$keys[$i]];

$bIndex = 0;

if($aIndex >= $keyValue){

$bIndex = $aIndex - $keyValue;

} else {

$bIndex = count($CODE_ARRAY) + $aIndex - $keyValue;

}

$tokenbuf .= $CODE_ARRAY[$bIndex];

} else {

$tokenbuf .= $a;

}

}

$tokenbuf .= $suffix;

return base64UrlEncode($tokenbuf);

}

function userip()

{

$ip=false;

if(!empty($_SERVER["HTTP_CLIENT_IP"])){

$ip = $_SERVER["HTTP_CLIENT_IP"];

}

if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {

$ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']);

if ($ip) { array_unshift($ips, $ip); $ip = FALSE; }

for ($i = 0; $i < count($ips); $i++) {

if (!eregi ("^(10│172.16│192.168).", $ips[$i])) {

$ip = $ips[$i];

break;

}

}

}

return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);

}

$uidlist = ["142029001763","142029001915","142029001916","142029001976"];

$rand_keys = array_rand($uidlist);

$access_token = getNToken(userip(), $uidlist[$rand_keys]);

$stype = empty($_GET['type']) ? "ipsd" : trim($_GET['type']);

$channel = empty($_GET['channel']) ? "CCTV1HD" : trim($_GET['channel']);

$strUrl = sprintf("http://stream.suntv.tvmining.com/approve/live?channel=%s&type=%s&access_token=%s", $channel, $stype, $access_token);

echo $strUrl;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值