97 lines
2.7 KiB
PHP
97 lines
2.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2021年11月15日
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace UniLbs;
|
|
|
|
class Qqmap extends Base
|
|
{
|
|
|
|
public function handleCurlResponse($parse = true)
|
|
{
|
|
if($this->uniLbs->curl->curl_error){
|
|
return [
|
|
'code' => 1,
|
|
'msg' => "ERROR_CODE:{$this->uniLbs->curl->error_code},ERROR_MSSAGGE:{$this->uniLbs->curl->error_message}",
|
|
'data' => [
|
|
'error_code' => $this->uniLbs->curl->error_code,
|
|
'error_message' => $this->uniLbs->curl->error_message
|
|
]
|
|
];
|
|
}
|
|
$response = $this->uniLbs->curl->response;
|
|
if(!$parse)
|
|
return $response;
|
|
$response = json_decode($response,true);
|
|
if(isset($response['status']) && $response['status'] == 0){
|
|
$data = [
|
|
'code' => 0,
|
|
'msg' => 'ok',
|
|
'data' => isset($response['result']) && !isset($response['data']) ? $response['result'] : $response['data'],
|
|
'response' => $response
|
|
];
|
|
} else {
|
|
$data = [
|
|
'code' => 1,
|
|
'msg' => isset($resp['message']) ? $resp['message'] : 'error',
|
|
'data' => [],
|
|
'response' => $response
|
|
];
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 逆地址解析
|
|
* return array
|
|
*/
|
|
public function getAddress($data)
|
|
{
|
|
$data = array_merge($data, ['key' => $this->uniLbs->key]);
|
|
$query = $this->uniLbs->getUrlQuery($data);
|
|
$api = "https://apis.map.qq.com/ws/geocoder/v1/{$query}";
|
|
$this->uniLbs->buildRequest($api);
|
|
$resp = $this->handleCurlResponse();
|
|
return $resp;
|
|
}
|
|
|
|
/**
|
|
* 地址解析
|
|
* return array
|
|
*/
|
|
public function getLocation($data)
|
|
{
|
|
$data = array_merge($data, ['key' => $this->uniLbs->key]);
|
|
$query = $this->uniLbs->getUrlQuery($data);
|
|
$api = "https://apis.map.qq.com/ws/geocoder/v1/{$query}";
|
|
$this->uniLbs->buildRequest($api);
|
|
$resp = $this->handleCurlResponse();
|
|
return $resp;
|
|
}
|
|
|
|
/**
|
|
* 关键词搜索提示
|
|
* return array
|
|
*/
|
|
public function getPlaceSuggestion($data)
|
|
{
|
|
$data = array_merge($data, ['key' => $this->uniLbs->key]);
|
|
$query = $this->uniLbs->getUrlQuery($data);
|
|
$api = "https://apis.map.qq.com/ws/place/v1/suggestion{$query}";
|
|
$this->uniLbs->buildRequest($api, []);
|
|
$resp = $this->handleCurlResponse();
|
|
return $resp;
|
|
}
|
|
|
|
}
|
|
|