php通过手机号查询归属地,使用免费接口,数据量6W+以上

函数名称:get_mobile_area

参数列表:$mobile表示需要查询的手机号

具体实现:

                 function get_mobile_area($mobile){

                        if (empty($mobile)) {

                                 return '';

                        }

                        $url = "http://mobsec-dianhua.baidu.com/dianhua_api/open/location?tel=".$mobile;  

                        $ch = curl_init();  

                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  

                        curl_setopt($ch , CURLOPT_URL , $url);  

                        $res = curl_exec($ch);  

                        $data_arr = json_decode($res,true);  

                       if ($data_arr['responseHeader']['status'] == 200) {

                                  return $data_arr['response'][$mobile]['location'];

                       }

                       return '';

                 }

QQ截图20181015124547.png

猜你喜欢

转载自blog.51cto.com/suyanzhu/2299997
今日推荐