Call to undefined function一直报错,哪位帮解决一下,报错位置一直在这里发起请求的时候

SZH8023 2018-12-28 01:53:12


/**
* 手机号码归属地查询
* @param $tel
* @return string
*/
function getLocation($tel)
{
// 过滤参数
if ( !isPhoneNumber($tel) ) return ['code'=>200,'status'=>false,'msg'=>'Cell phone number error!'];

// 请求地址
$url = 'http://mobsec-dianhua.baidu.com/dianhua_api/open/location?tel='.$tel;

// 发起请求
//$res = file_get_contents($url);
$res = curlRequest($url,'','GET');

if ( $res['code'] !== 200 ) return ['code'=>$res['code'],'status'=>false,'msg'=>$res['responseHeader']['msg']];// 判断请求是否成功

$data = $res['response'][$tel];// 接收返回值

if ( !$data ) return ['code'=>200,'status'=>false,'msg'=>'API Exception!'];// 返回值为空

$response['province'] = $data['detail']['province']; // 归属地
$response['city'] = $data['detail']['area'][0]['city']; // 城市
$response['service'] = $data['detail']['operator']; // 运行商
$response['fullname'] = $data['location']; // 运行商全称

return ['code'=>200,'status'=>true,'data'=>$response];
}

/**
* 手机号码格式验证
* @param $tel
* @return bool
*/
function isPhoneNumber($tel)//手机号码正则表达试
{
return (preg_match("/0?(13|14|15|17|18|19)[0-9]{9}/",$tel))?true:false;
}

/**
* 发起CURL请求
* @param string $url 请求地址
* @param string $data 请求数据
* @param string $method 请求方式
* @return array 一维数组
*/
function curlRequest($url,$data = '',$method = 'POST')
{
$ch = curl_init(); //初始化CURL句柄
curl_setopt($ch, CURLOPT_URL, $url); //设置请求的URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); //设为TRUE把curl_exec()结果转化为字串,而s不是直接输出
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); //设置请求方式

curl_setopt($ch,CURLOPT_HTTPHEADER,array("X-HTTP-Method-Override: $method"));//设置HTTP头信息
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//设置提交的字符串
$document = curl_exec($ch);//执行预定义的CURL
$code = curl_getinfo($ch,CURLINFO_HTTP_CODE); //获取HTTP请求状态码~
curl_close($ch);

$document = json_decode(removeBOM($document),true);
$document['code'] = $code;

return $document;
}

/**
* 检测并移除 BOM 头
* @param string $str 字符串
* @return string 去除BOM以后的字符串
*/
function removeBOM($str = '')
{
if (substr($str, 0,3) == pack("CCC",0xef,0xbb,0xbf)) {
$str = substr($str, 3);
}
return $str;
}

echo "<pre>";
var_dump( getLocation('18888888888') );exit();

作者:贾龙飞
链接:https://www.jianshu.com/p/4c6e7b9b49b3
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
...全文
2216 11 打赏 收藏 举报
写回复
11 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
SZH8023 2018-12-28
引用 9 楼 下雨的声音丶 的回复:
不加,这个分有什么用?

已经结贴了,谢谢你
  • 打赏
  • 举报
回复
SZH8023 2018-12-28
这个分应该是在CSDN里面可以用来买东西的,好吧,现在又换了一个错了,Function name must be a string
  • 打赏
  • 举报
回复
不加,这个分有什么用?
  • 打赏
  • 举报
回复
SZH8023 2018-12-28
引用 7 楼 下雨的声音丶 的回复:


改成 $this->removeBOM($document)

可以加qq?这样太慢了,成功了得分给你 613633484
  • 打赏
  • 举报
回复
改成 $this->removeBOM($document)
  • 打赏
  • 举报
回复
SZH8023 2018-12-28
引用 4 楼 下雨的声音丶 的回复:
你把这个文件放到 public 文件夹下面执行 人家说的 这个App\\Http\\Controllers\\Api\\Common\\removeBOM() 方法不存在,不懂你这个跟问题有啥关系

这些在我本地也是有的
  • 打赏
  • 举报
回复
SZH8023 2018-12-28
引用 4 楼 下雨的声音丶 的回复:
你把这个文件放到 public 文件夹下面执行 人家说的 这个App\\Http\\Controllers\\Api\\Common\\removeBOM() 方法不存在,不懂你这个跟问题有啥关系

这是我本地的项目,发给你的错误是在本地里面
  • 打赏
  • 举报
回复
你把这个文件放到 public 文件夹下面执行 人家说的 这个App\\Http\\Controllers\\Api\\Common\\removeBOM() 方法不存在,不懂你这个跟问题有啥关系
  • 打赏
  • 举报
