Example #1
0
 public function connect()
 {
     try {
         if (isEmptyString($this->config['username']) || isEmptyString($this->config['password'])) {
             $this->connection = new MongoClient(sprintf('mongodb://%s:%d', $this->config['host'], $this->config['port']));
         } else {
             $this->connection = new MongoClient(sprintf('mongodb://%s:%d', $this->config['host'], $this->config['port']), array('username' => $this->config['username'], 'password' => $this->config['password'], 'db' => $this->config['db']));
         }
     } catch (Exception $e) {
         $this->collection = null;
         $this->connection = null;
         Logger::ERROR('Connect mongodb error [' . $e->getMessage() . ']', __FILE__, __LINE__, ERROR_LOG_FILE);
     }
 }
Example #2
0
 public function checkAccessToken()
 {
     if (empty($this->accessToken)) {
         if (empty($this->refreshToken)) {
             Logger::ERROR("No Access Token.", "", "", "qq_sdk_err");
             return false;
         } else {
             $this->getAccessToken();
             if (empty($this->accessToken)) {
                 Logger::ERROR("Can NOT refresh access token.", "", "", "qq_sdk_err");
                 return false;
             }
         }
     }
     return true;
 }
Example #3
0
 /**
  * Make an HTTP request
  *
  * @return string API results
  * @ignore
  */
 function http($url, $method, $postfields = NULL, $headers = array())
 {
     list($usec, $sec) = explode(" ", microtime());
     $begin = (double) $usec + (double) $sec;
     $this->http_info = array();
     $ci = curl_init();
     /* Curl settings */
     curl_setopt($ci, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
     curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
     curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
     curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
     curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($ci, CURLOPT_ENCODING, "");
     curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
     curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
     curl_setopt($ci, CURLOPT_HEADER, FALSE);
     curl_setopt($ci, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
     $config = HaloEnv::get('config');
     $debug = $config['app']['debug'];
     if (!isEmptyString($this->http_proxy)) {
         curl_setopt($ci, CURLOPT_PROXY, $this->http_proxy);
         if (Logger::isDebugEnabled()) {
             Logger::DEBUG('URL:[' . $url . '][PROXY:' . $this->http_proxy . ']', __FILE__, __LINE__, 'sina_api');
         }
     }
     if ($this->cookie) {
         if (isset($this->cookie['SUW'])) {
             $this->cookie['SUW'] = urldecode($this->cookie['SUW']);
             curl_setopt($ci, CURLOPT_REFERER, "http://weibo.cn");
         } else {
             curl_setopt($ci, CURLOPT_REFERER, "http://weibo.com");
         }
         $cookie = http_build_query($this->cookie, null, '; ');
         curl_setopt($ci, CURLOPT_COOKIE, $cookie);
     }
     switch ($method) {
         case 'POST':
             curl_setopt($ci, CURLOPT_POST, TRUE);
             if (!empty($postfields)) {
                 curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
                 $this->postdata = $postfields;
             }
             break;
         case 'DELETE':
             curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
             if (!empty($postfields)) {
                 $url = "{$url}?{$postfields}";
             }
     }
     if (isset($this->access_token) && $this->access_token) {
         $headers[] = "Authorization: OAuth2 " . $this->access_token;
     }
     $headers[] = "API-RemoteIP: " . $_SERVER['REMOTE_ADDR'];
     curl_setopt($ci, CURLOPT_URL, $url);
     curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ci, CURLINFO_HEADER_OUT, TRUE);
     $response = curl_exec($ci);
     $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
     $this->http_info = array_merge($this->http_info, curl_getinfo($ci));
     $this->url = $url;
     if ($this->http_code != 200) {
         if (curl_errno($ci) == CURLE_OPERATION_TIMEOUTED) {
             Logger::ERROR("sina api timeout url is " . $url . ", sever ip is " . $_SERVER['REMOTE_ADDR'], "", "", "sina_api_timeout");
             //                $msg = urlencode("Fatal error sina api is timeout on ip ".$_SERVER['REMOTE_ADDR']);
             //                system('wget "http://223.202.17.147/insert_information.php?email=junqiang.liu@yolu-inc.com&info='.$msg.'&pass=fuck18324hfbdhfkgmxc" -O /dev/null -o /dev/null');
         }
         $e = new Exception();
         Logger::ERROR("&&&&&& Curl error is: " . print_r(curl_error($ci), true), "", "", "sina_api_error");
         Logger::ERROR(sprintf("====\ncode: %d\nurl:%s\nresponse:%s====\nstack:%s\ninfo:%s\n", $this->http_code, $url, $response, $e->getTraceAsString(), print_r(curl_getinfo($ci), true)), __FILE__, __LINE__, 'sina_api_error');
     }
     if ($this->debug) {
         echo "<hr/>=====post data======\r\n<pre>";
         // 			var_dump($postfields);
         echo '</pre><hr/>=====info=====' . "\r\n<pre>";
         // 			var_dump( curl_getinfo($ci) );
         echo '</pre><hr/>=====$response=====' . "\r\n";
         // 			var_dump( $response );
     }
     curl_close($ci);
     return $response;
 }
Example #4
0
 protected function inputClientError($data)
 {
     $config = HaloEnv::get('config');
     $debug = $config['app']['debug'];
     Logger::ERROR($data);
     switch ($data['code']) {
         case 1100:
             $desc = "职位不存在";
             break;
         case 1108:
             $desc = "职位已关闭";
             break;
         case 1109:
             $desc = "职位尚未发布";
             break;
         case 1205:
             $desc = "重复投递简历";
             break;
         case 1206:
             $desc = "不能投递简历,职位或公司不存在";
             break;
         case 1208:
             $desc = "简历不存在";
             break;
         case 1209:
             $desc = "简历已存在";
             break;
         case 1216:
             $desc = "项目不存在";
             break;
         case 1300:
             $desc = '用户名或密码错误';
             break;
         default:
             $desc = "请求错误";
             break;
     }
     $data['desc'] = $desc;
     if (!$debug) {
         unset($data['error']);
         unset($data['code']);
     }
     echo json_encode($data);
     haloDie();
 }
Example #5
0
         $prefix = sprintf('%s#%d', $tag, substr(strval(time()), -4));
         self::$mc->set('ns:' . $tag, $prefix, 0, 86400 * 3);
     }
     if (!empty($id)) {
         $prefix .= '#' . $id;
     }
     $prefix .= "_" . WZhaopinEnv::getVersion();
     return $prefix;
 }
 public function invalidAllValuesByTag($tag)
 {
     $prefix = self::$mc->get('ns:' . $tag);
     if ($prefix) {
         $prefix = sprintf('%s#%d', $tag, substr(strval(time()), -4));
         self::$mc->set('ns:' . $tag, $prefix, 0, 86400 * 3);
     }
 }
 /**
  * init MC SEVER
  * @param string $name
  * @return Memcache
  * @throws Exception
  */
 private static function getMc($name = 'web')
 {
Example #6
0
 public function query($sql, $values = null)
 {
     $stmt = $this->dbh->prepare($sql);
     $stmt->execute($values);
     if ($stmt->errorCode() != PDO::ERR_NONE) {
         if (count($values)) {
             $msg = sprintf('%s | (%s)', $sql, implode(',', $values));
         } else {
             $msg = $sql;
         }
         Logger::ERROR($msg, __FILE__, __LINE__, 'ERROR-SQL');
         Logger::ERROR($stmt->errorInfo());
     }
     return $stmt;
 }