天天看點

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 "

";      

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] =>

)