public function getList()
 {
     if (!extension_loaded('curl')) {
         $this->error('糗事百科插件需要开启PHP的CURL扩展');
     }
     $lists = S('QiuBai_content');
     if (!$lists) {
         $config = \Common\Controller\Addon::getConfig('QiuBai');
         $content = \Org\Net\Http::fsockopenDownload('http://www.qiushibaike.com');
         if ($content) {
             $regex = "/<div class=\"content\".*?>.*?--(.*?)--.*?<\\/div>/ism";
             preg_match_all($regex, $content, $match);
             $lists = array_map(function ($a, $b) {
                 return array('time' => time_format($a), 'content' => $b);
             }, $match[1], $match[0]);
             S('QiuBai_content', $lists, $config['cache_time']);
         }
     }
     if ($lists) {
         $this->success('成功', '', array('data' => $lists));
     } else {
         $this->error('获取糗事百科列表失败');
     }
     $this->assign('qiubai_list', $lists);
 }
Example #2
0
 public function downfile($url)
 {
     $path = C('TEMP_PATH');
     $name = md5($url) . '.jpg';
     $path = $path . $name;
     Http::curlDownload($url, $path);
     $info['name'] = $name;
     $info['type'] = 'image/jpeg';
     $info['tmp_name'] = $path;
     $info["error"] = 0;
     $data['temp_image'] = $info;
     $Picture = D('Picture');
     $pic_driver = C('PICTURE_UPLOAD_DRIVER');
     $info = $Picture->upload($data, C('VIDEO_PICTURE_UPLOAD'), C('PICTURE_UPLOAD_DRIVER'), C("UPLOAD_{$pic_driver}_CONFIG"));
     if ($info) {
         $return['status'] = 1;
         $return = array_merge($info, $return);
     } else {
         $return['status'] = 0;
         $return['info'] = $Picture->getError();
     }
     if (file_exists($path)) {
         unlink($myfile);
     }
     return $return;
 }
 public function down()
 {
     $aid = I('get.attach_id');
     $attach = D('Attach/Attach')->find($aid);
     if (!$attach) {
         die(L('PUBLIC_ATTACH_ISNULL'));
     }
     $filename = $attach['filepath'] . $attach['savename'];
     $realname = auto_charset($attach['name'], 'UTF-8', 'GBK//IGNORE');
     if (file_exists($filename)) {
         Http::download($filename, $realname);
     } else {
         die(L('PUBLIC_ATTACH_ISNULL'));
     }
 }
 /**
  * 检查新版本
  * @author jry <*****@*****.**>
  */
 public function checkVersion()
 {
     //远程更新地址
     $url = C('WEBSITE_DOMAIN') . C('UPDATE_URL') . '.html?action=check';
     //参数设置
     $params = array('product_name' => C('PRODUCT_NAME'), 'current_version' => C('CURRENT_VERSION'), 'company_name' => C('COMPANY_NAME'), 'develop_version' => C('DEVELOP_VERSION'), 'build_version' => C('BUILD_VERSION'), 'product_model' => C('PRODUCT_MODEL'), 'product_title' => C('PRODUCT_TITLE'), 'develop_team' => C('DEVELOP_TEAM'), 'data_auth_key' => sha1(C('DATA_AUTH_KEY')), 'website_domain' => $_SERVER['HTTP_HOST'], 'server_software' => php_uname() . '_' . $_SERVER['SERVER_SOFTWARE'], 'website_title' => C('WEB_SITE_TITLE'), 'auth_sn' => C('AUTH_SN'), 'autn_username' => C('AUTH_USERNAME'), 'autn_password' => C('AUTH_PASSWORD'));
     $vars = http_build_query($params);
     //获取版本数据
     $conf_arr = array('post' => $params);
     $result = json_decode(\Org\Net\Http::fsockopenDownload($url, $conf_arr), true);
     if ($result['status'] == 1) {
         $this->ajaxReturn($result);
     } else {
         $this->error('连接服务器失败');
     }
 }
 /**
  * 更新地理位置
  */
 public function getLocation()
 {
     $longitude = I('get.longitude');
     $latitude = I('get.latitude');
     $baiduLongLat = json_decode(Http::CurlRequst('http://api.map.baidu.com/geoconv/v1/', array('coords' => $longitude . ',' . $latitude, 'from' => 3, 'to' => 5, 'ak' => 'mcFKx7aa0WB73SAW6b2IYQAP'), 'get'), true);
     if ($baiduLongLat['status'] !== 0) {
         $this->ajaxReturn(array('status' => false, 'msg' => '获取地址失败1'));
     }
     $location = json_decode(Http::CurlRequst('http://api.map.baidu.com/geocoder/v2/', array('location' => $baiduLongLat['result'][0]['x'] . ',' . $baiduLongLat['result'][0]['y'], 'output' => 'json', 'pois' => 0, 'ak' => 'mcFKx7aa0WB73SAW6b2IYQAP'), 'get'), true);
     if ($location['status'] !== 0) {
         $this->ajaxReturn(array('status' => false, 'msg' => '获取地址失败2'));
     }
     //存放坐标
     $res = M('Users')->where('userid = ' . ACPopedom::getID())->save(array('longitude' => $baiduLongLat['result'][0]['x'], 'latitude' => $baiduLongLat['result'][0]['y']));
     if (!$res) {
         $this->ajaxReturn(array('status' => false, 'msg' => '保存地址失败'));
     }
     $this->ajaxReturn(array('status' => true, 'msg' => '地理位置已更新', 'address' => $location['result']['formatted_address'], 'lng' => $baiduLongLat['result'][0]['x'], 'lat' => $baiduLongLat['result'][0]['y']));
 }
 public function download($field, $value, $watermark = '0', $ext = 'gif|jpg|jpeg|bmp|png', $absurl = '', $basehref = '')
 {
     $dir = date('Y-m-d/');
     $upload_url = '/Uploads/';
     $uploadpath = $upload_url . $dir;
     $uploaddir = './Uploads/' . $dir;
     $string = stripslashes($value);
     //判断是否需要下载
     if (!preg_match_all("/(href|src)=([\"|']?)([^ \"'>]+\\.({$ext}))\\2/i", $string, $matches)) {
         return $value;
     }
     //取出下载的图片
     $remotefileurls = array();
     foreach ($matches[3] as $matche) {
         //如果是本地图片, 则跳过
         if (strpos($matche, '://') === false) {
             continue;
         }
         $remotefileurls[] = $matche;
     }
     unset($matches, $string);
     $remotefileurls = array_unique($remotefileurls);
     $oldpath = $newpath = array();
     //开始下载
     //import("Org.Net.Http");
     foreach ($remotefileurls as $k => $file) {
         //判断是否是本地图片
         if (strpos($file, '://') === false || strpos($file, $upload_url) !== false) {
             continue;
         }
         //获取文件扩展名
         $filename = fileext($file);
         //$file_name = basename($file);
         $filename = $this->getname($filename);
         $newfile = $uploaddir . $filename;
         \Org\Net\Http::curlDownload($file, $newfile);
         //var_dump($newfile);exit;
     }
     //替换下载后的地址
 }
 public function digg()
 {
     mysql_query('set names utf-8');
     $page_num = 1;
     $item = ($page_num - 1) * 20;
     $url_arr = getUrl("http://book.douban.com/tag/%E7%BC%96%E7%A8%8B?start={$item}&type=T");
     $i = 0;
     $book = M('Book');
     foreach ($url_arr as $url) {
         $page = new \Analyse_Url($url);
         $value = array('title' => $page->getTitle(), 'author' => $page->getZuoZhe(), 'translator' => $page->getYiZhe(), 'price' => $page->getSimpleInfo("定价"), 'publisher' => $page->getSimpleInfo("出版社"), 'publish_time' => $page->getSimpleInfo("出版年"), 'page_num' => $page->getSimpleInfo("页数"), 'zhuangzhen' => $page->getSimpleInfo("装帧"), 'isbn' => $page->getSimpleInfo("ISBN"), 'introduct' => $page->getIntro(), 'pic_name_big' => __ROOT__ . '/Public/img/lpic/' . $page->getSimpleInfo("ISBN") . '.jpg', 'pic_name_small' => __ROOT__ . '/Public/img/mpic/' . $page->getSimpleInfo("ISBN") . '.jpg');
         $pic_url = $page->getPic();
         $big_pic_url = preg_replace('/mpic/', 'lpic', $pic_url);
         \Org\Net\Http::curlDownload($pic_url, './Public/img/mpic/' . $page->getSimpleInfo("ISBN") . '.jpg');
         \Org\Net\Http::curlDownload($big_pic_url, './Public/img/lpic/' . $page->getSimpleInfo("ISBN") . '.jpg');
         $book->data($value)->add();
         $i++;
         if ($i > 10) {
             break;
         }
     }
 }
