瀏覽代碼

实名验证调整

zhangxiaobin 1 年之前
父節點
當前提交
2508a5463d

+ 26 - 8
application/api/controller/User.php

@@ -7,6 +7,7 @@ use app\common\library\Ems;
 use app\common\library\Sms;
 use app\common\service\UserService;
 use fast\Random;
+use think\Exception;
 use think\Validate;
 use miniprogram\wxBizDataCrypt;
 use onlogin\onlogin;
@@ -916,8 +917,8 @@ class User extends Api
     public function realauth()
     {
         try {
-            $realName = $this->request->param('real_name',0);
-            $idCard   = $this->request->param('id_card',0);
+            $realName = $this->request->param('real_name','');
+            $idCard   = $this->request->param('id_card','');
             if ($this->auth->is_auth == 2) {
                 $this->error('您已经真人认证过了~');
             }
@@ -927,7 +928,7 @@ class User extends Api
             if (empty($idCard)) {
                 throw new Exception('请输入身份证号');
             }
-            $userService = new UserService();
+            /*$userService = new UserService();
             $faceParams = [
                 'real_name' => $realName,
                 'id_card' => $idCard,
@@ -951,8 +952,26 @@ class User extends Api
                 'status' => 0,
                 'createtime' => time(),
                 'updatetime' => time()
+            ];*/
+            $userService = new UserService();
+            $aliParams = [
+                'id_card' => $idCard,
+                'real_name' => $realName,
+            ];
+            $aliCheckRes = $userService->aliCheck($aliParams);
+            if (!$aliCheckRes['status']) {
+                throw new Exception($aliCheckRes['msg']);
+            }
+            $user_auth = [
+                'user_id' => $this->auth->id,
+                'realname' => $realName,
+                'idcard' => $idCard,
+                'certify_id' => '',
+                'out_trade_no' => '',
+                'status' => 0,
+                'createtime' => time(),
+                'updatetime' => time()
             ];
-
             //开启事务
             Db::startTrans();
             //查询是否认证过
@@ -974,15 +993,14 @@ class User extends Api
             }
 
             Db::commit();
-
-            $return_data = [
+            /*$return_data = [
                 'face_id' => $user_auth['certify_id'],
                 'order_no' => $user_auth['out_trade_no'],
                 'user_id' => (string)$this->auth->id,
                 'nonce' => $rs['nonce'],
                 'sign' => $rs['sign'],
-            ];
-            $this->success('success', $return_data);
+            ];*/
+            $this->success('验证成功');
         } catch (Exception $e) {
             $this->error($e->getMessage());
         }

+ 1 - 1
application/api/controller/Usersign.php

@@ -126,7 +126,7 @@ class Usersign extends Api
         }
 
         //系统消息
-        $msg_id = \app\common\model\Message::addMessage($this->auth->id,'签到奖励','签到成功,获得金币奖励');
+        $msg_id = \app\common\model\Message::addMessage($this->auth->id,'签到奖励','签到成功,获得奖励');
 
         Db::commit();
         $result = [

+ 54 - 0
application/common/service/UserService.php

@@ -85,4 +85,58 @@ class UserService
         }
         return $result;
     }
+
+    /**
+     * 阿里实名认证二要素
+     * https://market.aliyun.com/products/57000002/cmapi026109.html
+     * @return void
+     */
+    public function aliCheck($params=[])
+    {
+        $result = [
+            'status' => 1,
+            'msg' => '',
+            'data' => [],
+        ];
+        try {
+            $idCard = isset($params['id_card']) ? $params['id_card'] : '';
+            $realName = isset($params['real_name']) ? $params['real_name'] : '';
+            $aliyunConfig = config('ali_yun');
+            $host = "https://eid.shumaidata.com";
+            $path = "/eid/check";
+            $method = "POST";
+            $appcode = isset($aliyunConfig['app_code']) ? $aliyunConfig['app_code'] : '';
+            $headers = ['Content-Type: application/json'];
+            array_push($headers, "Authorization:APPCODE " . $appcode);
+            $querys = "idcard=".$idCard."&name=".urlencode($realName);
+            $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);
+            //设定返回信息中是否包含响应信息头,启用时会将头文件的信息作为数据流输出,true 表示输出信息头, false表示不输出信息头
+            //如果需要将字符串转成json,请将 CURLOPT_HEADER 设置成 false
+            curl_setopt($curl, CURLOPT_HEADER, false);
+            if (1 == strpos("$".$host, "https://"))
+            {
+                curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+                curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
+            }
+            $returnRes = curl_exec($curl);
+            curl_close($curl);
+            $resultData = json_decode($returnRes,true);
+            if (isset($resultData['code']) && !empty($resultData['code'])) {
+                throw new Exception($resultData['message']);
+            }
+            $result['data'] = $resultData;
+        } catch (Exception $e) {
+            $result['status'] = 0;
+            $result['msg'] = $e->getMessage();
+        }
+        return $result;
+    }
 }

+ 4 - 3
application/config.php

@@ -415,8 +415,9 @@ return [
         'SecretId' => 'AKIDISQCk4FCuSN9j8LL9k7GH6oLgpkAOQDm',
         'SecretKey' => 'PaZKq8D4vgOtFSYUEoESVLwJVu78wXxA',
     ],
-    'tencent_yun' => [
-        'SecretId' => 'IDAisIo7',
-        'SecretKey' => 'cZ8neUo2kiNod7qK5zg7mbfgygjCdUQXxR3YrfxN2dYzHGKCNOXzzAbIC1p8tNP9',
+    'ali_yun' => [
+        'app_key' => '203989188',
+        'app_secret' => '4yku6nam6YK0TGdlEemkmMbBR4catDVU',
+        'app_code' => '3f4fc2408a0143509e5be5c20eb97c5b',
     ],
 ];