PHP号码归属地区分自动化查询API封装
2021-04-11 13:26
标签:lte out new from [] 更新 die elf cti 持续更新... PHP号码归属地区分自动化查询API封装 标签:lte out new from [] 更新 die elf cti 原文地址:https://www.cnblogs.com/phpcurd/p/9026908.htmlphp
/*
电话号码区分地址.储存到数据库;
*/
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;
}
}
上一篇:[第三堂课]c#自学课程(3)
下一篇:WPF 绕圈进度条(二)
文章标题:PHP号码归属地区分自动化查询API封装
文章链接:http://soscw.com/index.php/essay/74282.html