<?php //$content = file_get_contents('http://astro.sina.com.cn/pc/west/frame1_11.html'); //$content = file_get_contents('frame0_11_1.html'); if (isset($update_xz) && ($content = getUrlContent('http://astro.sina.com.cn/pc/west/frame0_' . $update_xz . '_1.html'))) { preg_match("/<!-- SUDA_CODE_END -->.*<!-- Start Wrating -->/si", $content, $match); preg_match("/<li class=\"datea\">有效日期:(.*)<\\/li>/i", $content, $dates); $yxqx = $dates[1]; $match[0] = str_replace("\n", '', $match[0]); preg_match("/<div class=\"lotconts\">(.*)<\\/div>/i", $match[0], $zhpg); $zhpg = $zhpg[1]; $match[0] = str_replace("</div>", "\n", $match[0]); preg_match_all("/<h4>(.*)<\\/h4>(.*)/i", $match[0], $match1); //print_r($match1); foreach ($match1[1] as $k => $m) { switch (substr($m, 0, 8)) { case '综合运势': $zhys = substr_count($match1[2][$k], '<img'); break; case '健康指数': $jkzs = $match1[2][$k]; break; case '工作状况': $gzzk = substr_count($match1[2][$k], '<img'); break; case '理财投资': $nctz = substr_count($match1[2][$k], '<img'); break; case '商谈指数': $stzs = $match1[2][$k]; break;
{ //$cookie_jar = tempnam('./','cookie'); // Create file with unique file name (cookie*) $cookie_jar = './cookie.txt'; $resource = curl_init(); curl_setopt($resource, CURLOPT_URL, $url); curl_setopt($resource, CURLOPT_POST, 1); curl_setopt($resource, CURLOPT_POSTFIELDS, $postdata); curl_setopt($resource, CURLOPT_COOKIEFILE, $cookie_jar); curl_setopt($resource, CURLOPT_COOKIEJAR, $cookie_jar); curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1); curl_exec($resource); return $resource; } // 取得此 Url 的內容 function getUrlContent($resource, $url) { curl_setopt($resource, CURLOPT_URL, $url); curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1); $content = curl_exec($resource); return $content; } // Test: // post to url and get cookie $url = 'http://local.asus.com/aaron/curl/login.php'; $postdata = 'username=admin&password=1234'; $resource = setUrlCookie($url, $postdata); // set cookie 'u' => 'admin' or anything // get contents (need cookie check) $url = 'http://local.asus.com/aaron/curl/check_login.php'; echo getUrlContent($resource, $url); // Login success.
/** * * @param $origin_path 原始物理图片地址 * @param array $sizes 缩略图大小信息 为空则取后台设置 可生成多个缩略图 数组 参数1 为宽度, 参数2为高度, 参数3为处理方式:0(缩放,默认),1(剪裁), 参数4为是否水印 默认为 0(不生成水印) array( array(300,300,0,0), array(100,100,0,0), ... ), * @param $path 存储的路径 * @param $file_name 保存的文件名 * @param $del_temp 是否删除临时文件 * @param $id 关联编号,将根据编号生成目录 * * 返回 复制成功的信息,如为false则复制失败 * array( * 'path' => xxx //物理路径 * 'url' => xxx //相对路径 * ); * * by fzmatthew */ function copyImage($origin_path, $sizes = array(), $path = 'share', $del_temp = true, $id = 0) { global $_FANWE; static $size_setting = NULL, $image = NULL; if ($image === NULL) { include_once fimport('class/image'); $image = new Image(); } if ($path == 'temp') { $dir = './public/upload/temp/' . fToDate(NULL, 'Y/m/d/H'); } else { if ($id > 0) { $dir = './public/upload/' . $path . '/' . getDirsById($id); } else { $dir = './public/upload/' . $path . '/' . fToDate(NULL, 'Y/m/d'); } } makeDir(FANWE_ROOT . $dir); $file_name = md5(microtime(true)) . random('6') . '.jpg'; $file_path = FANWE_ROOT . $dir . "/" . $file_name; $bln = false; if (file_exists($origin_path) && @copy($origin_path, $file_path)) { $bln = true; } else { $data = getUrlContent($origin_path); if (!empty($data) && @file_put_contents($file_path, $data) > 0) { $bln = true; } } if ($bln) { $info = $image->getImageInfo($file_path); if ($info['type'] != 'jpg' && $info['type'] != 'jpeg') { if (!$image->convertType($file_path, $file_path)) { return false; } } $water_image = $_FANWE['setting']['water_image']; if (!empty($water_image)) { $water_image = FANWE_ROOT . $water_image; } $water_mark = intval($_FANWE['setting']['water_mark']); $alpha = intval($_FANWE['setting']['water_alpha']); $place = intval($_FANWE['setting']['water_position']); if ($sizes !== false && empty($sizes)) { if ($size_setting === NULL) { if (!isset($_FANWE['cache']['image_sizes'])) { FanweService::instance()->cache->loadCache('image_sizes'); } $size_setting = $_FANWE['cache']['image_sizes']; } $sizes = $size_setting; } foreach ($sizes as $size) { if ($size[0] > 0 || $size[1] > 0) { $thumb_bln = false; $thumb_type = isset($size[2]) ? intval($size[2]) : 0; if ($thumb = $image->thumb($file_path, $size[0], $size[1], $thumb_type)) { if (isset($size[3]) && intval($size[3]) > 0) { $image->water($thumb['path'], $water_image, $alpha, $place); } } } } if ($del_temp) { @unlink($origin_path); } return array('path' => $file_path, 'url' => $dir . "/" . $file_name, 'width' => $info[0], 'height' => $info[1]); } else { return false; } }
public function fetch($url) { global $_FANWE; $id = $this->getID($url); if (empty($id)) { return false; } $key = 'dangdang_' . $id; $share_goods = FDB::resultFirst('SELECT share_id,goods_id FROM ' . FDB::table('share_goods') . ' WHERE uid = ' . $_FANWE['uid'] . " AND goods_key = '{$key}'"); if ($share_goods) { $result['status'] = -1; $result['share_id'] = $share_goods['share_id']; $result['goods_id'] = $share_goods['goods_id']; return $result; } //请求数据 $content = getUrlContent("http://product.dangdang.com/product.aspx?product_id=" . $id); if (empty($content)) { return false; } $content = gbToUTF8($content); $content = preg_replace("/[\r\n]/", '', $content); @preg_match("/<h1>(.*?)<\\/h1>/", $content, $title); if (empty($title)) { return false; } @preg_match("/var oldimage \\= '(.*?)';/", $content, $img); if (empty($img)) { return false; } @preg_match("/<span class=\"promotions_price_d\">¥<b>(.*?)<\\/b><\\/span>/u", $content, $price); if (empty($price)) { @preg_match("/<span.*?id=\"salePriceTag\">¥(.*?)<\\/span>/u", $content, $price); if (empty($price)) { return false; } else { $price = (double) $price[1]; } } else { $price = (double) $price[1]; } if (FS("Image")->getIsServer()) { $args = array(); $args['pic_url'] = $img[1]; $server = FS("Image")->formatServer($_FANWE['request']['image_server'], 'DE'); $server = FS("Image")->getImageUrlToken($args, $server, 1); $body = FS("Image")->sendRequest($server, 'savetemp', true); if (empty($body)) { return false; } $image = unserialize($body); $result['image_server'] = $server['image_server']; } else { $image = copyFile($img[1], "temp", false); if ($image === false) { return false; } $image['server_code'] = ''; } $result['item']['key'] = $key; $result['item']['name'] = strip_tags(str_replace('[当当自营]', '', $title[1])); $result['item']['price'] = $price; $result['item']['img'] = $image['path']; $result['item']['server_code'] = $image['server_code']; $result['item']['pic_url'] = $img[1]; $result['item']['url'] = "http://product.dangdang.com/product.aspx?product_id=" . $id; $from = $_FANWE['cache']['business']['dangdang']['from']; if (!empty($from)) { $result['item']['taoke_url'] = "http://union.dangdang.com/transfer.php?from=" . $from . "&ad_type=10&sys_id=1&backurl=" . $result['item']['url']; } @preg_match("/<div class=\"legend\"><a href=\"http:\\/\\/shop\\.dangdang\\.com\\/(.*?)\".*?>(.*?)<\\/a><a.*?>.*?<\\/a><\\/div>/", $content, $shop); if (!empty($shop)) { $result['shop']['name'] = $shop[2]; $result['shop']['url'] = "http://shop.dangdang.com/" . $shop[1]; if (!empty($from)) { $result['shop']['taoke_url'] = "http://union.dangdang.com/transfer.php?from=" . $from . "&ad_type=10&sys_id=1&backurl=" . $result['shop']['url']; } if (!FS("Shop")->getShopExistsByUrl($result['shop']['url'])) { $content = getUrlContent($result['shop']['url']); if (!empty($content)) { $content = preg_replace("/[\r\n]/", '', $content); @preg_match("/<dl.*?id=\"hslice_shop_basic_info_" . $shop[1] . "\">.*?<dt><a.*?><img src=\"(.*?)\".*?\\/><\\/a><\\/dt>/", $content, $shop_img); if (!empty($shop_img)) { if (FS("Image")->getIsServer()) { $args = array(); $args['pic_url'] = $shop_img[1]; $server = FS("Image")->getImageUrlToken($args, '', 1); $body = FS("Image")->sendRequest($server, 'savetemp', true); if (!empty($body)) { $image = unserialize($body); } else { $image = false; } } else { $image = copyFile($shop_img[1], "temp", false); if ($image === false) { $image['server_code'] = ''; } } if ($image !== false) { $result['shop']['logo'] = $image['path']; $result['shop']['server_code'] = $image['server_code']; } } } } } return $result; }
public function serverSide($options) { // Handle empty values if (empty($options['value'])) { return 'success'; } $messageArray = array(); // Perform the server side check with a scrape $serverSideResponse = getUrlContent($options['url'] . '&value=' . $options['value']); // Can't read the URL if ($serverSideResponse['status'] != 'success') { $messageArray[] = 'This component could not be validated.'; } else { $serverSideResponse = json_decode($serverSideResponse['response']); if ($serverSideResponse->status == 'success') { $messageArray == 'success'; } else { $messageArray = $serverSideResponse->response; } } return $messageArray; function getUrlContent($url, $postData = null) { // Handle objects and arrays $curlHandler = curl_init(); curl_setopt($curlHandler, CURLOPT_URL, $url); curl_setopt($curlHandler, CURLOPT_FAILONERROR, 1); curl_setopt($curlHandler, CURLOPT_TIMEOUT, 20); // Time out in seconds curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, 1); if ($postData != null) { foreach ($postData as $key => &$value) { if (is_object($value) || is_array($value)) { $value = json_encode($value); } } curl_setopt($curlHandler, CURLOPT_POSTFIELDS, $postData); } $request = curl_exec($curlHandler); if (!$request) { $response = array('status' => 'failure', 'response' => 'CURL error ' . curl_errno($curlHandler) . ': ' . curl_error($curlHandler)); } else { $response = array('status' => 'success', 'response' => $request); } return $response; } }
function process_sales($login, $options, $reptype) { global $last_http_headers; $appleid = $login["appleid"]; // function process_sales($sales_url, $appleid, $options, $reptype) { $reptype_l = strtolower($reptype); if (!is_dir(BASE_META_DIR . "/salesreports") && !mkdir(BASE_META_DIR . "/salesreports")) { return error("couldn't access salrereports directory"); } if (!is_dir(BASE_META_DIR . "/salesreports/{$appleid}") && !mkdir(BASE_META_DIR . "/salesreports/{$appleid}")) { return error("couldn't access salrereports directory for appleid={$appleid}"); } if (!is_dir(BASE_META_DIR . "/salesreports/{$appleid}/{$reptype_l}") && !mkdir(BASE_META_DIR . "/salesreports/{$appleid}/{$reptype_l}")) { return error("couldn't access salrereports {$reptype_l} directory for appleid={$appleid}"); } $filenames = array(); $attcnt = 0; if ($reptype_l == 'daily') { $from = 0; $to = 30; } else { $from = 0; $to = 24; } $weekbeg = mktime(0, 0, 0, date('m'), date('d'), date('Y')) - (date('N') - 1) * 24 * 60 * 60 - 24 * 60 * 60; for ($i = $from; $i < $to; $i++) { if ($reptype_l == 'daily') { $dt = date("Ymd", time() - $i * 24 * 60 * 60); } else { $dt = date("Ymd", $weekbeg - 7 * $i * 24 * 60 * 60); } $fntocheck = "S_" . $reptype[0] . "_" . $login["vendorid"] . "_{$dt}.txt"; echo "checkin report file {$fntocheck}... "; if (file_exists(BASE_META_DIR . "salesreports/{$appleid}/{$reptype_l}/" . $fntocheck)) { echo "report previously got. skipping \n"; continue; } echo "new report, getting\n"; echo "{$reptype} processing date {$dt}\n"; $postvars = array("USERNAME" => $login["appleid"], "PASSWORD" => $login["password"], "VNDNUMBER" => $login["vendorid"], "TYPEOFREPORT" => "Sales", "DATETYPE" => $reptype, "REPORTTYPE" => "Summary", "REPORTDATE" => $dt); $res = getUrlContent("https://reportingitc.apple.com/autoingestion.tft?", $postvars, true); $filename = isset($last_http_headers["content-disposition"]) ? $last_http_headers["content-disposition"] : false; $ERRORMSG = isset($last_http_headers["ERRORMSG"]) ? $last_http_headers["ERRORMSG"] : false; if ($ERRORMSG) { echo "ITC Error: {$ERRORMSG}\n"; } echo "filename={$filename}\n"; if (!$filename && $attcnt == 5) { if ($options["debug"]) { echo "content-disposition http header not found. skipping this report\n"; } continue; } $attcnt++; if (!$filename) { continue; } $ar = explode("=", $filename); $filename = $ar[1]; # Check for an override of the file name. If found then change the file # name to match the outputFormat. if ($options["outputFormat"]) { $filename = date($options["outputFormat"], $downloadReportDate); } $filebuffer = $res; $filename = BASE_META_DIR . "salesreports/{$appleid}/{$reptype_l}/" . $filename; if ($options["unzipFile"] && substr($filename, -3) == '.gz') { #Chop off .gz extension if not needed $filename = substr($filename, 0, strlen($filename) - 3); } if ($options["debug"]) { echo "Saving download file: {$filename}\n"; } file_put_contents($filename, $filebuffer); if ($options["unzipFile"]) { if ($options["debug"]) { echo "unzipping report file\n"; } $HandleRead = gzopen($filename, "rb"); $rest = substr($filebuffer, -4); $GZFileSize = end(unpack("V", $rest)); $report = gzread($HandleRead, $GZFileSize); gzclose($HandleRead); if (!$report) { warn("some problems with unzipping\n"); continue; } file_put_contents($filename, $report); if ($options["debug"]) { echo "unzipping succeeded\n"; } } $filenames[] = $filename; } return $filenames; }
curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1); curl_exec($resource); return $resource; } function getUrlContent($resource, $url) { curl_setopt($resource, CURLOPT_URL, $url); curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1); $content = curl_exec($resource); return $content; } $url = 'http://163.27.3.19/school/Login.asp'; $postdata = "txtID={$id}&txtPWD={$pwd}&Chk=Y"; $resource = setUrlCookie($url, $postdata); $url = 'http://163.27.3.19/school/STD_SCORE.asp'; $html = getUrlContent($resource, $url); //echo iconv("UTF-8","BIG5", $html); if (iconv("BIG5", "UTF-8", $html) == "無權使用 請登入") { //echo 'Login Error'; header("location:./?login_error"); } else { if (!isset($_SESSION['id'])) { $_SESSION['id'] = $id; $_SESSION['pwd'] = $pwd; } } //================Start parse================// include '../simple_html_dom.php'; class subject { public $name;
public function vjiaFetch($url) { global $_FANWE; $urls = $this->getVjiaID($url); if (empty($urls['id'])) { return false; } $key = 'vjia_' . $urls['id']; $share_goods = FDB::resultFirst('SELECT share_id,goods_id FROM ' . FDB::table('share_goods') . ' WHERE uid = ' . $_FANWE['uid'] . " AND goods_key = '{$key}'"); if ($share_goods) { $result['status'] = -1; $result['share_id'] = $share_goods['share_id']; $result['goods_id'] = $share_goods['goods_id']; return $result; } $url = $urls['url']; //请求数据 $content = getUrlContent($url); if (empty($content)) { return false; } $content = preg_replace("/[\r\n]/", '', $content); @preg_match("/<li class=\"title\">(.*?)<\\/li>/", $content, $title); if (empty($title)) { return false; } @preg_match("/<div class=\"sp-bigImg\">.*?<img.*?src=\"(.*?)\".*?\\/>.*?<\\/div>/", $content, $img); if (empty($img)) { return false; } @preg_match("/<span id=\"SpecialPrice\">(.*?)<\\/span>/", $content, $price); if (empty($price)) { return false; } if (FS("Image")->getIsServer()) { $args = array(); $args['pic_url'] = str_replace('/mid/', '/big/', $img[1]); $server = FS("Image")->formatServer($_FANWE['request']['image_server'], 'DE'); $server = FS("Image")->getImageUrlToken($args, $server, 1); $body = FS("Image")->sendRequest($server, 'savetemp', true); if (empty($body)) { return false; } $image = unserialize($body); $result['image_server'] = $server['image_server']; } else { $image = copyFile(str_replace('/mid/', '/big/', $img[1]), "temp", false); if ($image === false) { return false; } $image['server_code'] = ''; } $result['item']['key'] = $key; $result['item']['name'] = strip_tags(trim($title[1])); $result['item']['price'] = (double) $price[1]; $result['item']['img'] = $image['path']; $result['item']['server_code'] = $image['server_code']; $result['item']['pic_url'] = $img[1]; $result['item']['url'] = $url; $Source = $_FANWE['cache']['business']['vancl']['Source']; if (!empty($Source)) { $result['item']['taoke_url'] = $result['item']['url'] . "?Source=" . $Source; } return $result; }
public static function build_http_query_multi($params) { if (!$params) { return ''; } //print_r( $params ); //return null; // Urlencode both keys and values $keys = array_keys($params); $values = array_values($params); //$keys = SinaOAuthUtil::urlencode_rfc3986(array_keys($params)); //$values = SinaOAuthUtil::urlencode_rfc3986(array_values($params)); $params = array_combine($keys, $values); // Parameters are sorted by name, using lexicographical byte value ordering. // Ref: Spec: 9.1.1 (1) uksort($params, 'strcmp'); $pairs = array(); self::$boundary = $boundary = uniqid('------------------'); $MPboundary = '--' . $boundary; $endMPboundary = $MPboundary . '--'; $multipartbody = ''; foreach ($params as $parameter => $value) { //if( $parameter == 'pic' && $value{0} == '@' ) if (in_array($parameter, array("pic", "image")) && $value[0] == '@') { $url = ltrim($value, '@'); $content = getUrlContent($url); $filename = reset(explode('?', basename($url))); $mime = self::get_image_mime($url); $multipartbody .= $MPboundary . "\r\n"; $multipartbody .= 'Content-Disposition: form-data; name="' . $parameter . '"; filename="' . $filename . '"' . "\r\n"; $multipartbody .= 'Content-Type: ' . $mime . "\r\n\r\n"; $multipartbody .= $content . "\r\n"; } else { $multipartbody .= $MPboundary . "\r\n"; $multipartbody .= 'content-disposition: form-data; name="' . $parameter . "\"\r\n\r\n"; $multipartbody .= $value . "\r\n"; } } $multipartbody .= $endMPboundary; // For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61) // Each name-value pair is separated by an '&' character (ASCII code 38) // echo $multipartbody; return $multipartbody; }
/** * Find URLs and titles of items in a given feed * * Since there are several ways a feed can provide URL * to the item, we'll look for 'link' attribute first. * If it wasn't found, we'll settle for 'guid'. * * @param string $url URL of the feed * @return array Associative array: URL=>Title */ function getFeedItems($url) { $result = array(); libxml_use_internal_errors(true); $xml = simplexml_load_string(getUrlContent($url)); if ($xml) { foreach ($xml->channel->item as $item) { $link = $item->link ? $item->link : $item->guid; $result[(string) $link] = (string) $item->title; } } return $result; }
function init() { try { $path = __DIR__ . '/../app/config/parameters.ini'; $data = parse_ini_file($path); if (empty($data)) { throw new Exception("配置文件或内容损坏,请重新配置"); } $database_host = $data['database_host']; $database_port = $data['database_port']; $database_name = $data['database_name']; $database_user = $data['database_user']; $database_password = $data['database_password']; $database_host_im = $data['database_host_im']; $database_port_im = $data['database_port_im']; $database_name_im = $data['database_name_im']; $database_user_im = $data['database_user_im']; $database_password_im = $data['database_password_im']; $tmp = parse_url($data['ejabberd-server-http']); $host = $tmp["host"]; $conn = mysql_connect($database_host . ':' . $database_port, $database_user, $database_password, true); if (!$conn) { throw new Exception("WEB服务数据库连接失败,请重新配置"); } mysql_select_db($database_name, $conn); $errmsg = mysql_error(); if (!empty($errmsg)) { throw new Exception("WEB数据库错误:" . $errmsg); } $sql = "SET NAMES 'utf8'"; mysql_query($sql, $conn); mysql_query('delete from we_enterprise', $conn); mysql_query('delete from we_circle', $conn); mysql_query('delete from we_appcenter_apps', $conn); mysql_query('delete from we_sys_param', $conn); mysql_query('delete from we_micro_account', $conn); mysql_query('delete from we_department', $conn); //初始化企业 数据 $eno = $data['ENO']; $edomain = mysql_real_escape_string($_GET['en_domain']); $ename = mysql_real_escape_string($_GET['en_name']); $admin = mysql_real_escape_string($_GET['admin_account']); $sql = 'insert into we_enterprise(eno,edomain,ename,eshortname,sys_manager)values(\'' . $eno . '\',\'' . $edomain . '\',\'' . $ename . '\',\'' . $ename . '\',\'' . $admin . '\')'; $result = mysql_query($sql, $conn); $sql = 'insert into we_department(eno,dept_id,dept_name,parent_dept_id,fafa_deptid)values(\'' . $eno . '\',\'v' . $eno . '\',\'' . $ename . '\',\'v' . $eno . '\',\'v' . $eno . '\')'; $result = mysql_query($sql, $conn); $sql = 'insert into we_circle(circle_id,circle_name,create_staff,create_date,manager,enterprise_no,network_domain)values(\'10000\',\'' . $ename . '\',\'' . $admin . '\',now(),\'' . $admin . '\',\'' . $eno . '\',\'' . $edomain . '\')'; $result = mysql_query($sql, $conn); $sql = 'insert into we_sys_param(param_name,param_value)values(\'ejabberd_server_path\',\'\'),(\'imserver\',\'' . $host . ':5222\'),(\'mobile_active_code\',\'888888\')'; $result = mysql_query($sql, $conn); $sql = 'insert into we_appcenter_apps(appid,appkey,appname,state,appdeveloper,apptype)values(\'35dc24ba28ee06ce8741259c19fbc8e8\',\'61xU54Wx\',\'实时通知\',1,\'' . $eno . '\',\'99\')'; $result = mysql_query($sql, $conn); mysql_close($conn); $conn_im = mysql_connect($database_host_im . ':' . $database_port_im, $database_user_im, $database_password_im, true); if (!$conn_im) { throw new Exception("IM服务数据库连接失败,请重新配置"); } mysql_select_db($database_name_im, $conn_im); $errmsg = mysql_error(); if (!empty($errmsg)) { throw new Exception("IM数据库错误:" . $errmsg); } $sql = "SET NAMES 'utf8'"; mysql_query($sql, $conn_im); mysql_query('delete from cluster_node', $conn_im); mysql_query('delete from cluster_node_media', $conn_im); mysql_query('delete from users', $conn_im); mysql_query('delete from im_employee', $conn_im); mysql_query('delete from im_base_dept', $conn_im); $sql = 'insert into cluster_node(nodename,nodetype,isenabled,isstart,ip,start_time)values(\'ejabberd@' . $host . '\',0,1,1,\'' . $host . '\',now())'; $result = mysql_query($sql, $conn_im); $sql = 'insert into cluster_node_media(nodename,serv_type,port,extern_ip,extern_port)values(\'ejabberd@' . $host . '\',\'fileproxy\',7777,\'' . $host . '\',7777),(\'ejabberd@' . $host . '\',\'tcp\',4478,\'' . $host . '\',4478),(\'ejabberd@' . $host . '\',\'udp\',4478,\'' . $host . '\',4478)'; $result = mysql_query($sql, $conn_im); $sql = 'insert into im_base_dept(deptid,deptname,pid,path,noorder)values(\'v' . $eno . '\',\'' . $ename . '\',\'-10000\',\'/-10000/v' . $eno . '/\',0)'; $result = mysql_query($sql, $conn_im); $sql = 'insert into im_sys_seq(table_name,col_name,name,curr_value,step)values(\'im_base_dept\',\'deptid\',\'im_base_dept_deptid\',100001,1)'; $result = mysql_query($sql, $conn_im); mysql_close($conn_im); //初始化一个部门 $url = $data['open_api_url'] . '/api/http/exec_dataaccess?module=ApiHR&action=org_add'; $url .= '&deptname=体验部门&deptid=&eno=' . $eno . '&pid='; $re = json_decode(getUrlContent($url), true); //初始化管理员帐号 $admininfo = array(); $admininfo['eno'] = $eno; $admininfo['account'] = $admin; $admininfo['deptid'] = ''; $admininfo['realName'] = $_GET['admin_name']; $admininfo['passWord'] = $_GET['admin_pwd']; $admininfo['duty'] = '系统管理员'; $admininfo['mobile'] = ''; $url = $data['open_api_url'] . '/api/http/exec_dataaccess?module=ApiHR&action=staff_add&staffinfo='; $url .= json_encode(array($admininfo)); $re = json_decode(getUrlContent($url), true); //初始化默认公众号 $url = $data['open_api_url'] . '/api/http/exec_dataaccess?openid=' . $admin . '@' . $edomain . '&module=service&action=register_service¶ms='; $params = array(); $params['concern_approval'] = '0'; $params['deptid'] = array('v' . $eno); $params['desc'] = '用于发布公司内部管理规章制度'; $params['login_account'] = ''; $params['micro_id'] = ''; $params['name'] = '规章制度'; $re = json_decode(getUrlContent($url . json_encode($params)), true); $params['name'] = '企业新闻'; $params['desc'] = '用于发布公司事件'; $re = json_decode(getUrlContent($url . json_encode($params)), true); $filepath = __DIR__ . '/install/install.ini'; $ft = fopen($filepath, 'w+'); fwrite($ft, "install=ok"); fclose($ft); $data = array("returncode" => "0000", "msg" => ''); } catch (Exception $e) { if (isset($conn) && !empty($conn)) { mysql_close($conn); } $filepath = __DIR__ . '/install/install.ini'; $ft = fopen($filepath, 'w+'); fwrite($ft, $e); fclose($ft); $data = array("returncode" => "9999", "msg" => $e->getMessage()); } echo json_encode($data); }
function checkLoginValid() { $url = "http://" . $_POST['host'] . ":8086/db?u=" . urlencode($_POST['user']) . "&p=" . urlencode($_POST['pw']); $httpResult = getUrlContent($url); debug("Login check against {$url} returned: "); debug($httpResult); return 200 == $httpResult['status_code']; }
#!/usr/bin/php <?php function getUrlContent($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return $httpcode >= 200 && $httpcode < 300 ? $data : false; } $json = getUrlContent("http://78.46.50.55:8000/parimatch/"); $data = json_decode($json, true); #var_dump($data); print $data['lastUpdate']; var_dump($data['data']);
mysql_query($sql, $conn); } $sql = "SET NAMES 'utf8'"; mysql_query($sql, $conn); while (true) { //读取100条信息 $sql = "select conv_id, post_to_circle circle_id, conv_content from we_convers_list where conv_id=conv_root_id and conv_id > {$lastconvid} order by 0+conv_id limit 0, 100"; $result = mysql_query($sql, $conn); if (mysql_num_rows($result) == 0) { break; } while ($row = mysql_fetch_array($result)) { //分词 $conv_content = $row["conv_content"]; $conv_content = iconv("UTF-8", "GBK//IGNORE", $conv_content); $tokenstr = getUrlContent($cwsurl, urlencode($conv_content)); $tokenstr = iconv("GBK", "UTF-8//IGNORE", $tokenstr); $tokenarr = explode(" ", $tokenstr); //过滤一些 $tokenarr = array_unique(array_map(function ($item) { return trim($item); }, $tokenarr)); $filterstr = "'\"\\/,.!!"#\$%&()*+-_={}[]#¥%&`'()〔〕〈〉《》「」『』〖〗【】.*+,-.。、?…—·ˉˇ¨‘’“”々~‖∶/:;|〃<=>?@[\]^_`{|} ̄"; $tokenarr = array_filter($tokenarr, function ($item) use(&$filterstr) { return !empty($item) && strpos($filterstr, $item) === false; }); //写入索引表 $conv_id = $row["conv_id"]; $circle_id = $row["circle_id"]; foreach ($tokenarr as &$token) { $sql = "insert into we_convers_index(circle_id, token, conv_id) values('{$circle_id}', '{$token}', '{$conv_id}')";
function getUrlContent2($url, $postvars = false, $gethdr = false) { $attcnt = 1; global $last_http_code, $scrape_options; while (true) { if ($attcnt >= MAXATTEMPT) { return error("aborting getUrlContent2 after " . MAXATTEMPT . " attempts getting content"); } $cont = getUrlContent($url, $postvars, $gethdr); if ($last_http_code == 404) { return error("page not found. strange"); break; } if ($cont) { break; } if ($scrape_options["debug"]) { echo "sleeping for {$attcnt} sec\n"; } sleep($attcnt); $attcnt++; if ($scrape_options["debug"]) { echo " attempt {$attcnt}\n"; } } return $cont; }
public function sentShare($uid, $data) { global $_FANWE; static $bln = false; if (!$bln) { $uid = (int) $uid; $bind = FS("User")->getUserBindByType($uid, 'tqq'); $_FANWE['login_oauth']['tqq'][OpenSDK_Tencent_Weibo::ACCESS_TOKEN] = $bind['access_token']; $_FANWE['login_oauth']['tqq'][OpenSDK_Tencent_Weibo::OAUTH_TOKEN_SECRET] = $bind['oauth_token_secret']; $bln = true; } $data['content'] .= ' ' . $data['url']; if (empty($data['img'])) { OpenSDK_Tencent_Weibo::call('t/add', array('content' => $data['content'], 'clientip' => $_FANWE['client_ip']), 'POST'); } else { $content = getUrlContent($data['img']); $filename = reset(explode('?', basename($data['img']))); OpenSDK_Tencent_Weibo::call('t/add_pic', array('content' => $data['content'], 'clientip' => $_FANWE['client_ip']), 'POST', array('pic' => array('type' => 'image/jpg', 'name' => $filename, 'data' => $content))); } }
public function getPrice($img) { $dir = './public/upload/temp/' . fToDate(NULL, 'Y/m/d/H'); $file_name = md5(microtime(true)) . random('6') . '.png'; makeDir(FANWE_ROOT . $dir); $file_path = FANWE_ROOT . $dir . "/" . $file_name; $img_data = getUrlContent($img); if (empty($img_data) || @file_put_contents($file_path, $img_data) == 0) { return false; } $xs_count = 2; $keys = array('7' => array('011111011000111100011110001111000111100011110001111000110111110' => 0, '000110001111000001100000110000011000001100000110000011000111111' => 1, '011111011000111100011000001100001100001100001100001100001111111' => 2, '011111011000111100011000001100011100000011110001111000110111110' => 3, '000011000011100010110010011010001101111111000011000001100000110' => 4, '011111101100000110000011111000000110000011110001111000110111110' => 5, '001111001100001100000111111011000111100011110001111000110111110' => 6, '111111100000110000011000011000001100001100000110000110000011000' => 7, '011111011000111100011110001101111101100011110001111000110111110' => 8, '011111011000111100011110001111000110111111000001100001100111100' => 9), '9' => array('001111100011000110110000011110000011110000011110000011110000011110000011110000011011000110001111100' => 0, '000011000001111000000011000000011000000011000000011000000011000000011000000011000000011000001111110' => 1, '011111100110000110110000011000000011000000110000001100000011000000110000001100000011000000111111111' => 2, '011111100110000110110000011000000011000000110000111100000000110000000011110000011110000110011111100' => 3, '000000110000001110000010110000100110001000110010000110100000110111111111000000110000000110000000110' => 4, '011111111011000000011000000011000000011111100000000110000000011000000011110000011110000110011111100' => 5, '000111110001100000011000000110000000110111100111000110110000011110000011110000011011000110001111100' => 6, '111111111000000011000000110000000110000001100000001100000011000000011000000110000000110000001100000' => 7, '001111100011000110110000011110000011011000110001111100011000110110000011110000011011000110001111100' => 8, '001111100011000110110000011110000011110000011011000111001111011000000011000000110000001100011111000' => 9)); $configs = array('1' => array('word_width' => 9, 'offset_l' => 20, 'offset_t' => 4, 'word_spacing' => 2, 'd_width' => 5), '2' => array('word_width' => 7, 'offset_l' => 18, 'offset_t' => 4, 'word_spacing' => 2, 'd_width' => 5), '3' => array('word_width' => 7, 'offset_l' => 17, 'offset_t' => 3, 'word_spacing' => 2, 'd_width' => 4)); $res = imagecreatefrompng($file_path); $size = getimagesize($file_path); $data = array(); $offset_r = 0; for ($j = $size[0] - 1; $j >= 0; $j--) { $rgb = imagecolorat($res, $j, 6); $rgbarray = imagecolorsforindex($res, $rgb); if ($rgbarray['red'] < 125 || $rgbarray['green'] < 125 || $rgbarray['blue'] < 125) { break; } else { $offset_r++; } } $offset_b = 0; for ($i = $size[1] - 1; $i >= 0; $i--) { $rgb = imagecolorat($res, 9, $i); $rgbarray = imagecolorsforindex($res, $rgb); if ($rgbarray['red'] < 125 || $rgbarray['green'] < 125 || $rgbarray['blue'] < 125) { break; } else { $offset_b++; } } $img_width = $size[0]; if ($offset_b == 9) { $config = $configs[2]; } elseif ($offset_b == 10) { $config = $configs[3]; } else { $config = $configs[1]; $offset_b++; } $word_width = $config['word_width']; $key = $keys[$word_width]; $offset_l = $config['offset_l']; $offset_t = $config['offset_t']; $word_spacing = $config['word_spacing']; $d_width = $config['d_width']; $no_l = $size[0] - ($xs_count * ($word_width + $word_spacing) + $d_width + $offset_r); $no_r = $no_l + $d_width; for ($i = $offset_t; $i < $size[1] - $offset_b; $i++) { $w = 0; for ($j = $offset_l; $j < $size[0] - $offset_r; $j++) { if ($j >= $no_l && $j < $no_r) { continue; } $rgb = imagecolorat($res, $j, $i); $rgbarray = imagecolorsforindex($res, $rgb); if ($rgbarray['red'] < 125 || $rgbarray['green'] < 125 || $rgbarray['blue'] < 125) { $data[$i - $offset_t][$w] = 1; } else { $data[$i - $offset_t][$w] = 0; } $w++; } } $prices = array(); $length = count($data[0]); $height = count($data); $count = ($length + $word_spacing) / ($word_width + $word_spacing); for ($i = 0; $i < $count; $i++) { $x = $i * ($word_width + $word_spacing); for ($h = 0; $h < $height; $h++) { $temp = ''; for ($w = $x; $w < $x + $word_width; $w++) { $prices[$i] .= $data[$h][$w]; } } } $number = ''; foreach ($prices as $price) { $number .= $key[$price]; } @unlink($file_path); return (double) $number / 100; }
$data = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return $httpcode >= 200 && $httpcode < 300 ? $data : false; } date_default_timezone_set('EDT'); $dom = intval(date("j")); $mon = intval(date("m")); $year_start = 1949; $year_end = intval(date("Y")); //loop through and get all of the data $y = $year_start; $big_data = array(); while ($y < $year_end) { $base_url = "http://www.wunderground.com/history/airport/KIGX/" . $y . "/" . $mon . "/" . $dom . "/CustomHistory.html?format=1"; $dat = getUrlContent($base_url); $csv_dat = str_getcsv($dat, "\n"); foreach ($csv_dat as &$row) { $row = str_getcsv($row); } #var_dump($csv_dat); #first row is null, next is header if ($year_start - $y == 0) { #first foreach ($csv_dat[1] as $key => $value) { $big_data[0][] = strip_tags($value); } } foreach ($csv_dat[2] as $key => $value) { $big_data[$y - $year_start + 1][] = strip_tags($value); }