- <?php
- // +----------------------------------------------------------------------
- // | JuhePHP [ NO ZUO NO DIE ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
- // +----------------------------------------------------------------------
- // | Author: Juhedata <info@juhe.cn>
- // +----------------------------------------------------------------------
- //----------------------------------
- // 聚合数据-基站查询API调用示例代码
- //----------------------------------
- header('Content-type:text/html;charset=utf-8');
- $apiurl = 'http://v.juhe.cn/cell/get'; //基站接口url
- $mnc = '0';//移动基站:0 联通基站:1 默认:0
- $cell = '28655';//大区号
- $lac = '17695';//小区号
- $key = '52a0ee009932b35054********'; //您申请的appkey
- $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];
- /*
- "MCC":"460",
- "MNC":"1",
- "LNG":"120.721423", //gps坐标:经度
- "LAT":"31.29854", //gps坐标:纬度
- "O_LNG":"120.72577772352", //高德坐标:经度
- "O_LAT":"31.296529947917", //高德坐标:纬度
- "PRECISION":"1101", //基站覆盖半径
- "ADDRESS":"江苏省苏州市吴中区金鸡湖大道368号" //基站地址
- */
- 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) {
- //echo "cURL Error: " . curl_error($ch);
- return false;
- }
- $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
- $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
- curl_close( $ch );
- return $response;
- }
- //该片段来自于http://www.codesnippet.cn/detail/2601201614489.html
来源: http://www.codesnippet.cn/detail/2601201614489.html