Example #1
0
 /**
  * 分词
  */
 public static function segger($paramArr)
 {
     $options = array('content' => '', 'segger' => 'default', 'mustIn' => 0, 'num' => 10);
     if (is_array($paramArr)) {
         $options = array_merge($options, $paramArr);
     }
     extract($options);
     $outArr = array();
     $content = strip_tags(mb_convert_encoding($content, "utf-8", "gbk"));
     #$data = API_Http::curlPage(array('url'=>self::$seggerUrl . "?segger=default&content=".urlencode($content)));
     $data = API_Http::curlPost(array('url' => self::$seggerUrl, 'postdata' => array('segger' => $segger, 'cnt' => $num, 'content' => $content)));
     if ($data) {
         $dataArr = explode("\n", $data);
         foreach ($dataArr as $d) {
             if (!$d) {
                 continue;
             }
             list($wd, $score) = explode("/", $d);
             if ($mustIn && $score < 0) {
                 continue;
             }
             $outArr[] = array('wd' => $wd, 'score' => $score);
         }
     }
     return $outArr;
 }
Example #2
0
 /**
  * 统计访问日志,比如记录某一文章ID的访问
  */
 public static function logAccessByType($paramArr)
 {
     $options = array('type' => '', 'param' => false, 'imei' => "");
     if (is_array($paramArr)) {
         $options = array_merge($options, $paramArr);
     }
     extract($options);
     $url = '';
     switch ($type) {
         case "DOC_DETAIL":
             #文章内容页
             $param = array('docId' => 3269781, 'classId' => 210, 'fullUrl' => 1);
             //$url = API_Item_Urls_Doc::getDocUrl($param);
             $url = "www.baidu.com";
             //做实验用
             break;
         case "PRO_DETAIL":
             #产品库各种综述页
             $url = '';
             break;
     }
     if (!$url) {
         return false;
     }
     $url = urlencode($url);
     $ip = API_Item_Service_Area::getClientIp();
     //获得当前用户的IP地址
     $refer = isset($_SERVER['HTTP_REFERER']) ? urlencode($_SERVER['HTTP_REFERER']) : '';
     //上一层连接
     $reqUrl = "http://hongbo.ea3w.com/ext-test/writeLog.php?ip={$ip}&url={$url}&refer={$refer}&imei={$imei}&type={$type}";
     #请求这个页面,writeLog.php执行写入日志
     return API_Http::sendHeaderOnly(array('url' => $reqUrl));
 }
Example #3
0
 /**
  * 设置各种码的header信息
  * @param int $code
  */
 public static function sendHeaderCode($paramArr)
 {
     $options = array('code' => '');
     if (is_array($paramArr)) {
         $options = array_merge($options, $paramArr);
     }
     extract($options);
     API_Http::sendHeaderCode($code);
 }
Example #4
0
 /**
  * 加载缓存数据
  */
 protected static function loadProCache($moduleName, $param = array(), $num = 0)
 {
     if (!$moduleName) {
         return false;
     }
     $paramStr = "";
     if ($param) {
         foreach ($param as $k => $v) {
             $paramStr .= "&{$k}=" . urlencode($v);
         }
     }
     $url = "http://zcloud.xxx.com/proMongo?modName={$moduleName}{$paramStr}";
     $data = API_Http::curlPage(array('url' => $url, 'timeout' => 1));
     #远程请求数据
     if ($data) {
         $data = API_JsonDecode::decode($data);
     }
     return $data;
 }
Example #5
0
 function _connect(&$fp)
 {
     if (!empty($this->proxy_host) && !empty($this->proxy_port)) {
         $this->_isproxy = true;
         $host = $this->proxy_host;
         $port = $this->proxy_port;
     } else {
         $host = $this->host;
         $port = $this->port;
     }
     $this->status = 0;
     if ($fp = fsockopen($host, $port, $errno, $errstr, $this->_fp_timeout)) {
         // socket connection succeeded
         return true;
     } else {
         //如果连接失败,尝试不适用代理重新连接一次
         if ($this->_isproxy) {
             $this->proxy_host = API_Http::curlPage(array('url' => "http://118.67.120.127/cgi-bin/socket_adsl_restart_control.cgi?file=1", 'timeout' => 2));
             $this->proxy_port = "8088";
             $host = $this->proxy_host;
             $port = $this->proxy_port;
             if ($fp = fsockopen($host, $port, $errno, $errstr, $this->_fp_timeout)) {
                 return true;
             } else {
                 // socket connection failed
                 $this->status = $errno;
                 switch ($errno) {
                     case -3:
                         $this->error = "#socket creation failed (-3)";
                     case -4:
                         $this->error = "#dns lookup failure (-4)";
                     case -5:
                         $this->error = "#connection refused or timed out (-5)";
                     default:
                         $this->error = "#connection failed (" . $errno . ")";
                 }
                 return false;
             }
         }
         // socket connection failed
         $this->status = $errno;
         switch ($errno) {
             case -3:
                 $this->error = "socket creation failed (-3)";
             case -4:
                 $this->error = "dns lookup failure (-4)";
             case -5:
                 $this->error = "connection refused or timed out (-5)";
             default:
                 $this->error = "connection failed (" . $errno . ")";
         }
         return false;
     }
 }
Example #6
0
 /**
  *   获得某个标签下面的用户列表 
  *   
  */
 public static function getTagUserList($paramArr)
 {
     $options = array('tagId' => '');
     if (is_array($paramArr)) {
         $options = array_merge($options, $paramArr);
     }
     extract($options);
     if (!$tagId) {
         return false;
     }
     $assessToken = API_Item_Open_WeixinQy::getAccessToken();
     $data = API_Http::curlPage(array('url' => 'https://qyapi.weixin.qq.com/cgi-bin/tag/get?access_token=' . $assessToken . '&tagid=' . $tagId, 'timeout' => 3));
     $data = api_json_decode($data);
     return $data;
 }
Example #7
0
 /**
  * 发送模板信息接口
  * @param type $paramArr
  * @return type 
  */
 public static function sendTemplateMessage($paramArr)
 {
     $options = array('appId' => '', 'appSecret' => '', 'dataArr' => '');
     if (is_array($paramArr)) {
         $options = array_merge($options, $paramArr);
     }
     extract($options);
     if (empty($appId) || empty($appSecret) || empty($dataArr)) {
         return false;
     }
     #获得access_token
     $tokenDataArr = self::getAccessToken(array('appId' => $appId, 'appSecret' => $appSecret));
     #获得 access_token
     $accessToken = "";
     if (!empty($tokenDataArr['state'])) {
         $accessToken = $tokenDataArr['data'];
     } else {
         return false;
     }
     $jsonStr = "";
     $jsonStr = API_Http::curlPost(array('url' => 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . $accessToken, 'postdata' => !empty($dataArr) ? api_json_encode($dataArr) : ''));
     $jsonArr = array();
     $jsonArr = api_json_decode($jsonStr);
     if (!empty($jsonArr['errmsg'])) {
         if ($jsonArr['errmsg'] == 'ok' && $jsonArr['errcode'] == '0') {
             return true;
         }
     } else {
         return false;
     }
 }
Example #8
0
 /**
  * 获得手机号信息
  */
 public static function getMobileArea($paramArr)
 {
     $options = array('mobile' => '');
     if (is_array($paramArr)) {
         $options = array_merge($options, $paramArr);
     }
     extract($options);
     if (!$mobile || !preg_match('/^1[3458][0-9]{9}$/', $mobile)) {
         return false;
     }
     $outArr = array();
     #首先尝试从db中查询
     /** add by cui*/
     $db = API_Db_Ip::instance();
     $sql = "select * from mobile_data where mno = '{$mobile}' limit 1";
     $re = $db->getRow($sql);
     if ($re) {
         $outArr = array('卡号归属地' => $re["area"], '卡类型' => $re["card"], '区号' => $re["areano"], '邮编' => $re["zip"]);
         return $outArr;
     }
     $outData = array();
     #尝试接口1
     $url = "http://www.ip138.com:8080/search.asp?action=mobile&mobile={$mobile}";
     $dom = LJL_Api::run("Service.FetchHtml.getHtmlOrDom", array('url' => $url, 'charset' => 'gbk', 'timeout' => 3, 'getDom' => 1));
     if ($dom) {
         $trs = $dom->find(".tdc");
         if ($trs) {
             foreach ($trs as $tr) {
                 $tds = $tr->find("td");
                 if (!isset($tds[0])) {
                     continue;
                 }
                 $name = $tds[0]->innertext;
                 $value = $tds[1]->innertext;
                 $name = str_replace(array(" ", "&nbsp;"), "", strip_tags($name));
                 $name = iconv('gbk', 'utf-8', $name);
                 $value = iconv('gbk', 'utf-8', $value);
                 if (!in_array($name, array('卡类型', '区号', '邮编', '卡号归属地'))) {
                     continue;
                 }
                 $value = str_replace(" ", "", strip_tags($value));
                 if ($name == '邮编') {
                     $value = (int) $value;
                 }
                 if ($name == '卡号归属地') {
                     $value = str_replace("&nbsp;", "|", $value);
                 }
                 if ($name && $value) {
                     $outData[$name] = $value;
                 }
             }
         }
     }
     if (!$outData) {
         #尝试接口2
         $url = 'http://www.youdao.com/smartresult-xml/search.s?type=mobile&q=' . $mobile;
         $data = API_Http::curlPage(array('url' => $url, 'timeout' => 1));
         if (preg_match("#<location>(.+)</location>#Ui", $data, $m)) {
             $outData['卡号归属地'] = trim(trim($m[1]), '|');
         }
     }
     #将取得的数据记录到数据库,方便下次直接使用
     /*bycui*/
     if ($outData) {
         $sql = "insert into mobile_data(mno,area,card,areano,zip,tm)\r\n                    values('{$mobile}','" . $outData['卡号归属地'] . "','" . $outData['卡类型'] . "','" . $outData['区号'] . "','" . $outData['邮编'] . "','" . SYSTEM_TIME . "') ";
         $db->query($sql);
     }
     return $outData;
 }
