123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- <?php
- namespace xiaohongwu;
- use DOMDocument;
- class Vr
- {
- /**
- * 获取vr详情
- */
- public function info($url)
- {
- $url = urldecode($url);
- if (preg_match('/kujiale/', $url)) {
- $type = 'kujiale';
- } elseif (preg_match('/xiaohongwu/', $url)) {
- $type = 'xiaohongwu';
- } elseif (preg_match('/justeasy/', $url)) {
- $type = 'justeasy';
- } elseif (preg_match('/panorama/', $url)) {
- $type = 'panorama';
- } elseif (preg_match('/zqxg/', $url)) {
- $type = 'panorama';
- } else {
- trace('vr地址不支持:' . $url, 'error');
- return [];
- }
- $metod = $type . 'Info';
- return $this->$metod($url);
- }
- /**
- * 获取vr第一张图片
- */
- public function getFirstImg($url)
- {
- $rs = $this->info($url);
- if (empty($rs)) return '';
- return $rs['first_img'];
- }
- /**
- * 小红屋获取vr详情
- */
- public function xiaohongwuInfo($url)
- {
- $pattern = '/p=([-\w]*)/';
- preg_match($pattern, $url, $param);
- if (empty($param)) {
- trace($url, 'error');
- return [];
- }
- $requestUrl = 'https://web.xiaohongwu.com/BASEURL/hozo-album/api/album/info';
- $postData = ['origin' => 1, 'parameter' => $param[1]];
- $rs = $this->curl($requestUrl, $postData);
- $rs = json_decode($rs, true);
- if ($rs['success'] != true) {
- trace($rs, 'error');
- return [];
- }
- $colId = $rs['params']['albumInfo']['id'];
- $ids = [];
- foreach ($rs['params']['albumInfo']['categoryList'] as $item) {
- $ids[] = $item['id'];
- }
- $colId = $rs['params']['albumInfo']['id'];
- // 获取id信息
- $url = 'https://web.xiaohongwu.com/BASEURL/hozo-album/api/album/pic/category/info';
- $postData = ['colId' => $colId, 'ids' => $ids];
- $rs = $this->curl($url, $postData);
- $rs = json_decode($rs, true);
- if ($rs['success'] != true) {
- trace($rs, 'error');
- return [];
- }
- if (!isset($rs['params'][0]['pictureList'][0]['thumbUrl']) || empty($rs['params'][0]['pictureList'][0]['thumbUrl'])) return [];
- return [
- 'first_img' => $rs['params'][0]['pictureList'][0]['thumbUrl'],
- 'info' => $rs
- ];
- }
- /**
- * 酷家乐获取VR详情
- */
- public function kujialeInfo($url)
- {
- //$pattern = '/(?:pano|display|design)\/([\w]*)/';
- $pattern = '/(?:pano|display|design)\/([\w]*)\/([\w]*)/';
- preg_match($pattern, $url, $param);
- if (empty($param)) {
- trace($url, 'error');
- return [];
- }
- if (strstr($param[0], 'design')) {
- //$requestUrl = 'https://pano337.p.kujiale.com/api/page/cloud/design/' . $param[1] . '/show/v2?timestamp=' . round(microtime(true) * 1000);
- $requestUrl = 'https://pano337.p.kujiale.com/api/page/cloud/design/' . $param[1] . '/'.$param[2].'/v2?with_config=true×tamp=' . round(microtime(true) * 1000);
- } else {
- $requestUrl = 'https://pano337.p.kujiale.com/api/page/xiaoguotu/pano/' . $param[1] . '/v2?timestamp=' . round(microtime(true) * 1000);
- }
- $rs = $this->curl($requestUrl);
- $rs = json_decode($rs, true);
- return [
- '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'] : ''),
- 'info' => $rs
- ];
- }
- /**
- * 建E全景
- */
- public function justeasyInfo($url)
- {
- $content = file_get_contents($url);
- if ($content === false) {
- trace('vr图片获取失败,地址:' . $url, 'debug');
- return ['first_img' => '', 'info' => []];
- }
- $info = [];
- // create new DOMDocument
- // $document = new DOMDocument('1.0', 'UTF-8');
- // $internalErrors = libxml_use_internal_errors(true);
- // $document->loadHTML($content);
- // libxml_use_internal_errors($internalErrors);
- // // 获取title
- // $titleDom = $document->getElementsByTagName('title');
- // $info['title'] = $titleDom->item(0)->textContent;
- // // 获取关键字和描述
- // $meta = $document->getElementsByTagName('meta');
- // $xm = ['keywords', 'description'];
- // foreach ($meta as $searchNode) {
- // $name = $searchNode->getAttribute('name');
- // if (in_array($name, $xm)) $info[$name] = $searchNode->getAttribute('content');
- // }
- // 正则匹配 获取封面图
- if (!preg_match("/\"preview\":\"([\w|\\\\|\/|\-|\.]*)\"/", $content, $match))
- return ['first_img' => '', 'info' => $info];
- $firstImg = str_replace('\/', '/', $match[1]);
- return ['first_img' => 'https://vrimg.justeasy.cn/' . $firstImg, 'info' => $info];
- }
- /**
- * 屋联详情
- */
- public function panoramaInfo($url)
- {
- if (!preg_match("/tour\/(\w*)/", $url, $match)) {
- return ['first_img' => '', 'info' => []];
- }
- $requestUrl = 'https://panorama.wlwno1.com/api/work/workDetail';
- $rs = $this->curl($requestUrl, ['id' => $match[1]]);
- $info = json_decode($rs, true);
- return ['first_img' => $info['data']['base']['thumb_path'], 'info' => $info];
- }
- /**
- * 通过CURL发送HTTP请求
- * @param string $url //请求URL
- * @param array $postFields //请求参数
- * @return mixed
- *
- */
- private function curl($url, $postFields = [])
- {
- // 创建一个 cURL 句柄
- $ch = curl_init();
- $header = ['Content-Type: application/json'];
- // 设置 cURL 句柄的选项
- curl_setopt($ch, CURLOPT_URL, $url);
- if (!empty($postFields)) {
- $json_data = json_encode($postFields);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
- $header[] = 'Content-Length: ' . strlen($json_data);
- }
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- // 执行 cURL 请求
- $ret = curl_exec($ch);
- if (false == $ret) {
- $result = curl_error($ch);
- } else {
- $rsp = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- if (200 != $rsp) {
- $result = "请求状态 " . $rsp . " " . curl_error($ch);
- } else {
- $result = $ret;
- }
- }
- curl_close($ch);
- return $result;
- }
- }
|