Home > php教程 > PHP源码 > body text

聚合数据的移动联通基站接口的php完整代码实例

PHP中文网
Release: 2016-05-23 08:39:41
Original
1568 people have browsed it

本代码是基于聚合数据的移动联通基站查询API实现的基站定位功能

<?php
// +----------------------------------------------------------------------
// | JuhePHP [ NO ZUO NO DIE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: Juhedata <info@juhe.cn>
// +----------------------------------------------------------------------
  
//----------------------------------
// 聚合数据-基站查询API调用示例代码
//----------------------------------
header(&#39;Content-type:text/html;charset=utf-8&#39;);
$apiurl = &#39;http://v.juhe.cn/cell/get&#39;; //基站接口url
$mnc = &#39;0&#39;;//移动基站:0 联通基站:1 默认:0
$cell = &#39;28655&#39;;//大区号
$lac = &#39;17695&#39;;//小区号
$key = &#39;52a0ee009932b35054********&#39;; //您申请的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[&#39;error_code&#39;];
    if($error_code == 0){
        //成功请求到数据
        $data = $result[&#39;result&#39;][&#39;data&#39;][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[&#39;reason&#39;]."(".$result[&#39;error_code&#39;].")";
    }
}
  
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 , &#39;Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36&#39; );
        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.&#39;?&#39;.$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;
}
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!