|
12 | 12 |
|
13 | 13 | class AutoController extends Controller
|
14 | 14 | {
|
| 15 | + /** |
| 16 | + * @var Http 请求类 |
| 17 | + */ |
| 18 | + private $http; |
| 19 | + |
| 20 | + public function __construct() |
| 21 | + { |
| 22 | + $this->http = Http::getInstent(); |
| 23 | + } |
15 | 24 | /**
|
16 | 25 | * 获取七牛 Token 的方法
|
17 | 26 | *
|
@@ -43,30 +52,35 @@ public function getToken()
|
43 | 52 | *
|
44 | 53 | * @param Request $request
|
45 | 54 | *
|
46 |
| - * @return array |
| 55 | + * @return \Illuminate\Http\Response |
47 | 56 | */
|
48 | 57 | public function qiniuCallback(Request $request)
|
49 | 58 | {
|
50 | 59 | $uploadRet = $request['upload_ret'];
|
51 | 60 | $ret = base64_decode($uploadRet);
|
52 | 61 | $cbody = json_decode($ret, true);
|
53 | 62 | if (empty($cbody['key'])) {
|
54 |
| - return ['code' => 1, 'data' => [], 'msg' => 'error']; |
| 63 | + // return ['code' => 1, 'data' => [], 'msg' => 'error']; |
| 64 | + return $this->out(1100); |
55 | 65 | }
|
56 | 66 | // 七牛云访问的 url
|
57 | 67 | $dn = env('QINIU_URL');
|
58 | 68 | Log::info('qiniuCallback: ', $cbody); // error_log(print_r($cbody, true));
|
59 | 69 | $url = $dn.$cbody['key'];
|
60 | 70 |
|
61 |
| - $stat_ = file_get_contents($url.'?stat'); |
62 |
| - $stat = json_decode($stat_, true); |
63 |
| - $mtype = $stat['mimeType']; |
64 |
| - if (substr($mtype, 0, 6) == 'image/') { |
| 71 | + // $stat_ = file_get_contents($url.'?stat'); |
| 72 | + // $stat = json_decode($stat_, true); |
| 73 | + |
| 74 | + $stat_get = $this->http->get($url.'?stat', [], 4); |
| 75 | + $stat = json_decode($stat_get['content'], true); |
| 76 | + |
| 77 | + if ($stat && $stat['mimeType'] && substr($stat['mimeType'], 0, 6) == 'image/') { |
65 | 78 | // 3. 调用百度 OCR 识别信息
|
66 | 79 | $words = $this->baiduOCR('', $url);
|
67 |
| - return ['code' => 0, 'data' => ['url' => $url, 'words' => $words], 'msg' => 'success']; |
| 80 | + return $this->out(200, ['url' => $url, 'words' => $words]); |
68 | 81 | }
|
69 |
| - return ['code' => 1, 'data' => [], 'msg' => 'error']; |
| 82 | + |
| 83 | + return $this->out(1100); |
70 | 84 | }
|
71 | 85 |
|
72 | 86 | /**
|
@@ -97,8 +111,8 @@ public function baiduOCR($img, $imgUrl)
|
97 | 111 | return '';
|
98 | 112 | }
|
99 | 113 |
|
100 |
| - $http = new Http(); |
101 |
| - $res = $http->request($url, $bodys, 'POST'); |
| 114 | + // $http = new Http(); |
| 115 | + $res = $this->http->request($url, $bodys, 'POST'); |
102 | 116 |
|
103 | 117 | $result = json_decode($res['content'], true);
|
104 | 118 |
|
|
0 commit comments