1 个管道
的构建
通过
耗费
17 秒
后台数管结果问题修改,数管识别接口优化
正在显示
2 个修改的文件
包含
21 行增加
和
27 行删除
@@ -132,6 +132,7 @@ class Shuguan extends Backend | @@ -132,6 +132,7 @@ class Shuguan extends Backend | ||
132 | $map = [ | 132 | $map = [ |
133 | 'shuguan_id' => $row->id | 133 | 'shuguan_id' => $row->id |
134 | ]; | 134 | ]; |
135 | + $this->dataLimit = false; | ||
135 | $this->model = $this->shuguan_log_model; | 136 | $this->model = $this->shuguan_log_model; |
136 | list($where, $sort, $order, $offset, $limit) = $this->buildparams(); | 137 | list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
137 | $total = $this->shuguan_log_model | 138 | $total = $this->shuguan_log_model |
@@ -322,12 +322,13 @@ class App extends Api | @@ -322,12 +322,13 @@ class App extends Api | ||
322 | $param['key'] = $key; | 322 | $param['key'] = $key; |
323 | $param['image_id'] = $image_id; | 323 | $param['image_id'] = $image_id; |
324 | $param['sign'] = $this->getSign($param); | 324 | $param['sign'] = $this->getSign($param); |
325 | - $result = $this->httpPost($url,$param); | 325 | + list($http_code,$body) = $this->httpPost($url,$param); |
326 | 326 | ||
327 | - file_put_contents('a.txt',print_r($result,true),FILE_APPEND); | ||
328 | - file_put_contents('a.txt','\r\n',FILE_APPEND); | 327 | + if($http_code != 200) { |
328 | + $this->error('数管识别返回失败','',$http_code); | ||
329 | + } | ||
329 | 330 | ||
330 | - $data = json_decode($result,true); | 331 | + $data = json_decode($body,true); |
331 | Db::startTrans(); | 332 | Db::startTrans(); |
332 | //保存数管信息 | 333 | //保存数管信息 |
333 | $arr = [ | 334 | $arr = [ |
@@ -368,25 +369,7 @@ class App extends Api | @@ -368,25 +369,7 @@ class App extends Api | ||
368 | } | 369 | } |
369 | } | 370 | } |
370 | Db::commit(); | 371 | Db::commit(); |
371 | - $this->success('SUCCESS',$result); | ||
372 | - } | ||
373 | - | ||
374 | - /** | ||
375 | - * 模拟调用 | ||
376 | - */ | ||
377 | - private function test(){ | ||
378 | - dump(getAddress("N39.085660E117.068135")); | ||
379 | - exit(); | ||
380 | - $url = "http://gangjuren.net/api/app/getImageInfo"; | ||
381 | - $arr = [ | ||
382 | - 'url' => "http://company.zzspjob.com/6b408e79f3a21ac02746b218f6cbc99@3x.png", | ||
383 | - 'app_id' => 'gjra2g11dg56ad7bb71', | ||
384 | - 'customer_id' => '1', | ||
385 | - 'access_token' => 'e508a6c25ed2ec1237fa8a0ba8a09357ff83b8c8', | ||
386 | - 'image_id' => '1', | ||
387 | - ]; | ||
388 | - $result = $this->httpPost($url,$arr); | ||
389 | - $this->success('',$result); | 372 | + $this->success('SUCCESS',$body); |
390 | } | 373 | } |
391 | 374 | ||
392 | /** | 375 | /** |
@@ -421,14 +404,24 @@ class App extends Api | @@ -421,14 +404,24 @@ class App extends Api | ||
421 | curl_setopt($curl, CURLOPT_POST, true); // 发送一个常规的Post请求 | 404 | curl_setopt($curl, CURLOPT_POST, true); // 发送一个常规的Post请求 |
422 | curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包 | 405 | curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包 |
423 | //curl_setopt($curl, CURLOPT_TIMEOUT, 120); // 设置超时限制防止死循环 | 406 | //curl_setopt($curl, CURLOPT_TIMEOUT, 120); // 设置超时限制防止死循环 |
424 | - curl_setopt($curl, CURLOPT_HEADER, false); // 显示返回的Header区域内容 | 407 | + curl_setopt($curl, CURLOPT_HEADER, true); // 显示返回的Header区域内容 |
425 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回 | 408 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回 |
426 | $result = curl_exec($curl); // 执行操作 | 409 | $result = curl_exec($curl); // 执行操作 |
427 | if (curl_errno($curl)) { | 410 | if (curl_errno($curl)) { |
428 | - echo 'Error POST'.curl_error($curl); | ||
429 | - } | 411 | + return curl_error($curl); |
412 | + } | ||
413 | + // 获得响应结果里的:头大小 | ||
414 | + $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE); | ||
415 | + $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); | ||
416 | + // 根据头大小去获取body信息内容 | ||
417 | + $header = substr($result,0,$headerSize); | ||
418 | + file_put_contents('b.txt',print_r(['time' => date('Y-m-d H:i:s',time()), 'content' => $header],true),FILE_APPEND); | ||
419 | + file_put_contents('b.txt','\r\n',FILE_APPEND); | ||
420 | + $body = substr($result,$headerSize,strlen($result)-$headerSize); | ||
421 | + file_put_contents('a.txt',print_r(['time' => date('Y-m-d H:i:s',time()), 'content' => $body],true),FILE_APPEND); | ||
422 | + file_put_contents('a.txt','\r\n',FILE_APPEND); | ||
430 | curl_close($curl); // 关键CURL会话 | 423 | curl_close($curl); // 关键CURL会话 |
431 | - return $result; // 返回数据 | 424 | + return array($http_code,$body); // 返回数据 |
432 | } | 425 | } |
433 | 426 | ||
434 | /** | 427 | /** |
-
请 注册 或 登录 后发表评论