Files
liche/api/controllers/wxapp/licheb/Idcard.php
T
2021-07-22 10:01:41 +08:00

111 lines
4.1 KiB
PHP

<?php
defined('WXAPP_APP') OR exit('No direct script access allowed');
/**
* Created by Vim
* Desc: 身份证图片识别
* User: lcc
* Date: 2021/07/16
* Time: 14:08
*/
require_once APPPATH.'controllers/wxapp/Wxapp.php';
class Idcard extends Wxapp{
public function __construct($inputs, $app_key){
parent::__construct($inputs, $app_key);
$this->login_white = array();//登录白名单
$this->check_status = array();//用户状态校验
$this->check_mobile = array();//需要手机号
$this->check_headimg =array();//授权微信信息
$this->load->model('receiver/order/receiver_order_loans_model','order_loans_model');
$this->load->model('receiver/order/receiver_orders_model','orders_model');
$this->load->model('receiver/order/receiver_order_bills_model','order_bills_model');
}
protected function put(){
$id = $this->input_param('id');
$cardidA = $this->input_param('cardidA');
$cardidB = $this->input_param('cardidB');
$row = $this->order_bills_model->get(['id'=>$id]);
if(!$row || !$cardidA || !$cardidB){
throw new Exception('参数错误', ERR_PARAMS_ERROR);
}
$full_cardidA = build_qiniu_image_url($cardidA);
$jsondata = json_decode($row['jsondata'],true);
$this->load->library('TcOrc');
$result = $this->tcorc->IdentityCard($full_cardidA);
if(!$result['code']){
$res_data['code'] = API_CODE_ORC_FAIL;
$res_data['data'] = [
['caridA' => false,'errmsg'=>$result['msg']],
['caridB' => true,'errmsg'=>''],
];
return $res_data;
}
$userinfo = $result['data'];
$jsondata['cardidA']['data'] = $userinfo;
$update = [
'cardidA' => $cardidA,
'cardidB' => $cardidB,
'c_time' => time()
];
$jsondata && $update['jsondata'] = json_encode($jsondata,JSON_UNESCAPED_UNICODE);
$result = $this->order_bills_model->update($update,['id'=>$row['id']]);
if($result){
$this->load->library('receiver/orders_entity');
$this->orders_entity->up_info($row['o_id'],$userinfo);
throw new Exception('修改成功', API_CODE_SUCCESS);
}else{
throw new Exception('修改失败', ERR_PARAMS_ERROR);
}
}
protected function post(){
$oid = $this->input_param('oid');
$cardidA = $this->input_param('cardidA');
$cardidB = $this->input_param('cardidB');
$bill = $this->order_bills_model->count(['o_id'=>$oid]);
if($bill){
throw new Exception('创建失败', ERR_PARAMS_ERROR);
}
$row = $this->orders_model->get(['id'=>$oid]);
if(!$row || !$cardidA || !$cardidB){
throw new Exception('参数错误', ERR_PARAMS_ERROR);
}
$full_cardidA = build_qiniu_image_url($cardidA);
$jsondata = json_decode($row['jsondata'],true);
$this->load->library('TcOrc');
$result = $this->tcorc->IdentityCard($full_cardidA);
if(!$result['code']){
$res_data['code'] = API_CODE_ORC_FAIL;
$res_data['data'] = [
['caridA' => false,'errmsg'=>$result['msg']],
['caridB' => true,'errmsg'=>''],
];
return $res_data;
}
$userinfo = $result['data'];
$jsondata['cardidA']['data'] = $userinfo;
$add_data = [
'o_id' => $oid,
'cardidA' => $cardidA,
'cardidB' => $cardidB,
'c_time' => time()
];
$jsondata && $update['jsondata'] = json_encode($jsondata,JSON_UNESCAPED_UNICODE);
$l_id = $this->order_bills_model->add($add_data);
if($l_id){
$this->load->library('receiver/orders_entity');
$this->orders_entity->up_info($oid,$userinfo);
$data = [
'id' => $l_id,
];
return $data;
}else{
throw new Exception('创建失败', ERR_PARAMS_ERROR);
}
}
}