2023-05-12 开启多语言插件支持……

php 通过请求webservice服务 判断手机号码归属地

php 苏 demo 2019℃ 0评论

php 获取到的指定的手机号码,需要判断手机号码的归属地。

/**
 * 获取手机归属地
 * @param $mobile
 * @return array
 */
function get_mobile_belongs($mobile){
    $type   = 'text';
    $url    = "http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo";

    header("Content-Type:text/html;charset=utf-8");
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "mobileCode={$mobile}&userId=");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $data = curl_exec($ch);
    curl_close($ch);
    $data =simplest_xml_to_array($data);

    $result = array();
    $arr = explode(":",$data['0']);

    if(!empty($arr[1])){
        $arr_second = explode(" ",$arr[1]);
    }

    $result['mobile']   = $arr['0'];
    $result['province'] = $arr_second['0'];
    $result['city']     = $arr_second['1'];
    $result['isp']      = $arr_second['2'];

    return $result;
}

代码用例:

$mobile = '131********;
$belongs = json_encode(get_mobile_belongs($mobile));

返回结果:

 

 

打赏

转载请注明:苏demo的别样人生 » php 通过请求webservice服务 判断手机号码归属地

   如果本篇文章对您有帮助,欢迎向博主进行赞助,赞助时请写上您的用户名。
支付宝直接捐助帐号oracle_lee@qq.com 感谢支持!
喜欢 (0)or分享 (0)