1
0

Vr.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. namespace xiaohongwu;
  3. use DOMDocument;
  4. class Vr
  5. {
  6. /**
  7. * 获取vr详情
  8. */
  9. public function info($url)
  10. {
  11. $url = urldecode($url);
  12. if (preg_match('/kujiale/', $url)) {
  13. $type = 'kujiale';
  14. } elseif (preg_match('/xiaohongwu/', $url)) {
  15. $type = 'xiaohongwu';
  16. } elseif (preg_match('/justeasy/', $url)) {
  17. $type = 'justeasy';
  18. } elseif (preg_match('/panorama/', $url)) {
  19. $type = 'panorama';
  20. } elseif (preg_match('/zqxg/', $url)) {
  21. $type = 'panorama';
  22. } else {
  23. trace('vr地址不支持:' . $url, 'error');
  24. return [];
  25. }
  26. $metod = $type . 'Info';
  27. return $this->$metod($url);
  28. }
  29. /**
  30. * 获取vr第一张图片
  31. */
  32. public function getFirstImg($url)
  33. {
  34. $rs = $this->info($url);
  35. if (empty($rs)) return '';
  36. return $rs['first_img'];
  37. }
  38. /**
  39. * 小红屋获取vr详情
  40. */
  41. public function xiaohongwuInfo($url)
  42. {
  43. $pattern = '/p=([-\w]*)/';
  44. preg_match($pattern, $url, $param);
  45. if (empty($param)) {
  46. trace($url, 'error');
  47. return [];
  48. }
  49. $requestUrl = 'https://web.xiaohongwu.com/BASEURL/hozo-album/api/album/info';
  50. $postData = ['origin' => 1, 'parameter' => $param[1]];
  51. $rs = $this->curl($requestUrl, $postData);
  52. $rs = json_decode($rs, true);
  53. if ($rs['success'] != true) {
  54. trace($rs, 'error');
  55. return [];
  56. }
  57. $colId = $rs['params']['albumInfo']['id'];
  58. $ids = [];
  59. foreach ($rs['params']['albumInfo']['categoryList'] as $item) {
  60. $ids[] = $item['id'];
  61. }
  62. $colId = $rs['params']['albumInfo']['id'];
  63. // 获取id信息
  64. $url = 'https://web.xiaohongwu.com/BASEURL/hozo-album/api/album/pic/category/info';
  65. $postData = ['colId' => $colId, 'ids' => $ids];
  66. $rs = $this->curl($url, $postData);
  67. $rs = json_decode($rs, true);
  68. if ($rs['success'] != true) {
  69. trace($rs, 'error');
  70. return [];
  71. }
  72. if (!isset($rs['params'][0]['pictureList'][0]['thumbUrl']) || empty($rs['params'][0]['pictureList'][0]['thumbUrl'])) return [];
  73. return [
  74. 'first_img' => $rs['params'][0]['pictureList'][0]['thumbUrl'],
  75. 'info' => $rs
  76. ];
  77. }
  78. /**
  79. * 酷家乐获取VR详情
  80. */
  81. public function kujialeInfo($url)
  82. {
  83. //$pattern = '/(?:pano|display|design)\/([\w]*)/';
  84. $pattern = '/(?:pano|display|design)\/([\w]*)\/([\w]*)/';
  85. preg_match($pattern, $url, $param);
  86. if (empty($param)) {
  87. trace($url, 'error');
  88. return [];
  89. }
  90. if (strstr($param[0], 'design')) {
  91. //$requestUrl = 'https://pano337.p.kujiale.com/api/page/cloud/design/' . $param[1] . '/show/v2?timestamp=' . round(microtime(true) * 1000);
  92. $requestUrl = 'https://pano337.p.kujiale.com/api/page/cloud/design/' . $param[1] . '/'.$param[2].'/v2?with_config=true&timestamp=' . round(microtime(true) * 1000);
  93. } else {
  94. $requestUrl = 'https://pano337.p.kujiale.com/api/page/xiaoguotu/pano/' . $param[1] . '/v2?timestamp=' . round(microtime(true) * 1000);
  95. }
  96. $rs = $this->curl($requestUrl);
  97. $rs = json_decode($rs, true);
  98. return [
  99. 'first_img' => str_replace('%s', 'f?x-oss-process=image/resize,w_256', !empty($rs['panoJson']['panoSnenes'][0]['image']['cube']['url']) ? $rs['panoJson']['panoSnenes'][0]['image']['cube']['url'] : ''),
  100. 'info' => $rs
  101. ];
  102. }
  103. /**
  104. * 建E全景
  105. */
  106. public function justeasyInfo($url)
  107. {
  108. $content = file_get_contents($url);
  109. if ($content === false) {
  110. trace('vr图片获取失败,地址:' . $url, 'debug');
  111. return ['first_img' => '', 'info' => []];
  112. }
  113. $info = [];
  114. // create new DOMDocument
  115. // $document = new DOMDocument('1.0', 'UTF-8');
  116. // $internalErrors = libxml_use_internal_errors(true);
  117. // $document->loadHTML($content);
  118. // libxml_use_internal_errors($internalErrors);
  119. // // 获取title
  120. // $titleDom = $document->getElementsByTagName('title');
  121. // $info['title'] = $titleDom->item(0)->textContent;
  122. // // 获取关键字和描述
  123. // $meta = $document->getElementsByTagName('meta');
  124. // $xm = ['keywords', 'description'];
  125. // foreach ($meta as $searchNode) {
  126. // $name = $searchNode->getAttribute('name');
  127. // if (in_array($name, $xm)) $info[$name] = $searchNode->getAttribute('content');
  128. // }
  129. // 正则匹配 获取封面图
  130. if (!preg_match("/\"preview\":\"([\w|\\\\|\/|\-|\.]*)\"/", $content, $match))
  131. return ['first_img' => '', 'info' => $info];
  132. $firstImg = str_replace('\/', '/', $match[1]);
  133. return ['first_img' => 'https://vrimg.justeasy.cn/' . $firstImg, 'info' => $info];
  134. }
  135. /**
  136. * 屋联详情
  137. */
  138. public function panoramaInfo($url)
  139. {
  140. if (!preg_match("/tour\/(\w*)/", $url, $match)) {
  141. return ['first_img' => '', 'info' => []];
  142. }
  143. $requestUrl = 'https://panorama.wlwno1.com/api/work/workDetail';
  144. $rs = $this->curl($requestUrl, ['id' => $match[1]]);
  145. $info = json_decode($rs, true);
  146. return ['first_img' => $info['data']['base']['thumb_path'], 'info' => $info];
  147. }
  148. /**
  149. * 通过CURL发送HTTP请求
  150. * @param string $url //请求URL
  151. * @param array $postFields //请求参数
  152. * @return mixed
  153. *
  154. */
  155. private function curl($url, $postFields = [])
  156. {
  157. // 创建一个 cURL 句柄
  158. $ch = curl_init();
  159. $header = ['Content-Type: application/json'];
  160. // 设置 cURL 句柄的选项
  161. curl_setopt($ch, CURLOPT_URL, $url);
  162. if (!empty($postFields)) {
  163. $json_data = json_encode($postFields);
  164. curl_setopt($ch, CURLOPT_POST, true);
  165. curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
  166. $header[] = 'Content-Length: ' . strlen($json_data);
  167. }
  168. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  169. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  170. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  171. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  172. // 执行 cURL 请求
  173. $ret = curl_exec($ch);
  174. if (false == $ret) {
  175. $result = curl_error($ch);
  176. } else {
  177. $rsp = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  178. if (200 != $rsp) {
  179. $result = "请求状态 " . $rsp . " " . curl_error($ch);
  180. } else {
  181. $result = $ret;
  182. }
  183. }
  184. curl_close($ch);
  185. return $result;
  186. }
  187. }