作者:叔叔123 | 来源:互联网 | 2018-03-23 01:01
跳至
set_mobile(18606240180);
$data = $mobile_home->showji();//data是一个数组,可以获取到你想要的信息
//print_r($data);
/**
*
* 手机归属地查询
*
* 通过curl扩展来实现查询手机号码归属地
*/
//定义一个class
class mobile_home {
public $mobile;
public function set_mobile($mobile) {
$this->mobile = $mobile;
$this->checklen();
}
//检测手机位数
public function checklen() {
if (strlen($this->mobile) != "11") {
die("手机号码有误");
}
}
//调用官方接口
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;
}
}
//通过curl扩展获取数据信息
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);
}
}
?>