PHP號碼歸屬地區分自動化查詢API封裝

來源:互聯網
上載者:User

標籤:lte   out   new   from   []   更新   die   elf   cti   

<?php/*        電話號碼區分地址.儲存到資料庫;*/class Filter{    private $_phone = ‘‘;    private $_api = ‘http://mobsec-dianhua.baidu.com/dianhua_api/open/location?tel=‘;    private $_user;    private $_host;    private $_pwd;    private $_dbname;    private static $conn = null;    private function __construct () {    }    public static function _interance () {        // 返回執行個體        if (self::$conn == null) return self::$conn = new Filter;    }    /*        param host        param user        param pwd        param dbname        return null    */    public function _conn ($host, $user, $pwd, $dbname) {        $this->_host = $host;        $this->_user = $user;        $this->_pwd  = $pwd;        $this->_dbname = $dbname;    }    public function _select () {        try {            $pdo = new PDO(‘mysql:host=‘ . $this->_host . ‘;dbname=‘ . $this->_dbname, $this->_user, $this->_pwd);            $pdo->query("SET CHARSET ‘utf8‘");        } catch (PDOException $e) {            die("Connection fail:") . $e->getMessage();        }        $sql = "SELECT * FROM phone WHERE"; // 待最佳化的sql語句        $stmt = $pdo->prepare($sql);        $stmt->execute();        while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) {            if ($result != []) return $result;        }    }    /*        param phone 電話        return null    */    public function _setdata ($phone) {        if ($phone != null and strlen($phone) == 11) {            $this->_phone = $phone;        }    }    /*        param phone 電話        param api   api地址        return json 字串    */    public function _rseponseText () {        $ch = curl_init();        $str = $this->_api . $this->_phone;        curl_setopt($ch, CURLOPT_URL, $str);        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);        $output = curl_exec($ch);        return $output;    }}

持續更新...

PHP號碼歸屬地區分自動化查詢API封裝

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.