165 lines
4.4 KiB
PHP
165 lines
4.4 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace addons\cardocr;
|
||
|
|
||
|
use addons\cardocr\library\Card;
|
||
|
use app\common\library\Menu;
|
||
|
use think\Addons;
|
||
|
use think\Exception;
|
||
|
use think\Loader;
|
||
|
use think\Request;
|
||
|
use think\response\Json;
|
||
|
|
||
|
/**
|
||
|
* 身份证联网认证插件
|
||
|
*/
|
||
|
class Cardocr extends Addons
|
||
|
{
|
||
|
private $menu;
|
||
|
private $name = "cardocr";
|
||
|
|
||
|
public function __construct()
|
||
|
{
|
||
|
parent::__construct();
|
||
|
$menu = [
|
||
|
[
|
||
|
'name' => 'cardocr',
|
||
|
'title' => '身份证验证管理',
|
||
|
'icon' => 'fa fa-address-book',
|
||
|
'sublist' => [
|
||
|
[
|
||
|
'name' => 'cardocr/card',
|
||
|
'title' => '身份证验证',
|
||
|
'icon' => 'fa fa-id-card',
|
||
|
'sublist' => [
|
||
|
['name' => 'cardocr/card/index', 'title' => '查看'],
|
||
|
['name' => 'cardocr/card/add', 'title' => '添加'],
|
||
|
['name' => 'cardocr/card/edit', 'title' => '修改'],
|
||
|
['name' => 'cardocr/card/del', 'title' => '删除'],
|
||
|
['name' => 'cardocr/card/multi', 'title' => '批量更新'],
|
||
|
]
|
||
|
],
|
||
|
|
||
|
]
|
||
|
]
|
||
|
];
|
||
|
|
||
|
$this->menu = $menu;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 插件安装方法
|
||
|
* @return bool
|
||
|
*/
|
||
|
public function install()
|
||
|
{
|
||
|
Menu::create($this->menu);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 插件卸载方法
|
||
|
* @return bool
|
||
|
*/
|
||
|
public function uninstall()
|
||
|
{
|
||
|
Menu::delete($this->name);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 插件启用方法
|
||
|
* @return bool
|
||
|
*/
|
||
|
public function enable()
|
||
|
{
|
||
|
Menu::enable($this->name);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 插件禁用方法
|
||
|
* @return bool
|
||
|
*/
|
||
|
public function disable()
|
||
|
{
|
||
|
Menu::disable($this->name);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
/** 检查身份证号码与姓名是一致钩子
|
||
|
* @param array $checkdata ['name'];$checkdata["idnum"]
|
||
|
* @return json
|
||
|
*/
|
||
|
public function checkIdname($checkdata)
|
||
|
{
|
||
|
$arr['time'] = time();
|
||
|
if(!isset($checkdata["name"])) {
|
||
|
return json(['code'=>400,'msg'=>'姓名不能缺少'],400);
|
||
|
}
|
||
|
|
||
|
if(!isset($checkdata["idnum"])) {
|
||
|
return json(['code'=>400,'msg'=>'身份证号码不能缺少'],400);
|
||
|
}
|
||
|
|
||
|
$data = Card::checkidcard($checkdata["idnum"],$checkdata["name"]);
|
||
|
return json(array_filter($data));
|
||
|
|
||
|
}
|
||
|
|
||
|
/** 身份证识别钩子
|
||
|
* @param array $array $data['ImageBase64'] = $ImageBase64;$data['CardSide'] = 'FRONT';
|
||
|
* 传入例子 checkOcr($data, $data['CardSide'])
|
||
|
* @param array $array ['CardSide'] |'FRONT','BACK' 识别身份证正反
|
||
|
* @return json
|
||
|
*/
|
||
|
public function checkOcr($arrjson)
|
||
|
{
|
||
|
$arr['time'] = time();
|
||
|
if(!isset($arrjson["ImageBase64"])) {
|
||
|
return json(['code'=>400,'msg'=>'身份证缺少ImageBase64'],400);
|
||
|
}
|
||
|
|
||
|
if(!preg_match('/^data:image\/(png|jpeg|gif);base64,/', $arrjson['ImageBase64'])){
|
||
|
return json(['code'=>400,'msg'=>'ImageBase64参数不是ImageBase64 格式'],400);
|
||
|
}
|
||
|
if(!isset($arrjson["CardSide"]) ){
|
||
|
return json(['code'=>400,'msg'=>'身份证缺少正反面参数'],400);
|
||
|
}
|
||
|
|
||
|
if($arrjson["CardSide"]!='FRONT' && $arrjson["CardSide"]!='BACK' ){
|
||
|
return json(['code'=>400,'msg'=>'身份证正反面参数不符合'],400);
|
||
|
}
|
||
|
|
||
|
$data = Card::checkcardocr(json_encode($arrjson), $arrjson['CardSide']);
|
||
|
return json(array_filter($data));
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 添加命名空间
|
||
|
*/
|
||
|
public function appInit()
|
||
|
{
|
||
|
//添加支付包的命名空间
|
||
|
Loader::addNamespace('TencentCloud', ADDON_PATH . 'cardocr' . DS . 'library' . DS . 'TencentCloud' . DS);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 会员中心边栏后
|
||
|
* @return mixed
|
||
|
* @throws \Exception
|
||
|
*/
|
||
|
public function userSidenavAfter()
|
||
|
{
|
||
|
$request = Request::instance();
|
||
|
$controllername = strtolower($request->controller());
|
||
|
$actionname = strtolower($request->action());
|
||
|
$data = [
|
||
|
'actionname' => $actionname,
|
||
|
'controllername' => $controllername
|
||
|
];
|
||
|
return $this->fetch('view/hook/user_sidenav_after', $data);
|
||
|
}
|
||
|
}
|