瀏覽代碼

银行卡绑定

zhangxiaobin 1 年之前
父節點
當前提交
70cd3afd50

+ 3 - 0
application/api/controller/User.php

@@ -1157,6 +1157,9 @@ class User extends Api
             if ($user->status == 'new') {
                 $user->status = 'normal';
             }
+            if (empty($user->username)) {
+                $user->username = $mobile;
+            }
             $userRes = $user->save();
 
             if ($userRes) {

+ 13 - 1
application/api/controller/Withdraw.php

@@ -4,6 +4,7 @@ namespace app\api\controller;
 
 use app\common\library\Sms;
 use app\api\controller\Common;
+use app\common\service\UserService;
 use fast\Random;
 use think\Db;
 use think\Exception;
@@ -177,6 +178,7 @@ class Withdraw extends Common
     public function bindBank() {
         $realname = $this->request->request('realname');// 真实姓名
         $bank_no = $this->request->request('bank_no');// 银行账号
+        $idCard = $this->request->request('id_card');// 身份证号
         /*$bank_name = $this->request->request('bank_name');// 银行名称
         $open_address = $this->request->request('open_address');// 开户地*/
         $open_bank = $this->request->request('open_bank');// 开户行
@@ -188,7 +190,16 @@ class Withdraw extends Common
         if(!$realname || !$bank_no || !$open_bank ) {
             $this->error("请将信息填写完整");
         }
-
+        $userService = new UserService();
+        $aliParams = [
+            'bank_no' => $bank_no,
+            'id_card' => $idCard,
+            'real_name' => $realname,
+        ];
+        $aliBankCheckRes = $userService->bankCheck($aliParams);
+        if (!$aliBankCheckRes['status']) {
+            throw new Exception($aliBankCheckRes['msg']);
+        }
         // 获取用户信息
         //$userInfo = \app\common\model\User::where(["id"=>$this->auth->id])->find();
 
@@ -204,6 +215,7 @@ class Withdraw extends Common
         $data["realname"] = $realname;
         $data["bank_no"] = $bank_no;
         $data["open_bank"] = $open_bank;
+        $data["id_card"] = $idCard;
         /*$data["bank_name"] = $bank_name;
         $data["open_address"] = $open_address;
         $data["mobile"] = $bank_mobile;*/

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

@@ -144,6 +144,72 @@ class UserService
     }
 
     /**
+     * 阿里银行卡三要素
+     * https://market.aliyun.com/products/57000002/cmapi00063283.html
+     * @return void
+     */
+    public function bankCheck($params=[])
+    {
+        $result = [
+            'status' => 1,
+            'msg' => '',
+            'data' => [],
+        ];
+        try {
+            $bankcard = isset($params['bank_no']) ? $params['bank_no'] : '';//银行卡
+            $idCard = isset($params['id_card']) ? $params['id_card'] : '';//身份证号
+            $realName = isset($params['real_name']) ? $params['real_name'] : '';//姓名
+            $aliyunConfig = config('ali_yun');
+            $host = "https://sxbank3v2.market.alicloudapi.com";
+            $path = "/bankcard3/check";
+            $method = "POST";
+            $appcode = isset($aliyunConfig['app_code']) ? $aliyunConfig['app_code'] : '';
+            $headers = [];
+            array_push($headers, "Authorization:APPCODE " . $appcode);
+            $querys = "bankcard=".$bankcard."&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['msg']);
+            }
+            $aliResult = isset($resultData['data']['result']) ? $resultData['data']['result'] : 0;
+            if ($aliResult != 1) {
+                //核查结果(1:一致,2:不一致,3:无效卡号或卡状态异常)
+                $aliMsg = '';
+                if ($aliResult == 2) {
+                    $aliMsg = '不一致';
+                } elseif ($aliResult == 3) {
+                    $aliMsg = '无效卡号或卡状态异常';
+                }
+                throw new Exception($aliMsg);
+            }
+            $result['data'] = $resultData;
+        } catch (Exception $e) {
+            $result['status'] = 0;
+            $result['msg'] = $e->getMessage();
+        }
+        return $result;
+    }
+
+    /**
      * 邀请赠送金额
      * @return void
      */