根据手机号判断运营商

具体代码以下:php

<?phpjson

//根据手机号获取运营商信息(淘宝API)
/*返回数据信息
Array
(
    [mts] => 1316184
    [province] => 北京
    [catName] => 中国联通
    [telString] => 1316184xxxx
    [areaVid] => 29400
    [ispVid] => 137815084
    [carrier] => 北京联通
)
*/
function getOperatorByMoblieInTB($moblie=''){
    if(empty($moblie)){
        return 'moblie is empty!';
    }
    $url = 'https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=';
    $api_url = $url.$moblie;
    $s = file_get_contents($api_url);
    preg_match_all("/(\w+):'([^']+)/", $s, $m);
    $a = array_combine($m[1], $m[2]);
    return $a;
}api

//根据手机号获取运营商信息(360API)
/*返回数据信息
Array
(
    [code] => 0
    [data] => Array
        (
            [province] => 北京
            [city] => 北京
            [sp] => 联通
        )url

)
*/
function getOperatorByMoblieIn360($moblie=''){
    if(empty($moblie)){
        return 'moblie is empty!';
    }
    $url = 'http://cx.shouji.360.cn/phonearea.php?number=';
    $api_url = $url.$moblie;
    $res = file_get_contents($api_url);
    $res = json_decode($res,1);
    return $res;
}code

相关文章
相关标签/搜索