PHP号码归属地区分自动化查询API封装
Posted MiraclesGG
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP号码归属地区分自动化查询API封装相关的知识,希望对你有一定的参考价值。
<?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封装的主要内容,如果未能解决你的问题,请参考以下文章