Advertisement
Guest User

api.php

a guest
May 27th, 2015
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.86 KB | None | 0 0
  1. <?php
  2. header('Content-Type: text/html;charset=utf-8');
  3. function ip() {
  4. if(!empty($_SERVER['HTTP_CLIENT_IP']))
  5. {
  6. $ip = $_SERVER['HTTP_CLIENT_IP'];
  7. }
  8. elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
  9. {
  10. $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  11. }
  12. else
  13. {
  14. $ip = $_SERVER['REMOTE_ADDR'];
  15. }
  16. return $ip;
  17. }
  18. class tw_api_tv
  19. {
  20.  
  21. private function GetData($url){
  22.  
  23. $curl = curl_init();
  24. $headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
  25. $headers[] = 'Accept-Language: en-us,en;q=0.5';
  26. $headers[] = 'Accept-Charset: utf-8';
  27. $headers[] = 'Keep-Alive: 300';
  28. $headers[] = 'Connection: Keep-Alive';
  29. $headers[] = 'X-Forwarded-For: ' . $this->ip();
  30. curl_setopt($curl, CURLOPT_USERAGENT, 'android 4.2');
  31. curl_setopt($curl, CURLOPT_HEADER, 0);
  32. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  33. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  34. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);
  35. curl_setopt($curl, CURLOPT_TIMEOUT, 120);
  36. curl_setopt($curl, CURLOPT_URL, $url);
  37. $html = curl_exec($curl);
  38. curl_close($curl);
  39. return $html;
  40. }
  41.  
  42. public function hplus($channel){
  43.  
  44. $html = $this->GetData($channel);
  45. preg_match('/var iosUrl = "(.*?)";/is', $html, $stream);
  46. return $stream[1];
  47. }
  48. }
  49. class MyTv{
  50. var $cookie = "";
  51. var $ua = "";
  52. protected function getData($url, $param = array(), $method = "GET"){
  53. $headers = array(
  54. "Content-Type: application/x-www-form-urlencoded",
  55. "X-Forwarded-For: " . ip()
  56. );
  57. $strParam = "";
  58. if (count($param) > 0){
  59. ksort($param);
  60. $strParam = http_build_query($param);
  61. if ($method == "GET"){
  62. $url = $url . "?" . $strParam;
  63. }
  64. }
  65. $ch = curl_init();
  66. curl_setopt($ch, CURLOPT_URL, $url);
  67. curl_setopt($ch, CURLOPT_HEADER, 0);
  68. curl_setopt($ch, CURLOPT_USERAGENT, $this->ua);
  69. curl_setopt($ch, CURLOPT_COOKIE, $this->cookie );
  70. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  71. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,1);
  72. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  73. curl_setopt($ch, CURLOPT_REFERER, $url);
  74. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  75. if ($method == 'POST') {
  76. curl_setopt($ch, CURLOPT_POST, 1);
  77. curl_setopt($ch, CURLOPT_POSTFIELDS, $strParam);
  78. }
  79. $data = curl_exec($ch);
  80. return $data;
  81. }
  82. public function getLiveTvStreamWeb($arrayParam = array())
  83. {
  84. $param = array(
  85. '_f' => 6666,
  86. 'c' => $arrayParam['channel'],
  87. 'q' => 'high',
  88. 'type' => 'tv'
  89. );
  90. $this->cookie = 'ojid=UryGHmUCni0KfiuwTUS2zetq|QZcIptDEA4Rd4pyY3E3/dFY1popsaEQ78Xq|s70aABiFDADkev|JeZa8Bb6XmGZxcARngxI6zUm8aGGC0R8oSbZBy50Wrqrp9AGVynh5uoV3|MoOh/HcmriPkkID9G83dMw/zFil9|EE6CDH0vPYWCO8eduGqFiYvGXbYjucmtuKAK2i1PAn4F65LzpdNER3K38l8pkszof8nuybqE=';
  91. $this->ua = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36";
  92. $url = "http://truelife.vn/offica/resourcesubcription/action";
  93. $data = $this->getData($url , $param , "GET");
  94. $data = json_decode($data, true);
  95. $url = 'http://123.29.68.44/live.m3u8?c='.$param['c'].'&q='.$param['q'].'&type=tv&token='.$data['object'][0]['token'].'&from=vuappcdn&time='.$data['object'][0]['time'];
  96. return $url;
  97. }
  98. }
  99. $ref = $_SERVER['HTTP_REFERER'];
  100. $check = parse_url($ref);
  101. $host = empty($check['host']) ? 'direct' : (string)$check['host'];
  102. $allow = array('depvcc.net', 'thucdem.mobi', 'template');
  103. $ip_allow = array('123.31.12.59');
  104. $ips = explode(',', ip());
  105. $block = true;
  106. foreach($ips as $ip){
  107. if(in_array($ip, $ip_allow))
  108. $block = false;
  109. }
  110. if($block){
  111. echo $_GET['callback'] . '(' . json_encode(array('status' => 'error', 'message' => 'Địa chỉ ' . $host.' không được đăng kí')) . ');';
  112. }
  113. elseif(in_array($host, $allow)){
  114. if($_REQUEST['server'] == 'mytv'){
  115. $api = new MyTv();
  116. $stream = $api->getLiveTvStreamWeb(array('channel' => 'vstv' . $_REQUEST['channel']));
  117. }
  118. else
  119. {
  120. $api = new tw_api_tv();
  121. $channel = urldecode($_REQUEST['channel']);
  122. $stream = $api->hplus($channel);
  123. }
  124. $data['stream'] = $stream;
  125. $data['status'] = 'success';
  126. echo $_GET['callback'] . '(' . json_encode($data) . ');';
  127. }
  128. else
  129. echo $_GET['callback'] . '(' . json_encode(array('status' => 'error', 'message' => 'Địa chỉ ' . $host.' không được đăng kí')) . ');';
  130. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement