Core.php 1.04 KB
<?php 

/**
 * 搜索的核心类
 * @author tongdesheng
 *
 */
class YHMSearch_Core {
	
	/**
	 * 请求
	 * @param string $urlPath
	 * @param array $params
	 */
	protected function req($urlPath, $params) {
		//构造请求地址
		$baseUrl = YHMConfig_Search::$baseUrl[Q_APPLICATION_ENV] . $urlPath . '?' . http_build_query($params);
		$httpClient = new Q_Utils_Http($baseUrl);
		$httpClient->request('get');
		if($httpClient->getStatus() == 200) {
			$strRet = $httpClient->getBody();
			return json_decode($strRet, true); 
		} else {
			throw new Exception('请求出错: ' . $httpClient->getStatus());
		}
	}
        
        /**
	 * 多个请求
	 * @param string $urlPath
	 * @param array $params
	 */
	protected function reqM($urlPath, $params) {
		//构造请求地址
		$baseUrl = YHMConfig_Search::$baseUrl[Q_APPLICATION_ENV] . $urlPath . '?' . http_build_query($params);
		$httpClient = new Q_Utils_Http($baseUrl);
		$httpClient->request('get');
                $strRet = $httpClient->getBody();
                return json_decode($strRet, true); 
	}
}