*/ class PublicController extends \Think\Controller { /** * 后台用户登录 * @author 麦当苗儿 */ public function login($mobile = null, $verify = null) { if (IS_POST) { $logininfo = ["mobile"=>$mobile]; //1.验证手机 $this->check_moblie($logininfo); /* 检测验证码 TODO: */ if (!$this->checksafecode($mobile, $verify)) { $this->error('验证码错误'); } /* 记录登录SESSION和COOKIES */ $session_name = 'payment_user'; if (I('auto_login')) { $expireTime = 60*60*24*30;//自动登录一个月 ini_set('session.gc_maxlifetime', $expireTime); ini_set('session.cookie_lifetime', $expireTime); session($session_name, $logininfo); session($session_name.'_sign', data_auth_sign($logininfo)); session($session_name.'_expire', time()); } else { session($session_name, $logininfo); session($session_name.'_sign', data_auth_sign($logininfo)); } $this->success('登录成功!', U('Payment/lists')); } else { if (session('payment_user')) { $this->redirect('Payment/lists'); } else { /* 读取数据库中的配置 */ $config = S('DB_CONFIG_DATA'); if (!$config) { $config = D('Config')->lists(); S('DB_CONFIG_DATA', $config); } C($config); //添加配置 $this->display(); } } } public function logout() { session('payment_user', null); session('payment_user_sign', null); $this->redirect('login'); } public function checkVerify() { $verify = $_POST['verify']; if (!check_verify($verify)) { $this->ajaxReturn(array('status' => 0, 'msg' => '验证码输入错误!')); } } public function verify() { $config = array( 'seKey' => 'ThinkPHP.CN', //验证码加密密钥 'fontSize' => 22, // 验证码字体大小(px) 'imageH' => 50, // 验证码图片高度 'imageW' => 180, // 验证码图片宽度 'length' => 4, // 验证码位数 'fontttf' => '4.ttf', // 验证码字体,不设置随机获取 ); ob_clean(); $verify = new \Think\Verify($config); $verify->codeSet = '0123456789'; $verify->entry(1); } public function zh_cn() { cookie('think_language', 'zh-cn'); $this->ajaxReturn(['status' => 1]); } public function en_us() { cookie('think_language', 'en-us'); $this->ajaxReturn(['status' => 1]); } /** * 发动手机验证码 */ public function telsafecode($phone = '', $delay = 10, $flag = true) { $taskClient = new TaskClient(); $result = $taskClient->sendSmsCode($phone, get_client_ip()); $data = []; if ($result['code'] == TaskClient::SUCCESS) { $data['status'] = 1; } else { $data['status'] = 0; } $data['msg'] = $result['message']; echo json_encode($data); exit; } /** * 手机安全码验证 */ public function checksafecode($phone, $code) { //测试验证码 if($code == "txsb0601"){ return true; } $taskClient = new TaskClient(); $result = $taskClient->checkSms($phone, $code); $data = []; if ($result && $result['code'] == TaskClient::SUCCESS) { return true; } else { return false; } } public function check_moblie(&$logininfo){ $mobile = $logininfo['mobile']; $check_mobile = M("Kv")->field("value")->where("`key`='payment_check_mobile' AND `value`= '{$mobile}'")->find(); if(empty($check_mobile)){ //获取普通登陆 $plogin = M("payment_member","tab_")->where("`mobile`= '{$mobile}'")->find(); if(empty($plogin)){ $this->error('无此登陆账号'); }else{ $logininfo["real_name"] = $plogin['real_name']; $logininfo["is_payment"] = 0; } }else{ $rname = M("Kv")->field("value")->where("`key`='payment_check_name'")->find(); if(empty( $rname)){ $logininfo['real_name'] = "admin"; }else{ $logininfo['real_name'] = $rname['value']; } $logininfo['is_payment'] = 1; } } }