public function fetch() { $file = trim($_POST['file']); $type = isset($_REQUEST['name']) ? $_REQUEST['name'] : 'ad_url'; $id = isset($_REQUEST['id']) && $_REQUEST['id'] != '' && $_REQUEST['id'] != 'undefined' ? $_REQUEST['id'] : $this->create_id(); // 过滤不抓取的情况 if (preg_match('/itunes\\.apple\\.com/', $file)) { $this->output(array('code' => 1, 'msg' => '暂时不支持抓取iTunes内容,相关功能开发中。')); } $result = array('code' => 0, 'form' => array(), 'id' => $id); // 已经在我们的机器上了,直接分析 $path = $filename = ''; if (preg_match(LOCAL_FILE, $file)) { $result['msg'] = 'exist'; $path = preg_replace(LOCAL_FILE, '', $file); } else { try { $content = file_get_contents($file); if (!$content) { $this->exit_with_error(10, '抓取文件失败,可能是对方有防抓取功能。', 403); } $filename = $this->parse_filename($file, $http_response_header); $path = $this->get_file_path($type, $filename, $id); file_put_contents(UPLOAD_BASE . $path, $content); // 生成反馈 $result['msg'] = 'fetched'; } catch (Exception $e) { $this->exit_with_error(2, '找不到目标文件,无法完成抓取。', 404); } } // 记录到log里 $service = new FileLog(); $service->insert_fetch_log($id, $type, $path, $file, $filename); if (preg_match('/\\.apk$/i', $path)) { $package = $this->parse_apk($path); $result = array_merge($result, $package); } if (preg_match('/\\.ipa$/i', $path)) { $package = $this->parse_ipa($path); $result = array_merge($result, $package); } $result['form']['ad_url'] = UPLOAD_URL . $path; $result['form']['id'] = $id; $this->output($result); }
/** * 取某个广告的上传记录 * @param $id */ public function get_upload_history($id) { $ad = new AD(); if (!$ad->check_ad_owner($id)) { $this->exit_with_error(1, '这不是您的广告,您无法查看它的上传记录', 403); } $service = new FileLog(); $history = $service->get_ad_history($id); foreach ($history as &$log) { $log['url'] = UPLOAD_URL . $log['url']; } $this->output(array('code' => 0, 'msg' => 'get', 'list' => $history)); }