手机号码归属地查询API

 1 <?php
 2 function object_array($array){
 3   if(is_object($array)){
 4     $array = (array)$array;
 5   }
 6   if(is_array($array)){
 7     foreach($array as $key=>$value){
 8       $array[$key] = object_array($value);
 9     }
10   }
11   return $array;
12 } 
13 //9ksalhdfkashdfkjdhfsdfaa
14 for($x=5000;$x<=9999; $x++){
15     $ch = curl_init();
16     $url = 'http://apis.baidu.com/showapi_open_bus/mobile/find?num=185'.$x.$x;
17     $header = array(
18         'apikey: 97fab8dasfdsfsafsada3aa',//http://apistore.baidu.com/apiworks/servicedetail/709.html
19     );
20     // 添加apikey到header
21     curl_setopt($ch, CURLOPT_HTTPHEADER  , $header);
22     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
23     // 执行HTTP请求
24     curl_setopt($ch , CURLOPT_URL , $url);
25     $res = curl_exec($ch);
26     $ress = json_decode($res);
27      
28     $ress = object_array($ress);
29     //var_dump($ress);
30     //var_dump($ress['showapi_res_body']['prov'],$ress['showapi_res_body']['city'],$ress['showapi_res_body']['name']);
31     echo $ress['showapi_res_body']['prov'].$ress['showapi_res_body']['city'].$ress['showapi_res_body']['name']."<br/>";
32     
33 }

 

posted @ 2016-11-09 16:42  今天、天气晴  阅读(511)  评论(0编辑  收藏  举报