初始化代码
This commit is contained in:
126
application/api/controller/Login.php
Normal file
126
application/api/controller/Login.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use think\Controller;
|
||||
|
||||
|
||||
class Login extends BaseCom
|
||||
{
|
||||
protected function initialize()
|
||||
{
|
||||
$validate_action_list = ['user_reg'];
|
||||
$action = request()->action();
|
||||
if(!in_array($action, $validate_action_list)) {
|
||||
parent::initialize();
|
||||
}
|
||||
// parent::initialize();
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
$config = get_uncache_system_config();
|
||||
if($config['is_maintenance'] == 2){
|
||||
ajaxReturn(301, '系统维护中');
|
||||
}
|
||||
// ajaxReturn(301, '系统维护');
|
||||
// add_operation(0, 0); //用户行为日志
|
||||
}
|
||||
|
||||
public function c(){
|
||||
model('UserRecharge')->threePayFromPost('E'.time(), 30, 922);
|
||||
}
|
||||
|
||||
public function user_login()
|
||||
{
|
||||
|
||||
$user_name = input('user_login', '');
|
||||
$password = input('password', '');
|
||||
$system = input('system',0);
|
||||
$last_login_device = input('last_login_device', '');
|
||||
$reslut = model('UserLogin')->user_login($user_name, $password, $last_login_device, $system);
|
||||
ajaxReturn($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//注册
|
||||
public function user_reg()
|
||||
{
|
||||
header("Access-Control-Allow-Origin: *"); // 允许任意域名发起的跨域请求
|
||||
$user_name = input('user_login');
|
||||
$password = input('password');
|
||||
$reg_code = input('reg_code', '');
|
||||
$sms_code = input('sms_code', ''); //短信验证码
|
||||
$key_name = "api:login:user_reg:" . $user_name;
|
||||
|
||||
|
||||
// if($sms_code != 9999){
|
||||
$reslut = model('sms')->verification_code($user_name, $sms_code);
|
||||
if ($reslut['code'] == 201) {
|
||||
return ajaxReturn($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
// }
|
||||
redis_lock_exit($key_name,1,2);
|
||||
$reslut = model('UserLogin')->user_reg($user_name, $password, $reg_code);
|
||||
redis_unlock($key_name);
|
||||
return ajaxReturn($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
|
||||
//发送短信
|
||||
public function send_sms()
|
||||
{
|
||||
header("Access-Control-Allow-Origin: *"); // 允许任意域名发起的跨域请求
|
||||
$mobile = input('mobile');
|
||||
$type = input('type');
|
||||
$key_name = "api:login:send_sms:" . $mobile;
|
||||
|
||||
//图片验证码--开始
|
||||
$captcha_code = input('captcha_code', '');
|
||||
$captcha_key = input('captcha_key', '');
|
||||
$result = model('api/ImgCaptcha')->check_captcha($captcha_code, $captcha_key);
|
||||
if ($result['code'] != 200) {
|
||||
ajaxReturn($result['code'], $result['msg'], $result['data']);
|
||||
}
|
||||
|
||||
|
||||
redis_lock_exit($key_name);
|
||||
$reslut = model('sms')->send_sms($mobile, $type);
|
||||
redis_unlock($key_name);
|
||||
return ajaxReturn($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//验证码登录
|
||||
public function phone_verification_code_log(){
|
||||
header("Access-Control-Allow-Origin: *"); // 允许任意域名发起的跨域请求
|
||||
$user_name = input('user_login');
|
||||
$system = input('system',0);
|
||||
$last_login_device = input('last_login_device', '');
|
||||
$sms_code = input('sms_code', ''); //短信验证码
|
||||
$key_name = "api:login:phone_verification_code_log:" . $user_name;
|
||||
|
||||
|
||||
// if($sms_code != 9999){
|
||||
$reslut = model('sms')->verification_code($user_name, $sms_code);
|
||||
if ($reslut['code'] == 201) {
|
||||
return ajaxReturn($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
// }
|
||||
redis_lock_exit($key_name);
|
||||
$reslut = model('UserLogin')->phone_verification_code_log($user_name, $last_login_device, $system);
|
||||
redis_unlock($key_name);
|
||||
return ajaxReturn($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//获取图片验证码
|
||||
public function create_captcha()
|
||||
{
|
||||
$reslut = model('api/ImgCaptcha')->create_captcha();
|
||||
ajaxReturn($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user