Example #8
0
 public function downloadAllHomework()
 {
     $homeworkId = I('get.homeworkId');
     $courseId = I('get.courseId');
     if (empty($homeworkId) || empty($courseId)) {
         $this->error('参数错误');
     }
     $zipObject = new \ZipArchive();
     $homeworkDir = "./Uploads/Course/{$courseId}/homework/{$homeworkId}/";
     if ($handle = opendir($homeworkDir)) {
         $allHomework = "{$homeworkDir}course{$courseId}{$homewokrId}.zip";
         $zipObject->open($allHomework, $zipObject::CREATE);
         /* 这是正确地遍历目录方法 */
         while (false !== ($file = readdir($handle))) {
             if ($file == '.' || $file == '..') {
                 continue;
             }
             $zipObject->addFile("{$homeworkDir}{$file}", "{$file}");
         }
         closedir($handle);
         \Org\Net\Http::download($allHomework);
     }
 }
Example #9
0
 /** 
  * 发送HTTP请求核心函数
  *
  * @param string $method 使用GET还是POST方式访问
  * @param array $vars 需要另外附加发送的GET/POST数据
  * @param int $timeout 连接对方服务器访问超时时间,单位为秒
  * @param array $options 当前操作类一些特殊的属性设置
  * @return string 返回服务器端读取的返回数据
  */
 public function send($method = 'GET', $timeout = 5, $options = array())
 {
     //处理参数是否为空
     if ($this->uri == '') {
         throw new Exception(__CLASS__ . ": Access url is empty");
     }
     $parse = parse_url($this->uri);
     $host = $parse['host'];
     //处理GET请求参数
     if ($method == 'GET' && !empty($this->vars)) {
         $query = Http::makeQuery($this->vars);
         $sep = isset($parse['query']) && $parse['query'] != '' ? '&' : '?';
         $this->uri .= $sep . $query;
     }
     //处理POST请求数据
     $data = '';
     if ($method == 'POST' && !empty($this->vars)) {
         $data = Http::makeQuery($this->vars);
     }
     //设置缺省头
     $this->setHeader('User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1)');
     if (!preg_match("/^[/d]{1,3}/.[/d]{1,3}/.[/d]{1,3}/.[/d]{1,3}\$/", $host)) {
         $this->setHeader("Host: " . $host);
     }
     if ($this->cookies != '') {
         $this->setHeader("Cookie: " . $this->cookies);
     }
     $this->setHeader("Connection: Close");
     //'Accept-Language: zh-cn',
     //'Cache-Control: no-cache',
     //构造头信息
     $opts = array('http' => array('method' => $method, 'timeout' => $timeout));
     if ($data != '') {
         $opts['http']['content'] = $data;
     }
     $opts['http']['header'] = '';
     foreach ($this->header as $h) {
         $opts['http']['header'] .= $h . "/r/n";
     }
     //print_r($opts);exit;
     //读取扩展设置选项
     if (!empty($options)) {
         isset($options['proxy']) ? $opts['http']['proxy'] = $options['proxy'] : '';
         isset($options['max_redirects']) ? $opts['http']['max_redirects'] = $options['max_redirects'] : '';
         isset($options['request_fulluri']) ? $opts['http']['request_fulluri'] = $options['request_fulluri'] : '';
     }
     //发送数据返回
     $context = stream_context_create($opts);
     if (($buf = file_get_contents($this->uri, null, $context)) === false) {
         throw new Exception(__CLASS__ . ": file_get_contents(" . $this->uri . ") fail");
     }
     return $buf;
 }
 public function gather()
 {
     $bookid = I('get.bookid');
     $gid = D('Book')->where('id=' . $bookid)->getField('gid');
     if (!$gid) {
         $this->ajaxReturn(array('statusCode' => 300, 'message' => '文章不存在'));
     }
     $url = $this->getBookJs($gid);
     $content = json_decode(\Org\Net\Http::fsockopenDownload($url), true);
     if (!$content || $content['status'] != 1) {
         $this->ajaxReturn(array('statusCode' => 300, 'message' => '采集失败'));
     }
     //判断是否采集过, 没有的话, 保存文章信息
     //判断最新章节
     //取出所有章节
     //dump($content);exit();
     $group = $content['data']['group'];
     //echo json_encode($group[199]);exit;
     $map['bookid'] = $data['bookid'] = $bookid;
     //待优化: 查看已采集的章节数量,
     $count_chapter = D('BookChapter')->where('bookid=' . $bookid)->count();
     if ($count_chapter < count($group)) {
         foreach ($group as $k => $chapter) {
             if ($k < $count_chapter) {
                 continue;
             }
             //判断是否已经存在
             $map['chapterid'] = $chapter['index'];
             $exist_chapter = D('BookChapter')->where($map)->field('id, status')->find();
             if (!$exist_chapter) {
                 //保存
                 $data['chapterid'] = $chapter['index'];
                 $data['cid'] = $chapter['cid'];
                 $data['index'] = $chapter['index'];
                 $data['rank'] = $chapter['rank'];
                 $data['title'] = $chapter['text'];
                 $data['url'] = $chapter['href'];
                 D('BookChapter')->add($data);
             }
         }
         //更新最后一章信息到Book表
         $last_chapter['last_chapter_title'] = $data['title'];
         $last_chapter['last_chapter_index'] = $data['index'];
         $last_chapter['last_chapter_update_time'] = NOW_TIME;
         D('Book')->where('id=' . $bookid)->save($last_chapter);
     }
     //取出地址中返回的章节
     $this->ajaxReturn(array('statusCode' => 200, 'message' => '采集成功', 'tabid' => 'Book_manage'));
 }
 public function searchFolder()
 {
     import("ORG.Net.Http");
     $id = I('get.goalID');
     $url = "http://jwzx.cqupt.edu.cn/fileAttach.php?id=" . $id;
     $http = new Http();
     $html = file_get_contents($url);
     $last = $http_response_header[7];
     $last = explode('.', $last);
     $site = $_SERVER["SERVER_NAME"];
     $setPosition = "./Public/jwzxnews/" . $id . '.' . $last[1];
     if (!file_exists($setPosition)) {
         $http->curlDownload($url, $setPosition);
     }
     $folder_name = explode('/', $_SERVER["SCRIPT_NAME"]);
     $setPosition = "http://" . $site . '/' . $folder_name[1] . "/Public/jwzxnews/" . $id . '.' . $last[1];
     echo json_encode($setPosition);
 }
 /**
  * 测试功能:测试http类的下载功能
  */
 public function testDownload()
 {
     Http::download("Image/ggk.png", "图片");
 }
