function request($route, $params, $toArray = TRUE)
 {
     $AppKey = XWB_APP_KEY;
     $EncryptKey = XWB_plugin::pCfg('encrypt_key');
     $paramsJSON = json_encode($params);
     $EncryptTime = time();
     $secret = md5(sprintf("#%s#%s#%s#%s#%s#", $AppKey, $route, $paramsJSON, $EncryptTime, $EncryptKey));
     $data = array('A=' . $route, 'P=' . $paramsJSON, 'T=' . $EncryptTime, 'F=' . $secret);
     $url = $this->url;
     $this->http->setUrl($url);
     $this->http->setData(implode('&', $data));
     $time_start = microtime();
     $result = $this->http->request('post');
     $time_end = microtime();
     $time_process = array_sum(explode(' ', $time_end)) - array_sum(explode(' ', $time_start));
     if ($toArray) {
         $result = xwb_util_json::decode($result, true);
     }
     $code = $this->http->getState();
     $this->logRespond(rtrim($this->url, '/') . '/' . $route, 'post', (int) $code, $result, array('param' => $params, 'time_process' => $time_process, 'triggered_error' => $this->http->get_triggered_error()));
     if (200 != $code) {
         $result = array("rst" => false, "errno" => "50001", "err" => "network error");
         $this->setError($result);
     }
     return $result;
 }
 function get4Tip($sina_uid, $index = null, $default = null)
 {
     if ($this->info === null) {
         $sql = 'SELECT `profile` FROM ' . DB::table('xwb_bind_info') . ' WHERE sina_uid=' . $sina_uid;
         $this->info = $this->db->fetch_first($sql);
     }
     if (empty($this->info['profile'])) {
         if ($default !== null) {
             return $default;
         }
         return array();
     }
     $object = @xwb_util_json::decode($this->info['profile'], true);
     if (!$object) {
         if ($default !== null) {
             return $default;
         }
         return array();
     }
     if ($index) {
         if (isset($object[$index])) {
             return $object[$index];
         }
         if ($default !== null) {
             return $default;
         }
     }
     return $object;
 }
 function load($A, $P, $T, $F)
 {
     $switch = XWB_plugin::pCfg('switch_to_xweibo');
     list(, $method) = explode('.', $A);
     if (!$switch && !in_array($method, $this->whileList)) {
         $this->_ERHelper('4010005', TRUE, 'load');
     }
     $this->_validate($A, $P, $T, $F);
     //检测验证
     ///处理参数集
     $PJDecode = ($tmp = xwb_util_json::decode($P, TRUE)) && is_array($tmp) ? $tmp : array();
     if ('null' != strtolower($P) && !$PJDecode) {
         $this->_ERHelper('4030001', TRUE, 'load');
     }
     if (!XWB_plugin::_chkPath($A)) {
         $this->_ERHelper('4010001', TRUE, 'load');
     }
     ///分析路由
     $Route = XWB_plugin::_parseRoute($A);
     if (XWB_R_DEF_MOD_FUNC == $Route[3] || '_' == substr($Route[3], 0, 1)) {
         $this->_ERHelper('4010001', TRUE, 'load');
     }
     ///构建API文件路径
     $FilePath = XWB_P_ROOT . DIRECTORY_SEPARATOR . "xplugin_apis" . DIRECTORY_SEPARATOR . $Route[1] . $Route[2] . '.xapi.php';
     if (!file_exists($FilePath)) {
         $this->_ERHelper('4010002', TRUE, 'load');
     }
     ///引用API文件
     require_once $FilePath;
     if (!class_exists($Route[2])) {
         $this->_ERHelper('4010002', TRUE, 'load');
     }
     ///初始化API类
     $apiHandler = new $Route[2]();
     if (!is_object($apiHandler) || !method_exists($apiHandler, $Route[3])) {
         $this->_ERHelper('4010002', TRUE, 'load');
     }
     ///调用API方法
     $RT = call_user_func_array(array($apiHandler, $Route[3]), $PJDecode);
     return $RT;
 }
 /**
  * Format and sign an OAuth / API request
  * 目前仅支持get和post方法
  *
  * @return array
  */
 function oAuthRequest($url, $method, $parameters, $useType = true, $multi = false)
 {
     $request = ns_OAuthRequest::from_consumer_and_token($this->token, $method, $url, $parameters);
     $method = strtoupper($method);
     switch ($method) {
         case 'GET':
             $this->last_req_url = $request->to_url();
             $this->http->setUrl($request->to_url());
             break;
         case 'POST':
             $this->last_req_url = $request->get_normalized_http_url();
             $this->http->setUrl($request->get_normalized_http_url());
             $this->http->setData($request->to_postdata($multi));
             if ($multi) {
                 $header_array = array();
                 $header_array2 = array();
                 if ($multi) {
                     $header_array2 = array("Content-Type: multipart/form-data; boundary=" . $GLOBALS['__CLASS']['ns_OAuthRequest']['__STATIC']['boundary'], "Expect: ");
                 }
                 foreach ($header_array as $k => $v) {
                     array_push($header_array2, $k . ': ' . $v);
                 }
                 if (!defined('CURLOPT_HTTPHEADER')) {
                     define('CURLOPT_HTTPHEADER', 10023);
                 }
                 $config = array(CURLOPT_HTTPHEADER => $header_array2);
                 $this->http->setConfig($config);
             }
             break;
         default:
             trigger_error('WRONG REQUEST METHOD IN WEIBO CLASS!', E_USER_ERROR);
             break;
     }
     $this->http->setHeader('API-RemoteIP', (string) XWB_plugin::getIP());
     $time_start = microtime();
     $result = $this->http->request(strtolower($method));
     $time_end = microtime();
     $time_process = array_sum(explode(" ", $time_end)) - array_sum(explode(" ", $time_start));
     if ($useType === false || $useType === true) {
         $result = xwb_util_json::decode($result, true);
     }
     $code = $this->http->getState();
     if (200 != $code) {
         $this->_delBindCheck(isset($result['error']) ? (string) $result['error'] : (string) $result);
         $this->req_error_count++;
     }
     if (defined('XWB_DEV_LOG_ALL_RESPOND') && XWB_DEV_LOG_ALL_RESPOND == true) {
         $this->logRespond($this->last_req_url, $method, (int) $code, $result, array('param' => $parameters, 'time_process' => $time_process, 'triggered_error' => $this->http->get_triggered_error(), 'base_string' => $request->base_string, 'key_string' => $request->key_string));
     }
     if (200 != $code) {
         if (0 == $code) {
             $result = array("error_code" => "50000", "error" => "timeout");
         }
         if ($useType === true) {
             if (!is_array($result)) {
                 $result = array('error' => (string) $result, 'error_code' => $code);
             }
             $this->setError($result);
         }
     }
     return $result;
 }
 /**
  * 对评论回推服务器返回的信息进行解码,并返回
  * @access protected
  * @return array array('httpcode'=> (int)服务器返回的状态码 , 'data'=> (mixed)服务器返回的body主数据 )
  */
 function _decodeResult()
 {
     if ($this->httpcode == 200) {
         $this->result = xwb_util_json::decode($this->result, true);
     }
     if (!is_array($this->result)) {
         $this->result = array();
     }
     return array('httpcode' => $this->httpcode, 'data' => $this->result);
 }
 /**
  * 本静态方法在64位时,将和原生调用json_decode一致;
  * 在32位操作系统时,将强制使用或者模拟php 5.4的JSON_BIGINT_AS_STRING,
  * 以解决在32位操作系统时的bigint转换错误导致精度丢失问题。
  * 本静态方法仅采用前两位参数。
  * @static
  * @see http://www.php.net/manual/en/function.json-decode.php
  * @param string $json
  * @param bool[optional] $assoc
  */
 function decode($json, $assoc = false)
 {
     switch (xwb_util_json::get_decode_type()) {
         case 0:
             return json_decode($json, $assoc);
             break;
         case 1:
             return json_decode($json, $assoc, 512, JSON_BIGINT_AS_STRING);
             break;
         default:
             $json = preg_replace('#(?<=[,\\{\\[])\\s*("\\w+"):(\\d{6,})(?=\\s*[,\\]\\}])#si', '${1}:"${2}"', $json);
             return json_decode($json, $assoc);
             break;
     }
 }
 /**
  * 用户名片:显示个人微博信息
  * @return string
  */
 function space_card_baseinfo_bottom_output()
 {
     global $_G;
     $output = '';
     $uid = isset($_G['gp_uid']) ? (int) $_G['gp_uid'] : 0;
     if ($uid < 1 || !$this->pCfg('space_card_weiboinfo') || false == $this->_start_xweibo(true)) {
         return $output;
     }
     $result = XWB_plugin::getBindUser($uid);
     if (is_array($result) && isset($result['uid'])) {
         $xweibourl_ta = tpl_sina_xweibo_x2::getWeiboProfileLink($result['sina_uid']);
         $switch = $this->pCfg('switch_to_xweibo');
         if ($switch) {
             $xweibourl = $this->pCfg('baseurl_to_xweibo');
             $xweibourl_ta_friends = $xweibourl . '/index.php?m=ta.follow&id=' . $result['sina_uid'];
             $xweibourl_ta_followers = $xweibourl . '/index.php?m=ta.fans&id=' . $result['sina_uid'];
         } else {
             $xweibourl = $xweibourl_ta_friends = $xweibourl_ta_followers = '';
         }
         $profile = xwb_util_json::decode($result['profile'], true);
         if (isset($profile['tipUserInfo']['friends_count'])) {
             if ($switch) {
                 $output = '<img height="16" width="16" src="' . $this->xwb_p_rootname . '/images/bgimg/icon_logo.png" />&nbsp;<a href="' . $xweibourl_ta_friends . '" target="_blank">&#20851;&#27880;</a>:' . $profile['tipUserInfo']['friends_count'] . '&nbsp;&nbsp;<a href="' . $xweibourl_ta_followers . '" target="_blank">&#31881;&#19997;</a>:' . $profile['tipUserInfo']['followers_count'] . '&nbsp;&nbsp;<a href="' . $xweibourl_ta . '" target="_blank">&#24494;&#21338;</a>:' . $profile['tipUserInfo']['statuses_count'];
             } else {
                 $output = '<img height="16" width="16" src="' . $this->xwb_p_rootname . '/images/bgimg/icon_logo.png" />&nbsp;&#20851;&#27880;:' . $profile['tipUserInfo']['friends_count'] . '&nbsp;&nbsp;&#31881;&#19997;:' . $profile['tipUserInfo']['followers_count'] . '&nbsp;&nbsp;&#24494;&#21338;:' . $profile['tipUserInfo']['statuses_count'];
             }
         } else {
             $output = '<img height="16" width="16" src="' . $this->xwb_p_rootname . '/images/bgimg/icon_logo.png" />&nbsp;<a href="' . $xweibourl_ta . '" target="_blank">&#35775;&#38382;&#24494;&#21338;&#39029;&#38754;</a>';
         }
     } elseif ($_G['uid'] == $uid) {
         $output = '<a href="home.php?mod=spacecp&ac=plugin&id=' . $this->pluginid . ':home_binding">&#23578;&#26410;&#32465;&#23450;&#26032;&#28010;&#24494;&#21338;&#65292;&#28857;&#20987;&#32465;&#23450;</a>';
     } else {
         $output = 'TA&#23578;&#26410;&#32465;&#23450;&#26032;&#28010;&#24494;&#21338;';
     }
     return $output;
 }