<?php
header('Content-type:text/html;charset=utf-8');
$apiurl
= 'http:
$mnc
= '0';
$cell
= '28655';
$lac
= '17695';
$key
= '52a0ee009932b35054********';
$params
= "mnc={
$mnc
}&cell={
$cell
}&lac={
$lac
}&key={
$key
}";
$content
= juhecurl(
$apiurl
,
$params
);
if
(!
$content
){
echo
"网络错误,请求接口失败";
}
else
{
$result
= json_decode(
$content
,true);
$error_code
=
$result
['error_code'];
if
(
$error_code
== 0){
$data
=
$result
['result']['data'][0];
print_r(
$data
);
}
else
{
echo
$result
['reason']."(".
$result
['error_code'].")";
}
}
function
juhecurl(
$url
,
$params
=false,
$ispost
=0){
$httpInfo
=
array
();
$ch
= curl_init();
curl_setopt(
$ch
, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
curl_setopt(
$ch
, CURLOPT_USERAGENT , 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36' );
curl_setopt(
$ch
, CURLOPT_CONNECTTIMEOUT , 30 );
curl_setopt(
$ch
, CURLOPT_TIMEOUT , 30);
curl_setopt(
$ch
, CURLOPT_RETURNTRANSFER , true );
if
(
$ispost
)
{
curl_setopt(
$ch
, CURLOPT_POST , true );
curl_setopt(
$ch
, CURLOPT_POSTFIELDS ,
$params
);
curl_setopt(
$ch
, CURLOPT_URL ,
$url
);
}
else
{
if
(
$params
){
curl_setopt(
$ch
, CURLOPT_URL ,
$url
.'?'.
$params
);
}
else
{
curl_setopt(
$ch
, CURLOPT_URL ,
$url
);
}
}
$response
= curl_exec(
$ch
);
if
(
$response
=== FALSE) {
return
false;
}
$httpCode
= curl_getinfo(
$ch
, CURLINFO_HTTP_CODE );
$httpInfo
=
array_merge
(
$httpInfo
, curl_getinfo(
$ch
) );
curl_close(
$ch
);
return
$response
;
}