| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\client\controllers\v1;
- use app\modules\client\controllers\BaseController;
- use app\utils\Ocr\OcrApi;
- class OcrController extends BaseController
- {
- /**
- * 获取信息
- * @return \yii\web\Response
- */
- public function actionInfo() {
- $type = post_params('type');
- if (empty($type) || !in_array($type, OcrApi::$validType)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '类型参数错误'
- ]);
- }
- $side = post_params('side');
- if (empty($side) && $type == OcrApi::TYPE_ID_CARD) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '身份证参数有误'
- ]);
- }
- $url = post_params('url');
- if (empty($url)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '图片地址为空'
- ]);
- }
- try {
- $ocr = new OcrApi();
- switch ($type) {
- case OcrApi::TYPE_LICENSE:
- $res = $ocr->getBusinessLicense($url);
- break;
- case OcrApi::TYPE_ID_CARD:
- $res = $ocr->getIDCard($url, $side);
- break;
- case OcrApi::TYPE_BANK:
- $res = $ocr->getBankCard($url);
- break;
- case OcrApi::TYPE_TEXT:
- $res = $ocr->getTextRecognition($url, 1);
- break;
- }
- if ($res['code'] == 0 && !empty($res['data'])) {
- return $this->asJson($res);
- }
- return $this->asJson([
- 'code' => 1,
- 'msg' => '获取信息失败'
- ]);
- } catch (\Exception $e) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage()
- ]);
- }
- }
- }
|