respondError('参数非法'); } if ($skipVerify != 1) { $verify = new \Think\Verify(); if (!$verify->check($verifyCode)) { $this->respondError('验证码错误'); } } if ($account == '' && $mobile == '') { $this->respondError('请输入账号'); } $loginType = 1; if ($mobile != '') { $user = M('user', 'tab_')->field(['id', 'account'])->where(['phone' => $mobile])->find(); if (!$user) { $this->respondError('手机号错误'); } $account = $user['account']; if (!$this->smsVerify($mobile, $verifyCode)) { $this->respondError('验证失败'); } $loginType = -1; } $promote = M('promote', 'tab_')->where(['id' => $promoteId])->find(); $suserApi = new SuserApi(); $userId = $suserApi->login($account, $password, $loginType); //调用登录 $resMsg = "登录成功"; if ($userId <= 0) { switch ($userId) { case -1000 : $resMsg = "账号或密码错误"; break; case -10021 : $resMsg = "账号或密码错误"; break; default : $resMsg = "未知错误"; } $this->respondError($resMsg); } $_SESSION['user_id'] = $userId; $user = M('user', 'tab_')->where(['id' => $userId])->find(); if (!$user['promote_id'] && $promote) { M('user', 'tab_')->where(['id' => $userId])->save([ 'promote_id' => $promoteId, 'promote_account' => $promote['account'] ]); } $this->setData(['user_id' => $userId])->respondSuccess($resMsg); } //验证码 public function verify($vid = '') { $config = array( 'seKey' => 'ThinkPHP.CN', //验证码加密密钥 'fontSize' => 16, // 验证码字体大小(px) 'imageH' => 42, // 验证码图片高度 'imageW' => 107, // 验证码图片宽度 'length' => 4, // 验证码位数 'fontttf' => '4.ttf', // 验证码字体,不设置随机获取 'useCurve' => false, // 是否画混淆曲线 'useNoise' => false, // 是否添加杂点 'useCurve' => false, ); ob_clean(); $verify = new \Think\Verify($config); $verify->codeSet = '0123456789'; $verify->entry($vid); } //注册 public function phoneRegister() { //添加用户 C(api('Config/lists')); $params = $_POST; #判断数据是否为空 if (empty($params)) { $this->respondError('注册数据不能为空'); } $promoteId = $params['promote_id'] ?? 0; $gameId = $params['game_id'] ?? 0; #验证短信验证码 if (!$this->smsVerify($params['account'], $params['verify_code'])) { $this->respondError('验证失败'); } $res = $this->doRegister($params['account'], $params['password'], $params['account'], $promoteId, 4, 2, $gameId); if(empty($res)){ $this->respondError('添加失败'); } //添加自动登录 $suserApi = new SuserApi(); $userId = $suserApi->login($params['account'], $params['password'], 1); $_SESSION['user_id'] = $userId; $this->setData(['user_id' => $userId])->respondSuccess('添加成功'); } //忘记密码 public function forgetPassword() { $params = $_POST; if (empty($params)) { $this->respondError('基础信息不能为空'); } if (!$this->smsVerify($params['account'], $params['verify_code'])) { $this->respondError('验证失败'); } //更新密码 $userApi = new MemberApi(); $userInfo = M("user", "tab_")->where("account = '".$params['account']."'")->find(); if(empty($userInfo)){ $this->respondError('用户不存在'); } //更新用户 $upres = $userApi->updatePassword($userInfo['id'], $params['password']); if($upres){ //自动登陆 // $userId = $userApi->login($params['account'], $params['password'], 1); $this->respondSuccess('修改成功'); }else{ $this->respondError('密码更新错误,请刷新后再次尝试'); } } //普通注册 public function userRegister() { $account = I('account'); $password = I('password'); $promoteId = I('promote_id', 0); $res = $this->doRegister($account, $password, '', $promoteId, 4, 1); if(empty($res)){ $this->respondError('注册失败'); } //添加自动登录 $suserApi = new SuserApi(); $userId = $suserApi->login($account, $password, 1); $_SESSION['user_id'] = $userId; $this->setData(['user_id' => $userId])->respondSuccess('注册成功'); } //真正注册代码 public function doRegister($account, $password ,$phone, $promote_id, $register_way, $register_type, $game_id = 0) { //验证账号 $userService = new UserService(); if ($userService->isAccountExist($account)) { $this->respondError('用户名已存在'); } $data = [ 'account' => $account, 'password' => think_ucenter_md5($password, UC_AUTH_KEY), 'phone' => $phone, 'head_img' => '', 'promote_id' => $promote_id, 'promote_account' => get_promote_account($promote_id), 'register_way' => $register_way, 'register_type' => $register_type, 'register_ip' => get_client_ip(), 'parent_id' => get_fu_id($promote_id), 'parent_name' => get_parent_name($promote_id), 'register_time' => time(), 'check_time' => time(), ]; if (Request::isIOS()) { $data['device_type'] = 2; } elseif (Request::isAndroid()) { $data['device_type'] = 1; } if ($game_id) {//关联游戏 $game = M('game', 'tab_')->where(['id' => $game_id])->find(); if ($game) { $data['fgame_id'] = $game_id; $data['fgame_name'] = $game['game_name']; } } /* 添加用户 */ $res = M('user', 'tab_') ->add($data); if ($res) { $taskClient = new TaskClient(); $taskClient->registerEvent($res, 'TestFlight'); } return $res; } //发送验证码 public function sendPhoneCode() { $phone = I('phone'); $taskClient = new TaskClient(); $result = $taskClient->sendSmsCode($phone, get_client_ip()); $data = []; if ($result['code'] == TaskClient::SUCCESS) { $this->respondSuccess('发送成功'); } else { $this->respondError('发送失败'); } } public function smsVerify($phone = '' , $code = '') { $taskClient = new TaskClient(); $result = $taskClient->checkSms($phone, $code); $data = []; if ($result['code'] == TaskClient::SUCCESS) { return true; } else { return false; } } }