欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

批量在线查询手机号码归属地信息,淘宝接口,实时更新。外行作品,大牛完善

程序员文章站 2022-05-02 10:37:31
...
php代码
<?php
$handle = fopen("tel.txt", "r");
if ($handle) {
    //打开要写入的文件对象
   
    while (!feof($handle)) {
        $buffer = fgets($handle, 4096);
		$content = get_mobile_area(trim($buffer));
		echo "手机号:   ".$buffer."		归属地:   ".$content.'<br/>';
		if(strpos($content,'北京') !== false){
			 $file=fopen("北京.txt","a+");
			 fwrite($file,trim($buffer)."	".$content."\n");
			 fclose($file);
			}else if(strpos($content,'上海') !== false){
				 $file1=fopen("上海.txt","a+");
				 fwrite($file1,trim($buffer)."	".$content."\n");
				 fclose($file1);
				}else{
					 $file2=fopen("外省.txt","a+");
					 fwrite($file2,trim($buffer)."	".$content."\n");
					 fclose($file2);
					}

		
		
		
	    
    }
    
    fclose($handle);
}

function get_mobile_area($mobile){ 
if($mobile!=''){
    $sms = array('province'=>'', 'supplier'=>'');    //初始化变量 
    //根据淘宝的数据库调用返回值 
    $url = "http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=".$mobile."&t=".time(); 

    $contents = file_get_contents($url); 

    $sms['province'] = substr($contents, "56", "4");  //截取字符串 
    $sms['supplier'] = substr($contents, "81", "4"); 

    return $sms['province']."	".$sms['supplier'];
	
	}
} 
?>