fork download
  1. <?php
  2. header('Content-Type:text/json;charset=UTF-8');
  3. $id = $_GET['id'];
  4. if (empty($_GET['id'])) $id = 'gdws';
  5. $n = [
  6. 'gdws' => 43, //广东卫视
  7. 'gdzj' => 44, //广东珠江
  8. 'gdxw' => 45, //广东新闻
  9. 'gdgg' => 48, //广东公共
  10. 'gdty' => 47, //广东体育
  11. 'nfws' => 51, //大湾区卫视
  12. 'jjkj' => 49, //经济科教
  13. 'gdys' => 53, //广东影视
  14. 'gdzy' => 16, //广东综艺
  15. 'gdgj' => 46, //广东国际
  16. 'gdse' => 54, //广东少儿
  17. 'jjkt' => 66, //嘉佳卡通
  18. 'nfgw' => 42, //南方购物
  19. 'lnxq' => 15, //岭南戏曲
  20. 'gdfc' => 67, //广东房产
  21. 'xdjy' => 13, //现代教育
  22. 'gdyd' => 74, //广东移动
  23. 'gdjk' => 99, //GRTN健康频道
  24. 'gdwh' => 75, //GRTN文化频道
  25. ];
  26.  
  27. $ts = time();
  28. $headers = [
  29. "referer: https://w...content-available-to-author-only...v.cn/",
  30. "origin: https://w...content-available-to-author-only...v.cn",
  31. "user-agent: Mozilla/5.0 (Windows NT 10.0; WOW64",
  32. "x-itouchtv-ca-key: 89541443007807288657755311869534",
  33. "x-itouchtv-ca-timestamp: $ts",
  34. "x-itouchtv-client: WEB_PC",
  35. "x-itouchtv-device-id: WEB_0"
  36. ];
  37.  
  38. $bstrURL = "https://t...content-available-to-author-only...v.cn/getParam";
  39. $sign = base64_encode(hash_hmac("SHA256","GET\n$bstrURL\n$ts\n","dfkcY1c3sfuw0Cii9DWjOUO3iQy2hqlDxyvDXd1oVMxwYAJSgeB6phO8eW1dfuwX",true));
  40. $headers[] = "x-itouchtv-ca-signature: $sign";
  41.  
  42. $ch = curl_init($bstrURL);
  43. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  44. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  45. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  46. curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
  47. $data = curl_exec($ch);
  48. $json = json_decode($data);
  49. $node = $json -> node;
  50.  
  51. // 进入wss取串
  52. $contextOptions = ['ssl' => ["verify_peer"=>false,"verify_peer_name"=>false]];
  53. $context = stream_context_create($contextOptions);
  54. $sock = stream_socket_client("ssl://tcdn-ws.itouchtv.cn:3800",$errno,$errstr,1,STREAM_CLIENT_CONNECT,$context);
  55. $wssData = json_encode(['route' => 'getwsparam','message' => $node]);
  56.  
  57. $key = base64_encode(substr(md5(mt_rand(1,999)),0,16));
  58. $header .= "GET /connect HTTP/1.1\r\n";
  59. $header .= "Host: tcdn-ws.itouchtv.cn:3800\r\n";
  60. $header .= "Upgrade: websocket\r\n";
  61. $header .= "Sec-WebSocket-Key: $key\r\n";
  62. fwrite($sock,$header."\r\n");
  63. $handshake = stream_get_contents($sock);
  64. if(strstr($handshake,'Sec-Websocket-Accept')) {
  65. fwrite($sock, encode($wssData));
  66. $param = stream_get_contents($sock);
  67. $param = substr($param,4);
  68. $json =json_decode($param);
  69. $wsnode = $json->wsnode;
  70. }
  71. // wss 取串结束.
  72.  
  73. $bstrURL = "https://g...content-available-to-author-only...v.cn/api/tv/v2/tvChannel/$n[$id]?tvChannelPk=$n[$id]&node=".base64_encode($wsnode);
  74. $sign = base64_encode(hash_hmac("SHA256","GET\n$bstrURL\n$ts\n","dfkcY1c3sfuw0Cii9DWjOUO3iQy2hqlDxyvDXd1oVMxwYAJSgeB6phO8eW1dfuwX",true));
  75.  
  76. $ch = curl_init($bstrURL);
  77. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "OPTIONS");
  78. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  79. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  80. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  81. curl_setopt($ch, CURLOPT_HTTPHEADER,["referer: https://w...content-available-to-author-only...v.cn"]);
  82. $data = curl_exec($ch);
  83.  
  84. array_pop($headers);
  85. $headers[] = "x-itouchtv-ca-signature: $sign";
  86.  
  87. $ch = curl_init($bstrURL);
  88. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  89. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  90. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  91. curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
  92. $data = curl_exec($ch);
  93. $json = json_decode($data);
  94. $playURL = json_decode($json -> playUrl) -> hd;
  95.  
  96. // m3u8加referer校验。
  97. $ch = curl_init($playURL);
  98. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  99. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  100. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  101. curl_setopt($ch, CURLOPT_HTTPHEADER,["Referer: https://w...content-available-to-author-only...v.cn"]);
  102. $data = curl_exec($ch);
  103. print_r($data);
  104.  
  105. function encode($data) {
  106. $len = strlen($data);
  107. $head[0] = 129;
  108. $mask = [];
  109. for ($j = 0; $j < 4; $j ++) {
  110. $mask[] = mt_rand(1, 128);
  111. }
  112. $split = str_split(sprintf('%016b', $len), 8);
  113. $head[1] = 254;
  114. $head[2] = bindec($split[0]);
  115. $head[3] = bindec($split[1]);
  116. $head = array_merge($head, $mask);
  117. foreach ($head as $k => $v) {
  118. $head[$k] = chr($v);
  119. }
  120. $mask_data = '';
  121. for ($j = 0; $j < $len; $j ++) {
  122. $mask_data .= chr(ord($data[$j]) ^ $mask[$j % 4]);
  123. }
  124. return implode('', $head).$mask_data;
  125. }
  126.  
  127. ?>
Success #stdin #stdout 0.03s 26624KB
stdin
Standard input is empty
stdout
Standard output is empty