回复
SZH8023 2018-12-28


引用 1 楼 下雨的声音丶 的回复:

每错呀,你把错误信息发完整

  • 打赏
  • 举报
回复
SZH8023 2018-12-28
引用 1 楼 下雨的声音丶 的回复:

每错呀,你把错误信息发完整


{"config":{"transformRequest":{},"transformResponse":{},"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json;charset=utf-8"},"method":"post","url":"http://szh.s3.natapp.cc/api/v1/common/user/token/phone","data":"{\"phone\":\"18123456789\",\"code\":\"1234\",\"type\":1,\"device_id\":\"352107062467631\",\"device_plat\":1,\"push_id\":\"b9c5a39cd98ca5162c89cce10c25520f\",\"recommend_code\":\"\",\"device_address\":\"昆明市\"}"},"request":{},"response":{"data":{"message":"Call to undefined function App\\Http\\Controllers\\Api\\Common\\removeBOM()","exception":"Symfony\\Component\\Debug\\Exception\\FatalThrowableError","file":"D:\\laragon\\www\\szh.s3.natapp\\app\\Http\\Controllers\\Api\\Common\\SignInController.php","line":40,"trace":[{"file":"D:\\laragon\\www\\szh.s3.natapp\\app\\Http\\Controllers\\Api\\Common\\SignInController.php","line":79,"function":"curlRequest","class":"App\\Http\\Controllers\\Api\\Common\\SignInController","type":"->"},{"function":"phone","class":"App\\Http\\Controllers\\Api\\Common\\SignInController","type":"->"},{"file":"D:\\laragon\\www\\szh.s3.natapp\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Controller.php","line":54,"function":"call_user_func_array"},{"file":"D:\\laragon\\www\\szh.s3.natapp\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\ControllerDispatcher.php","line":45,"function":"callAction","class":"Illuminate\\Routing\\Controller","type":"->"},{"file":"D:\\laragon\\www\\szh.s3.natapp\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php","line":212,"function":"dispatch","class":"Illuminate\\Routing\\ControllerDispatcher","type":"->"},{"file":"D:\\laragon\\www\\szh.s3.natapp\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php","line":169,"function":"runController","class":"Illuminate\\Routing\\Route","type":"->"},{"file":"D:\\laragon\\www\\szh.s3.natapp\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php","line":658,"function":"run","class":"Illuminate\\Routing\\Route","type":"->"},{"file":"D:\\laragon\\www\\szh.s3.natapp\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php","line":30,"function":"Illuminate\\Routing\\{closure}","class":"Illuminate\\Routing\\Router","type":"->"},{"file":"D:\\laragon\\www\\szh.s3.natapp\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Middleware\\SubstituteBindings.php","line":41,"function":"Illuminate\\Routing\\{closure}","class":"Illuminate\\Routing\\Pipeline","type":"->"},{"file":"D:\\laragon\\www\\szh.s3.natapp\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php","line":149,"function":"handle","class":"Illuminate\\Routing\\Middleware\\SubstituteBindings","type":"->"},{"file":"D:\\laragon\\www\\szh.s3.natapp\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php","line":53,"function":"Illuminate\\Pipeline\\{closure}","class":"Illuminate\\Pipeline\\Pipeline","type":"->"},{"file":"D:\\laragon\\www\\szh.s3.natapp\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Middleware\\ThrottleRequests.php","line":57,"function":"Illuminate\\Routing\\{closure}","class":"Illuminate\\Routing\\Pipeline","type":"->"},{"file":"D:\\laragon\\www\\szh.s3.natapp\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php","line":149,"function":"handle","class":"Illuminate\\Routing\\Middleware\\ThrottleRequests","type":"->"},{"file":"D:\\laragon\\www\\szh.s3.natapp\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php","line":53,"function":"Illuminate\\Pipeline\\{closure}","class":"Illuminate\\Pipeline\\Pipeline","type":"->"},{"file":"D:\\laragon\\www\\szh.s3.natapp\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php","line":102,"function":"Illuminate\\Routing\\{closure}","class":"Illuminate\\Routing\\Pipeline","type":"->"},{"file":"D:\\laragon\\www\\szh.s3.natapp\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php","line":660,"function":"then","class

  • 打赏
  • 举报
回复
每错呀,你把错误信息发完整
  • 打赏
  • 举报
回复
相关推荐
发帖
Framework
加入

4247

社区成员

国内外优秀PHP框架讨论学习
社区管理员
  • Framework
申请成为版主
帖子事件
创建了帖子
2018-12-28 01:53
社区公告
暂无公告