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 

  • 相关阅读:
    获取office版本
    SQL中判断字符串中包含字符的方法
    wpf 多表头
    webservice MaxReceivedMessageSize :已超过传入消息(65536)的最大消息大小配额
    QQ检测登陆及QQ协议
    ssl-openssl简介
    抓包及分析(wireshark&tcpdump)
    Git的一些东西(后续补充)
    SSH实现隧道功能穿墙
    Nmap参考指南(Man Page)
  • 原文地址:https://www.cnblogs.com/yszr/p/8301198.html
Copyright © 2011-2022 走看看