Example #9
0
 /**
  * 获得一个代理IP和端口
  */
 public static function getProxyData($paramArr)
 {
     $options = array('retryCnt' => 5);
     if (is_array($paramArr)) {
         $options = array_merge($options, $paramArr);
     }
     extract($options);
     $defaultPort = 8088;
     $outArr = false;
     $tmp = 1;
     #如果已经取过至少3个代理,就从这三个中随机获得一个
     if (self::$proxySaveArr && count(self::$proxySaveArr) >= 3) {
         $tmpPidx = array_rand(self::$proxySaveArr, 1);
         $ip = self::$proxySaveArr[$tmpPidx];
         $outArr = array('ip' => $ip, 'port' => $defaultPort);
     } else {
         #尝试获得代理
         while ($tmp < $retryCnt) {
             #获得一个有用的
             $proxy = API_Http::curlPage(array('url' => "http://14.32.120.127/cgi-bin/socket_adsl_restart_control.cgi?file=1", 'timeout' => 2));
             if (!$proxy) {
                 continue;
             }
             #尝试这个代理是否可用
             $fp = @fsockopen($proxy, $defaultPort, $errno, $errstr, 1);
             if ($fp) {
                 self::$proxySaveArr[] = $proxy;
                 $outArr = array('ip' => $proxy, 'port' => $defaultPort);
                 fclose($fp);
                 break;
             } else {
                 #echo "CONNECT ERROR: ".$errno;
             }
             $tmp++;
         }
     }
     return $outArr;
 }
Example #10
0
 /**
  *  获取数据
  */
 private static function fetchData($paramArr)
 {
     $options = array('apiName' => '', 'data' => false, 'format' => 'json');
     if (is_array($paramArr)) {
         $options = array_merge($options, $paramArr);
     }
     extract($options);
     //系统级参数部分
     $reqData = array('app_key' => self::$_APPKEY, 'app_secret' => self::$_APPSECRET, 'api_name' => $apiName, 'format' => $format);
     if ($data) {
         $reqData = array_merge($data, $reqData);
     }
     $url = self::$_APPCALLBURL . "?" . http_build_query($reqData);
     #
     $responseData = API_Http::curlPage(array('url' => $url, 'timeout' => 30));
     if ($responseData && $responseData != "null") {
         return api_json_decode($responseData);
     } else {
         return false;
     }
 }
<?php

require '/www/8hao/html/tool/test_su/Http.php';
$url1 = 'http://pad.zol.com.cn/slide/531/5310254_1.html#p=1';
// 组图
//$url1 = 'http://ask.zol.com.cn/cell_phone/';
//$url1 = 'http://news.zol.com.cn/';
//$res1 = get_headers($url1);
//$res1 = curlHttpCode(array('url'=>$url1));
//var_dump($res1);exit('58_1');
$url1 = 'http://www.zol.com.cn/';
$paramArr = array('url' => $url1, 'timeout' => 5, 'recErrLog' => 0, 'reConnect' => 0, 'keepAlive' => 0);
$htmlCode = API_Http::curlPage($paramArr);
$pattern = '@<a href=\\"([^#\\"\']*?)">.*?<\\/a>@';
preg_match_all($pattern, $htmlCode, $res1);
if ($res1) {
    # 将非200的链接放到这个数组中
    $badData = array();
    foreach ($res1[1] as $k1 => $v1) {
        if ($k1 > 200) {
            break;
        }
        $httpCode = curlHttpCode(array('url' => $v1));
        if ($httpCode != 200 || $httpCode != 0) {
            $badData[] = $res1[0][$k1];
        }
    }
}
var_dump($badData);
exit;
$httpCode = curlHttpCode(array('url' => $url1));
Example #12
0
 /**
  * 请求天气网数据
  */
 private static function getCurlData($paramArr)
 {
     $options = array('url' => '', 'retry' => 3);
     if (is_array($paramArr)) {
         $options = array_merge($options, $paramArr);
     }
     extract($options);
     if (!$url) {
         return null;
     }
     #最多通信3次
     $requestFlag = 0;
     do {
         $json = API_Http::curlPage(array('url' => $url, 'timeout' => 5));
         $requestFlag++;
     } while (!$json && $requestFlag < $retry);
     if (!$json || $json == 'data error') {
         return null;
     }
     return $json;
 }