Laravel7根据手机号请求第三方接口获取手机号的运营商和归属地
第三方接口
https://www.baifubao.com/callback?cmd=1059&callback=phone&phone=137****9935
得到的结果是
返回的结果是json格式,但是我们需要做一些处理来转换为数组
public static function getHttpMobile($mobile='137****9935',$header=[])
{
$client = new \GuzzleHttp\Client();
$res = $client->request('GET', 'https://www.baifubao.com/callback?cmd=1059&callback=phone&phone='.$mobile,['headers' => $header]);
$header= $res->getHeader('content-type');
$data = $res->getBody()->getContents();
$str = str_replace('/*fgg_again*/phone(','',$data);
$data = json_decode(substr($str, 0, -1),true);
return $data;
}
还不快抢沙发