Example #13
0
 /**
  * 模拟微信请求
  */
 public function swxpay()
 {
     return true;
     // $api = 'http://222.92.197.77/mpay/wxpaynotify';
     $api = 'http://222.92.197.77/mpay/wxpaynotify';
     $paramvars = array('attach' => '商城订单', 'bank_billno' => '201503196160365106', 'bank_type' => '2024', 'discount' => '0', 'fee_type' => '1', 'input_charset' => 'UTF-8', 'notify_id' => 'l18MqLVnvVCjPrHZGj1cjpcikTgDLw7eKQgVsNpbLUkseuw_pr6TkSPL_ukq0yW4ewULSw1MP8JA6qC1YTB1Z9LO6WpyV6dd', 'out_trade_no' => 'MP2015031915591168188', 'partner' => '1230268401', 'product_fee' => '1', 'sign' => '36800F6EDC64F5F6A346C454FFA2B9E8', 'sign_type' => 'MD5', 'time_end' => '20150319160327', 'total_fee' => '1', 'trade_mode' => '1', 'trade_state' => '0', 'transaction_id' => '1230268401201503196194568564', 'transport_fee' => '0');
     //发送请求
     $HttpClient = Http::Init($api, 1);
     $result = $HttpClient->post(null, $paramvars, array(), '', 15);
     dump($result);
     exit;
 }
 public function saveCoverImage($url)
 {
     try {
         $config = C('ARTICLE_COVER_UPLOAD');
         $name = md5($url) . '.jpg';
         $path = $this->getName($config['subName'], $name) . '/';
         $this->_createFolder($config['rootPath'] . $path);
         $savepath = "./" . $config['rootPath'] . $path . $name;
         Http::curlDownload($url, $savepath);
         $info['tmp_name'] = $savepath;
         $info['savename'] = $name;
         $info['name'] = $name;
         $info['type'] = 'image/jpeg';
         $info['size'] = 2048;
         $info['md5'] = md5_file($savepath);
         $info['ext'] = 'jpg';
         $info['savepath'] = $path;
         $info['path'] = $config['rootPath'] . $path . $name;
         /* 调用文件上传组件上传文件 */
         $Picture = D('DcCover');
         $pic_driver = C('PICTURE_UPLOAD_DRIVER');
         $return = $Picture->uploadOne($info, C('ARTICLE_COVER_UPLOAD'), C('PICTURE_UPLOAD_DRIVER'), C("UPLOAD_{$pic_driver}_CONFIG"));
         // TODO:上传到远程服务器
         return $return['id'];
     } catch (Exception $e) {
         ob_end_flush();
         echo $e->getMessage() . "<br/>";
         flush();
         return;
     }
 }
 public function gather()
 {
     //保存请求时间
     //$data['create_time'] = NOW_TIME;
     //$result = M('post_log')->add($data);
     //取出需要更新文章
     $map_cron['next_cron_time'] = array('lt', NOW_TIME);
     //$map_cron['status']		//是否在连载
     $detail = D('Book')->where($map_cron)->order('next_cron_time')->find();
     $gid = $detail['gid'];
     $bookid = $detail['id'];
     //如果没有计划, 返回真
     if (!$detail) {
         exit('over');
     }
     //更新此次更新时间
     $data_cron['last_cron_time'] = NOW_TIME;
     $data_cron['next_cron_time'] = NOW_TIME + 3600;
     //下次时间 1小时
     $result = D('Book')->where('id=' . $bookid)->save($data_cron);
     if (!$gid) {
         exit('error');
     }
     $url = $this->getBookJs($gid);
     $content = json_decode(\Org\Net\Http::fsockopenDownload($url), true);
     if (!$content || $content['status'] != 1) {
         exit('error');
     }
     //判断是否采集过, 没有的话, 保存文章信息
     //判断最新章节
     //取出所有章节
     $group = $content['data']['group'];
     $map['bookid'] = $data['bookid'] = $bookid;
     //待优化: 查看已采集的章节数量,
     $count_chapter = D('BookChapter')->where('bookid=' . $bookid)->count();
     if ($count_chapter < count($group)) {
         foreach ($group as $k => $chapter) {
             if ($k < $count_chapter) {
                 continue;
             }
             //判断是否已经存在
             $map['chapterid'] = $chapter['index'];
             $exist_chapter = D('BookChapter')->where($map)->field('id, status')->find();
             if (!$exist_chapter) {
                 //保存
                 $data['chapterid'] = $chapter['index'];
                 $data['cid'] = $chapter['cid'];
                 $data['index'] = $chapter['index'];
                 $data['rank'] = $chapter['rank'];
                 $data['title'] = $chapter['text'];
                 $data['url'] = $chapter['href'];
                 D('BookChapter')->add($data);
             }
         }
         //更新最后一章信息到Book表
         $last_chapter['last_chapter_title'] = $data['title'];
         $last_chapter['last_chapter_index'] = $data['index'];
         $last_chapter['last_chapter_update_time'] = NOW_TIME;
         D('Book')->where('id=' . $bookid)->save($last_chapter);
         exit('success');
     } else {
         //更新下一个任务
         $this->gather();
     }
     //更新, 记录信息
 }
 public function QRcode()
 {
     \Predis\Autoloader::register();
     $redis = new \Predis\Client();
     //生成二维码
     $numberid = M('randnumber')->add(array('openid' => ''));
     $token = base64_encode(authcode($numberid, "ENCODE", SESSION_AUTH));
     //设置标志有效时间
     $redis->setex('__WX_NUMBERID_' . $numberid, 300, 'true');
     $rs = json_decode(Http::CurlRequst("http://api.wwei.cn/wwei", array("data" => $token, 'apikey' => 20150828111302), "GET"), true);
     $this->assign('erweima', $rs['data']['qr_filepath']);
     $this->assign('token', $token);
     $this->display();
 }
 public function download()
 {
     if (I('get.file')) {
         $filename = base64_decode(I('get.file'));
         $file = C('BACKUP_PATH') . $filename;
         $res = \Org\Net\Http::download($file);
         if ($res) {
             $this->error($res);
         }
     } else {
         $this->error(L('_ERROR_ACTION_'));
     }
 }