GetInfo.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\client\models\v1\diy;
  8. use tianxin100\wechat\DataTransform;
  9. class GetInfo
  10. {
  11. //获取视频播放地址
  12. public static function getVideoInfo1($url)
  13. {
  14. preg_match("/\/([0-9a-zA-Z]+).html/", $url, $match);
  15. if (empty($match)) {
  16. return [
  17. 'code' => 0,
  18. 'msg' => 'success',
  19. 'url' => $url
  20. ];
  21. }
  22. $vid = $match[1];//视频ID
  23. try {
  24. set_time_limit(0);
  25. $getinfo = "http://vv.video.qq.com/getinfo?vids={$vid}&platform=101001&charge=0&otype=xml";
  26. $info = self::http_get($getinfo);
  27. $info_arr = json_decode(json_encode(DataTransform::xmlToArray($info)), true);
  28. if (isset($info_arr['msg']) && $info_arr['msg'] == 'vid is wrong') {
  29. return [
  30. 'code' => 0,
  31. 'msg' => '视频出错',
  32. 'url' => $url
  33. ];
  34. }
  35. $filename = $info_arr['vl']['vi']['fn'];
  36. $key = $info_arr['vl']['vi']['fvkey'];
  37. $url = $info_arr['vl']['vi']['ul']['ui'][0]['url'];
  38. $video_url = $url . $filename . '?vkey=' . $key;
  39. // }
  40. return [
  41. 'code' => 0,
  42. 'msg' => 'success',
  43. 'url' => $video_url
  44. ];
  45. } catch (\Exception $e) {
  46. return [
  47. 'code' => 0,
  48. 'msg' => 'success',
  49. 'url' => $url
  50. ];
  51. }
  52. }
  53. //通过vid参数换取源地址
  54. public static function getVideoInfo($url){
  55. preg_match("/\/([0-9a-zA-Z]+).html/", $url, $vids);
  56. if(empty($vids) || !is_array($vids)){
  57. return [
  58. 'code' => 0,
  59. 'msg' => 'success',
  60. 'url' => $url
  61. ];
  62. }
  63. $getUrl = 'https://h5vv.video.qq.com/getinfo?';
  64. $realUrl = 'http://ugcws.video.gtimg.com/%s?vkey=%s&br=56&platform=2&fmt=auto&level=0&sdtfrom=v5010&guid=a3527bbc8888951591bc3a67c2bc9c50';
  65. $newVideo = array();
  66. foreach($vids as $key => $value){
  67. if(!empty($value) && $key == 1){
  68. $vid = $value;
  69. //获取真正的视频源地址
  70. $data = array(
  71. 'platform' => 11001,
  72. 'charge' => 0,
  73. 'otype' => 'json',
  74. 'ehost' => 'https://v.qq.com',
  75. 'sphls' => 1,
  76. 'sb' => 1,
  77. 'nocache' => 0,
  78. '_rnd' => time(),
  79. 'guid' => 'a3527bbc8888951591bc3a67c2bc9c50',
  80. 'appVer' => 'V2.0Build9496',
  81. 'vids' => $vid,
  82. 'defaultfmt' => 'auto',
  83. '_qv_rmt' => 'jJPtBTyoA12993HPU=',
  84. '_qv_rmt2' => 'pS3QdOqZ150285Jdg=',
  85. 'sdtfrom' => 'v5010'
  86. );
  87. $result = self::http_get($getUrl.http_build_query($data));
  88. if(!empty($result)){
  89. $result = explode('=', $result);
  90. if(!empty($result) && !empty($result[1])){
  91. $json = substr($result[1], 0, strlen($result[1])-1);
  92. $json = json_decode($json, true);
  93. if(json_last_error() == 'JSON_ERROR_NONE'){
  94. if(!empty($json['vl']['vi'][0]['fn']) && !empty($json['vl']['vi'][0]['fvkey'])){
  95. $fn = $json['vl']['vi'][0]['fn'];
  96. $fvkey = $json['vl']['vi'][0]['fvkey'];
  97. $returnUrl = sprintf($realUrl, $fn, $fvkey);
  98. $newVideo['url'] = $returnUrl;
  99. }
  100. }
  101. }
  102. }
  103. }
  104. }
  105. return [
  106. 'code' => 0,
  107. 'msg' => 'success',
  108. 'url' => $newVideo['url']
  109. ];
  110. }
  111. public static function http_get($url) {
  112. $oCurl = curl_init ();
  113. if (stripos ( $url, "https://" ) !== FALSE) {
  114. curl_setopt ( $oCurl, CURLOPT_SSL_VERIFYPEER, FALSE );
  115. curl_setopt ( $oCurl, CURLOPT_SSL_VERIFYHOST, FALSE );
  116. }
  117. curl_setopt ( $oCurl, CURLOPT_URL, $url );
  118. curl_setopt ( $oCurl, CURLOPT_RETURNTRANSFER, 1 );
  119. $sContent = curl_exec ( $oCurl );
  120. $aStatus = curl_getinfo ( $oCurl );
  121. curl_close ( $oCurl );
  122. if (intval ( $aStatus ["http_code"] ) == 200) {
  123. return $sContent;
  124. } else {
  125. return false;
  126. }
  127. }
  128. }