Core.php
1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?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);
}
}