search
Homephp教程PHP源码聚合数据的移动联通基站接口的php完整代码实例

本代码是基于聚合数据的移动联通基站查询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;
}
Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)