You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong/app/api/service/Ocr.php

67 lines
2.0 KiB

8 months ago
<?php
declare (strict_types=1);
namespace app\api\service;
use app\api\service\User as UserService;
use app\common\library\baidu\OcrCard;
use app\common\library\baidu\OcrLicense;
use app\common\service\BaseService;
use cores\exception\BaseException;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
class Ocr extends BaseService
{
/**
* @notes:获取配置
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
/**
* @notes:
* @param string $img_url //证件地址 可外网访问的
* @param int $type //1 正面 2反面
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException|BaseException
* @author: wanghousheng
*/
public static function checkCard(string $img_url, int $type = 1): array
{
// 当前用户ID
UserService::getCurrentLoginUserId();
$config = Setting::getOcr();
$clientSecret = !empty($config['secret_key']) ? $config['secret_key'] : '';
$clientId = !empty($config['access_key']) ? $config['access_key'] : '';
$obj = new OcrCard($clientId, $clientSecret);
return $obj->checkCard($img_url, $type);
}
/**
* @notes:营业执照识别
* @param string $img_url
* @return array
* @throws BaseException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
public static function checkLicense(string $img_url): array
{
// 当前用户ID
UserService::getCurrentLoginUserId();
$config = Setting::getOcr();
$clientSecret = !empty($config['secret_key']) ? $config['secret_key'] : '';
$clientId = !empty($config['access_key']) ? $config['access_key'] : '';
$obj = new OcrLicense($clientId, $clientSecret);
return $obj->check($img_url);
}
}