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

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

PHP中文网
PHP中文网原创
2016-05-26 08:21:081552浏览

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.&#39;<br/>&#39;;
		if(strpos($content,&#39;北京&#39;) !== false){
			 $file=fopen("北京.txt","a+");
			 fwrite($file,trim($buffer)."	".$content."\n");
			 fclose($file);
			}else if(strpos($content,&#39;上海&#39;) !== 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!=&#39;&#39;){
    $sms = array(&#39;province&#39;=>&#39;&#39;, &#39;supplier&#39;=>&#39;&#39;);    //初始化变量 
    //根据淘宝的数据库调用返回值 
    $url = "http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=".$mobile."&t=".time(); 

    $contents = file_get_contents($url); 

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

    return $sms[&#39;province&#39;]."	".$sms[&#39;supplier&#39;];
	
	}
} 
?>
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn