首页> 实战笔录 >PHP开发笔记 >PHP PHP

php实现根据手机号获取归属地

作者:小萝卜 2019-03-25 浏览 1857

简介php实现根据手机号获取归属地,php函数,自定义函数,自定义php函数

代码如下:

/**

*根据手机号获取归属地

*@phone:想要查询的手机号

*/

function phonefrom($phone){

    $apiurl = "http://apis.juhe.cn/mobile/get";

    $params = array(

      "key" ="申请的密钥", //这里我用的是聚合数据 网址https://www.juhe.cn/
      "phone" = " $phone " //要查询的手机号码

    );

    $paramsString = http_build_query($params);

    $content = @file_get_contents($apiurl."?".$paramsString);

    $result = json_decode($content,true);

    if($result['error_code'] == '0'){

        return [$result['result']['province'],$result['result']['city']];

    }else{

        return fasle;

    }

}

 

很赞哦! (0)

文章评论

    高端网站建设