zoukankan      html  css  js  c++  java
  • 一个非常好的php实现手机号归属地查询接口类

    前一阵子看到了一个非常好的php手机归属地查询的类,写的很精简,查询也很精确!大致代码是这样的:

    <?php

    header("Content-type:text/html;charset=utf-8");

    $mobile_home=new mobile_home();

    $mobile_home->set_mobile('13217248888');

    $arr = $mobile_home->showji();

    echo "<pre>";

    print_r($arr);

    class mobile_home{

    public $mobile;

    public function set_mobile($mobile) {

    $this->mobile=$mobile;

    $this->checklen();

    }

    public function checklen(){

    if(strlen($this->mobile) != "11"){

     

    }

    }

    public function showji(){  

    $data=$this->get('http://api.showji.com/Locating/www.showji.com.aspx?m='.$this->mobile.'&output=json','',"http://api.showji.com");

     

    if(is_array($data)){

    return $data;

    }

    }

    private function get($urll, $cookie='',$referer=''){ 

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $urll);

    curl_setopt($ch, CURLOPT_HEADER,0);

    curl_setopt($ch, CURLOPT_REFERER ,$referer);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    curl_setopt($ch, CURLOPT_COOKIE, $cookie);

    $content = curl_exec($ch);

    curl_close($ch);

    return  json_decode($content,true);

    }

    }

    ?>

    以下是查询返回的结果,是一个数组,所以很好调用。

    Array

    (

        [Mobile] => 13217244283

        [QueryResult] => True

        [Province] => 湖北

        [City] => 荆门

        [AreaCode] => 0724

        [PostCode] => 448000

        [Corp] => 中国联通

        [Card] => 

    )

    文章出自:http://www.daixiaorui.com/read/10.html 

  • 相关阅读:
    变量可变性问题
    Android 创建Listener监听器形式选择:匿名内部类?外部类?
    linux下安装zookeeper
    翻页工具类
    将哈夫曼树转化成二叉树
    Activity的启动流程分析
    题目1186:打印日期
    数据库设计--数据流图(DFD)
    c#基础之数组
    10.3.1 一个CONNECT BY的样例
  • 原文地址:https://www.cnblogs.com/yszr/p/8301198.html
Copyright © 2011-2022 走看看