增加了通用的google ajax搜索接口
This commit is contained in:
parent
60e1444c9e
commit
4b5afe8ed9
|
@ -757,5 +757,33 @@ class ServiceController extends Zend_Controller_Action
|
|||
$rows=$this->db->fetchAll($sql);
|
||||
echo Zend_Json::encode($rows);
|
||||
}
|
||||
|
||||
function googlesearchAction(){
|
||||
|
||||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
$q = $this->_request->getParam('q');
|
||||
$rez = $this->google_search_api(array(
|
||||
'q' => $q, // 查询内容
|
||||
'key' => $this->config->google->maps->api,
|
||||
'userip' => $_SERVER['REMOTE_ADDR'],
|
||||
));
|
||||
print_r($rez);
|
||||
exit();
|
||||
}
|
||||
|
||||
function google_search_api($args, $referer = 'http://westdc.westgis.ac.cn/', $endpoint = 'web'){
|
||||
$url = "http://ajax.googleapis.com/ajax/services/search/".$endpoint;
|
||||
if ( !array_key_exists('v', $args) )
|
||||
$args['v'] = '1.0';
|
||||
$url .= '?'.http_build_query($args, '', '&');
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_REFERER, $referer);
|
||||
$body = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $body;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue