Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
chenbo 2023-10-20 10:47:03 +08:00
commit 60defd526b

View File

@ -377,10 +377,11 @@ class XunFeiController extends BaseApiController
public function ocr() public function ocr()
{ {
$ocrHostUrl = "https://api.xf-yun.com/v1/private/sf8e6aca1"; $ocrHostUrl = "https://api.xf-yun.com/v1/private/sf8e6aca1";
$file = request()->file('image'); $file = request()->param('image');
if (empty($file)) { if (empty($file)) {
return $this->fail('未上传图片文件'); return $this->fail('未上传图片文件');
} }
/*
// 上传图片临时文件 // 上传图片临时文件
$savename = \think\facade\Filesystem::putFile('ocr', $file); $savename = \think\facade\Filesystem::putFile('ocr', $file);
$file = app()->getRootPath() . '/runtime/storage/' . $savename; $file = app()->getRootPath() . '/runtime/storage/' . $savename;
@ -391,12 +392,9 @@ class XunFeiController extends BaseApiController
if ($filesize > 4 * 1024 * 1024) { if ($filesize > 4 * 1024 * 1024) {
return $this->fail('图片文件不能超过4M'); return $this->fail('图片文件不能超过4M');
} }
*/
$ext = pathinfo($file, PATHINFO_EXTENSION); $ext = pathinfo($file, PATHINFO_EXTENSION);
$base64_image = base64_encode(file_get_contents($file)); $base64_image = base64_encode(file_get_contents($file));
if (file_exists($file)) {
// 删除临时文件
unlink($file);
}
$ocr = new OcrClient($this->app_id, $this->api_key, $this->api_secret); $ocr = new OcrClient($this->app_id, $this->api_key, $this->api_secret);
$ocrHostUrl = $ocr->assembleAuthUrl($ocrHostUrl); $ocrHostUrl = $ocr->assembleAuthUrl($ocrHostUrl);
$requestBody = [ $requestBody = [
@ -424,7 +422,7 @@ class XunFeiController extends BaseApiController
]; ];
$text = []; $text = [];
try { try {
$client = new GzClient(['timeout' => 2]); $client = new GzClient(['timeout' => 5]);
$response = $client->request('POST', $ocrHostUrl, [ $response = $client->request('POST', $ocrHostUrl, [
'json' => $requestBody, 'json' => $requestBody,
'verify' => false 'verify' => false