GetInfo.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\utils;
  8. class GetInfo
  9. {
  10. //通过vid参数换取源地址
  11. public static function getVideoInfo($url){
  12. preg_match("/\/([0-9a-zA-Z]+).html/", $url, $vids);
  13. if(empty($vids) || !is_array($vids)){
  14. return [
  15. 'code' => 0,
  16. 'msg' => 'success',
  17. 'url' => $url
  18. ];
  19. }
  20. $getUrl = 'https://h5vv.video.qq.com/getinfo?';
  21. $realUrl = 'http://ugcws.video.gtimg.com/%s?vkey=%s&br=56&platform=2&fmt=auto&level=0&sdtfrom=v5010&guid=a3527bbc8888951591bc3a67c2bc9c50';
  22. $newVideo = array();
  23. foreach($vids as $key => $value){
  24. if(!empty($value) && $key == 1){
  25. $vid = $value;
  26. //获取真正的视频源地址
  27. $data = array(
  28. 'platform' => 11001,
  29. 'charge' => 0,
  30. 'otype' => 'json',
  31. 'ehost' => 'https://v.qq.com',
  32. 'sphls' => 1,
  33. 'sb' => 1,
  34. 'nocache' => 0,
  35. '_rnd' => time(),
  36. 'guid' => 'a3527bbc8888951591bc3a67c2bc9c50',
  37. 'appVer' => 'V2.0Build9496',
  38. 'vids' => $vid,
  39. 'defaultfmt' => 'auto',
  40. '_qv_rmt' => 'jJPtBTyoA12993HPU=',
  41. '_qv_rmt2' => 'pS3QdOqZ150285Jdg=',
  42. 'sdtfrom' => 'v5010'
  43. );
  44. $result = self::http_get($getUrl.http_build_query($data));
  45. if(!empty($result)){
  46. $result = explode('=', $result);
  47. if(!empty($result) && !empty($result[1])){
  48. $json = substr($result[1], 0, strlen($result[1])-1);
  49. $json = json_decode($json, true);
  50. if(json_last_error() == 'JSON_ERROR_NONE'){
  51. if(!empty($json['vl']['vi'][0]['fn']) && !empty($json['vl']['vi'][0]['fvkey'])){
  52. $fn = $json['vl']['vi'][0]['fn'];
  53. $fvkey = $json['vl']['vi'][0]['fvkey'];
  54. $returnUrl = sprintf($realUrl, $fn, $fvkey);
  55. $newVideo['url'] = $returnUrl;
  56. }
  57. }
  58. }
  59. }
  60. }
  61. }
  62. return [
  63. 'code' => 0,
  64. 'msg' => 'success',
  65. 'url' => $newVideo['url']
  66. ];
  67. }
  68. public static function http_get($url) {
  69. $oCurl = curl_init ();
  70. if (stripos ( $url, "https://" ) !== FALSE) {
  71. curl_setopt ( $oCurl, CURLOPT_SSL_VERIFYPEER, FALSE );
  72. curl_setopt ( $oCurl, CURLOPT_SSL_VERIFYHOST, FALSE );
  73. }
  74. curl_setopt ( $oCurl, CURLOPT_URL, $url );
  75. curl_setopt ( $oCurl, CURLOPT_RETURNTRANSFER, 1 );
  76. $sContent = curl_exec ( $oCurl );
  77. $aStatus = curl_getinfo ( $oCurl );
  78. curl_close ( $oCurl );
  79. if (intval ( $aStatus ["http_code"] ) == 200) {
  80. return $sContent;
  81. } else {
  82. return false;
  83. }
  84. }
  85. }