Merge branch 'dev' of wmtx/sdk into master

成年人实名信息不允许更改成未成年
master
张谷诚 5 years ago committed by Gogs
commit 30e7ec6ef7

@ -1177,11 +1177,21 @@ function think_psw_md5($str, $key = 'ThinkUCenter')
}
//对年龄的审核
function age_verify($cardno, $name)
function age_verify($cardno, $name, $user_id = '')
{
$date = age($cardno, $name);
$info = '';
$date = age($cardno, $name, $info);
$arr['name'] = $name;
$arr['id_card'] = $cardno;
$arr['user_id'] = $user_id;
$arr['ip'] = get_client_ip();
$arr['create_time'] = time();
$arr['info'] = $info;
if ($date['status'] == '01') {
$arr['status'] = 1;
M('idcard_log', 'tab_')->data($arr)->add();
$age = floor((time() - strtotime($date['birthday'])) / (60 * 60 * 24 * 365));
if ($age > 17) {
return 1;
@ -1189,47 +1199,55 @@ function age_verify($cardno, $name)
return 2;
}
} elseif (isset($date['status']) && $date['status'] != '01') {
$arr['status'] = 0;
M('idcard_log', 'tab_')->data($arr)->add();
return 0;
} elseif(!isset($date['status']) && $date == 0) {
$arr['status'] = 0;
M('idcard_log', 'tab_')->data($arr)->add();
return 0;
} else {
$arr['status'] = -1;
M('idcard_log', 'tab_')->data($arr)->add();
return $date;
}
}
//根据配置向接口发送身份证号和姓名进行验证
function age($cardno, $name)
function age($cardno, $name, &$info)
{
$host = "https://idcardcert.market.alicloudapi.com";
$path = "/idCardCert";
$method = "GET";
$appcode = "244181f0846541a19e24df409736d3b9";
$headers = array();
array_push($headers, "Authorization:APPCODE " . $appcode);
$querys = "idCard={$cardno}&name={$name}";
$bodys = "";
$url = $host . $path . "?" . $querys;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
//curl_setopt($curl, CURLOPT_HEADER, true); 如不输出json, 请打开这行代码,打印调试头部状态码。
//状态码: 200 正常400 URL无效401 appCode错误 403 次数用完; 500 API网管错误
if (1 == strpos("$".$host, "https://"))
{
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
$output = curl_exec($curl);
if (empty($output)) {
return -1;//用完
}
$r = json_decode($output, true);
if ($r['status'] == "02") return 0;
$host = "https://idcardcert.market.alicloudapi.com";
$path = "/idCardCert";
$method = "GET";
$appcode = "244181f0846541a19e24df409736d3b9";
$headers = array();
array_push($headers, "Authorization:APPCODE " . $appcode);
$querys = "idCard={$cardno}&name={$name}";
$bodys = "";
$url = $host . $path . "?" . $querys;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
//curl_setopt($curl, CURLOPT_HEADER, true); 码。
//状态码: 200 正常400 URL无效401 appCode错如不输出json, 请打开这行代码,打印调试头部状态误; 403 次数用完; 500 API网管错误
if (1 == strpos("$".$host, "https://"))
{
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
$output = curl_exec($curl);
$info = $output;
if (empty($output)) {
return -1;//用完
}
$r = json_decode($output, true);
if ($r['status'] == "02") return 0;
return $r;
}

@ -14,7 +14,7 @@ use Sdk\Controller\BaseController;
* @param sting $idcard 身份证号码
* @author 鹿文学
*/
function is_adult($idcard, $adult=16) {
function is_adult($idcard, $adult=18) {
$id = substr($idcard,6,8);
$year = substr($id,0,4);

@ -2155,7 +2155,6 @@ class UserController extends BaseController
C(api('Config/lists'));
$user = json_decode(base64_decode(file_get_contents("php://input")), true);
if (empty($user['user_id']) || empty($user['idcard']) || empty($user['real_name'])) {
$this -> set_message(1066, "fail", "用户数据异常");
}
@ -2180,6 +2179,10 @@ class UserController extends BaseController
}
}
$userinfo = M('User', 'tab_')->where(['id' => $user['user_id']])->find();
if(!empty($userinfo['idcard']) && is_adult($userinfo['idcard']) && !is_adult($user['idcard'])) {
$this -> set_message(1086, "fail", "您的账户已经是成年账户,不能再修改成为未成年账户");
}
//身份证认证
if (C('tool_age.status') == 0) {
if (is_adult($data['idcard'])) {
@ -2188,9 +2191,10 @@ class UserController extends BaseController
$data['age_status'] = 3; // 未成年
}
} else {
$model = M('idcard_log', 'tab_')->where(['name' => $data['real_name'],'id_card' => $data['idcard']])->find();
if(!empty($model)) {
$model = M('idcard_log', 'tab_')->where(['name' => $data['real_name'],'id_card' => $data['idcard']])->order('id DESC')->find();
if(!empty($model) && $model['status'] != '-1') {
$arr['num'] = $model['num']+1;
M('idcard_log', 'tab_')->where(['id' => $model['id']])->save($arr);
if($model['status'] == 1) {
$data['age_status'] = is_adult($data['idcard']) ? 2 : 3;
@ -2198,17 +2202,17 @@ class UserController extends BaseController
$this -> set_message(1069, "fail", "用户数据不匹配");
}
} else {
$re = age_verify($data['idcard'], $data['real_name']);
if($re != -1)
{
$arr['name'] = $data['real_name'];
$arr['id_card'] = $data['idcard'];
$arr['user_id'] = $user['user_id'];
$arr['status'] = ($re == 1 || $re == 2 ) ? 1 : 0;
$arr['ip'] = get_client_ip();
$arr['create_time'] = time();
M('idcard_log', 'tab_')->data($arr)->add();
}
$re = age_verify($data['idcard'], $data['real_name'], $user['user_id']);
// if($re != -1)
// {
// $arr['name'] = $data['real_name'];
// $arr['id_card'] = $data['idcard'];
// $arr['user_id'] = $user['user_id'];
// $arr['status'] = ($re == 1 || $re == 2 ) ? 1 : 0;
// $arr['ip'] = get_client_ip();
// $arr['create_time'] = time();
// M('idcard_log', 'tab_')->data($arr)->add();
// }
switch ($re) {
case - 1:

Loading…
Cancel
Save