找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 5080|回复: 5

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

[复制链接]
  1. <?php
  2. //ANONYMOUS("N","ANONYMOUS","匿名"),
  3. //STB("O","STB","运营版机顶盒"),
  4. //GESTB("Q","GESTB","通用版机顶盒"),
  5. //MT("R","MT","移动应用"),
  6. //WEIXIN("K","WEIXIN","微信应用"),
  7. //WEB("V","WEB","网页应用"),
  8. //PLUGIN("P","PLUGIN","插件应用"),
  9. //SHOW_MANAGE("L","SHOW_MANAGE","秀场管理");
  10. function currentTimeMillis() {
  11.         list($t1, $t2) = explode(' ', microtime());
  12.         return (float)sprintf('%.0f',(floatval($t1)+floatval($t2))*1000);
  13. }

  14. function base64UrlEncode($input){
  15.         return str_replace('=', '', strtr(base64_encode($input), '+/', '-_'));
  16. }

  17. function base64UrlDecode($input){
  18.         $remainder = strlen($input) % 4;
  19.         if ($remainder) {
  20.                 $addlen = 4 - $remainder;
  21.                 $input .= str_repeat('=', $addlen);
  22.         }
  23.         return base64_decode(strtr($input, '-_', '+/'));
  24. }

  25. function getRandomString($length){
  26.         $tostr = "";
  27.         $pattern = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ";
  28.         $n = strlen($pattern);
  29.         for($i=0;$i< $length;$i++) {
  30.                 $tostr .= $pattern{mt_rand(0, $n - 1)};
  31.         }
  32.         return $tostr;
  33. }

  34. function pareNToken($acc_token){
  35.         $resp = array();
  36.         $clientIp = "";
  37.         $CODE_MAP = array();
  38.         $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,-,_,@,.";
  39.         $CODE_ARRAY = explode(",", $acinfo);
  40.         for($i=0;$i < count($CODE_ARRAY);$i++){
  41.                 $CODE_MAP[$CODE_ARRAY[$i]] = $i;
  42.         }
  43.         $s = base64UrlDecode($acc_token);
  44.         $code = substr($s, 0, 1);
  45.         $token = substr($s, 1);
  46.         $token_lenth = strlen($token);
  47.         $accountLength = intval(substr($token, 0, 2));
  48.         $encryptAccount = substr($token, 2, 2 + $accountLength);
  49.         $keys = substr($token, $token_lenth - $accountLength);
  50.         $version_tm = substr($token, $token_lenth - 13);
  51.         $encryptLoginIp = substr($token, 2 + $accountLength, -13);
  52.         for ($i = 0; $i < strlen($encryptLoginIp); $i++) {
  53.                 if (is_numeric($encryptLoginIp[$i])) {
  54.                         $clientIp  .= $encryptLoginIp[$i];
  55.                 } else {
  56.                         $clientIp  .= ".";
  57.                 }
  58.         }
  59.         $accountStr = "";
  60.         for ($i = 0; $i < strlen($encryptAccount); $i++) {
  61.                 $a = $encryptAccount[$i];
  62.                 if (isset($CODE_MAP[$a]) && isset($keys[$i]) && isset($CODE_MAP[$keys[$i]])){
  63.                         $aIndex = $CODE_MAP[$a];
  64.                         $keyValue = $CODE_MAP[$keys[$i]];
  65.                         $bIndex = $aIndex + $keyValue;
  66.                         if($bIndex >= count($CODE_MAP)){
  67.                                 $bIndex = $bIndex - count($CODE_MAP);
  68.                         }
  69.                         $accountStr .= $CODE_ARRAY[$bIndex];
  70.                 } else {
  71.                         $accountStr .= $a;
  72.                 }
  73.         }
  74.         $softwareVersion = substr($accountStr, strrpos($accountStr, "@") + 1);
  75.         $accountStr = substr($accountStr, 0, strrpos($accountStr, "@"));
  76.         $softwareCode = substr($accountStr, strrpos($accountStr, "@") + 1);
  77.         $accountStr = substr($accountStr, 0, strrpos($accountStr, "@"));
  78.         $resp['client_ip'] =  $clientIp;
  79.         $resp['version'] =  $version_tm;
  80.         $resp['account'] =  $accountStr;
  81.         $resp['software_code'] =  $softwareCode;
  82.         $resp['software_version'] =  $softwareVersion;
  83.         $resp['token'] =  $acc_token;
  84.         return $resp;
  85. }

  86. function getNToken($clientIp = "127.0.0.1", $account = "132020005012", $softwareCode = "SUNTV", $softwareVersion = "0.4.89", $prefix = "O"){
  87.         $ipbuf = array();
  88.         $CODE_MAP = array();
  89.         $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,-,_,@,.";
  90.         $CODE_ARRAY = explode(",", $acinfo);
  91.         for($i=0;$i < count($CODE_ARRAY);$i++){
  92.                 $CODE_MAP[$CODE_ARRAY[$i]] = $i;
  93.         }
  94.         $accountStr = $account."@".$softwareCode."@".$softwareVersion;
  95.         for($i=0;$i < strlen($clientIp);$i++){
  96.                 if ("." == $clientIp[$i]){
  97.                         $ipbuf[]= chr(rand(97, 122));
  98.                 } else {
  99.                         $ipbuf[] = $clientIp[$i];
  100.                 }
  101.         }
  102.         $tm = currentTimeMillis();
  103.         $clientIp = join("", $ipbuf);
  104.         $suffix = $clientIp.$tm;
  105.         $accountLength = strlen($accountStr);
  106.         if($accountLength > strlen($suffix)){
  107.                 $cLength = $accountLength - strlen($suffix);
  108.                 $suffix = getRandomString($cLength) . $suffix;
  109.         }
  110.         $tokenbuf = "";
  111.         if($accountLength < 10){
  112.                 $tokenbuf = $prefix."0".$accountLength;
  113.         } else {
  114.                 $tokenbuf = $prefix.$accountLength;
  115.         }
  116.         $keys = substr($suffix, strlen($suffix) - $accountLength);
  117.         for ($i = 0; $i < strlen($accountStr); $i++) {
  118.                 $a = $accountStr[$i];
  119.                 if (isset($CODE_MAP[$a]) && isset($keys[$i]) && isset($CODE_MAP[$keys[$i]])){
  120.                         $aIndex = $CODE_MAP[$a];
  121.                         $keyValue = $CODE_MAP[$keys[$i]];
  122.                         $bIndex = 0;
  123.                         if($aIndex >= $keyValue){
  124.                                 $bIndex = $aIndex - $keyValue;
  125.                         } else {
  126.                                 $bIndex = count($CODE_ARRAY) + $aIndex - $keyValue;
  127.                         }
  128.                         $tokenbuf .= $CODE_ARRAY[$bIndex];
  129.                 } else {
  130.                         $tokenbuf .= $a;
  131.                 }
  132.         }
  133.         $tokenbuf .= $suffix;
  134.         return base64UrlEncode($tokenbuf);
  135. }
  136. function userip()
  137. {
  138.         $ip=false;
  139.         if(!empty($_SERVER["HTTP_CLIENT_IP"])){
  140.                 $ip = $_SERVER["HTTP_CLIENT_IP"];
  141.         }
  142.         if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  143.                 $ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
  144.                 if ($ip) { array_unshift($ips, $ip); $ip = FALSE; }
  145.                 for ($i = 0; $i < count($ips); $i++) {
  146.                         if (!eregi ("^(10│172.16│192.168).", $ips[$i])) {
  147.                                 $ip = $ips[$i];
  148.                                 break;
  149.                         }
  150.                 }
  151.         }
  152.         return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
  153. }
  154. $uidlist = ["142029001763","142029001915","142029001916","142029001976"];
  155. $rand_keys = array_rand($uidlist);
  156. $access_token = getNToken(userip(), $uidlist[$rand_keys]);
  157. $stype = empty($_GET['type']) ? "ipsd" : trim($_GET['type']);
  158. $channel = empty($_GET['channel']) ? "CCTV1HD" : trim($_GET['channel']);
  159. $strUrl = sprintf("http://stream.suntv.tvmining.com/approve/live?channel=%s&type=%s&access_token=%s", $channel, $stype, $access_token);
  160. echo $strUrl;
复制代码
懂的人一看即止。不多说了。 以上代码保存成tvm.php  调用方式  tvm.php?channel=CCTV1HD


把他原文中的代码所缺的函数补了下,现在能直接获取到地址了,但是这个获取到的地址不能打开,不知道要怎么用,有懂的大神能指点一二吗?还是说这个代码本身就只是片段,不完整?
我的恩山、我的无线 The best wifi forum is right here.
算法升级了

点评

有天脉新的源码吗  详情 回复 发表于 2020-3-11 19:02
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

有新的吗。。大神们。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

fb85800062 发表于 2019-5-29 08:26
我打开这个地址可以获取到连接 http://stream.suntv.tvmining.com/approve/live?channel=CCTV1HD&type=ipsd ...

你好,有新升级的代理吗。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报


有天脉新的源码吗
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

无论是静态还代理的好像都失效了,是不是改了算法
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

欢迎大家光临恩山无线论坛上一条 /1 下一条

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2024-4-29 13:58

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com 举报电话:0519-86695797

快速回复 返回顶部 返回列表