2021-10-07

此处仅作记录。

 

 

<?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);
}

$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;

 

懂的人一看即止。不多说了。 以上代码保存成tvm.php  调用方式  tvm.php?channel=CCTV1HD

 

 

打赏

好文章,更需要你的鼓励

本文由 氢设计 创作,除注明转载/出处外,均为本站原创,转载前请务必署名

最后编辑时间为:2021-11-23 10:21:01

本文链接:https://www.h2sheji.com/show-98.html