接口:https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=13526527733
public function getProviceBymobile($mobile)
{
$url = "https://tcc.taobao.com/cc/json/mobile_tel_segment.htm";
$curl = new Curl();
// $curl->setHeaders("Content-type:text/html;charset=UTF-8");
$curl->get($url, ['tel' => $mobile]);
$str1 = $this->str_to_utf8($curl->response);
$str1 = preg_replace('# #', '', $str1);
$start = strpos($str1,"=")+1;
// $str1 = "\"".substr($str1,$start)."\"";
$str1 = substr($str1,$start);
// echo $str1;die();
$str1 = "{ mts:'15136469515', province:'河南', catName:'中国联通', telString:'15136469515', areaVid:'30500', ispVid:'137815084', carrier:'河南联通' } ";
$str1 = str_replace("'","\"", $str1);
// echo $str1;die();
$re = $this->ext_json_decode($str1,true);
$province = $re['province'];
return $province;
}
public function str_to_utf8 ($str = '')
{
$encode = mb_detect_encoding($str, array("ASCII",'UTF-8',"GB2312","GBK",'BIG5'));
// var_dump($encode);die();
if($encode == 'UTF-8'){
return $str;
}else{
return mb_convert_encoding($str, 'UTF-8', $encode);
}
}
public function ext_json_decode($str, $mode=true)
{
if(preg_match('/\w:/', $str)){
$str = preg_replace('/(\w+):/is', '"$1":', $str);
}
return json_decode($str, $mode);
}
/**
*
* 把对象转成数组
* @param $object 要转的对象$object
*/
public function objectToArray($object){
$object = json_decode( json_encode( $object),true);
return $object;
}
结果:
_GetZoneResult = {
mts:‘1352652’,
province:‘河南’,
catName:‘中国移动’,
telString:‘13526527733’, areaVid:‘30500’, ispVid:‘3236139’, carrier:‘河南移动’ }