获取get接口
function.php
function doGet($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// 执行后不直接打印出来
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
// 跳过证书检查
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// 不从证书中检查SSL加密算法是否存在
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
//执行并获取HTML文档内容
$output = curl_exec($ch);
//释放curl句柄
curl_close($ch);
return $output;
}controller.php
public function getUrl($moble)
{
$url = 'http://mobsec-dianhua.baidu***/dianhua_api/open/location?tel='.$moble;
// print_r($url);
//将url 进行json格式化转换 返回数组
$doget = json_decode(doGet($url),true);
// print_r($doget);
// die();
$str = $doget['response']["$moble"]['detail']['province'];
return $str;
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号