[PHP高可用后端]④④--登陆功能

route.php

app.php

 '_#sing_ty',//密码加密言
    'aeskey' => 'sgg45747ss223455',
    'apptypes' => [
        'ios',
        'android',
    ],
    'app_sign_time' => 6000,
    'app_sign_cache_time' => 12000,
    'login_time_out_day'=>7,//登陆token的失效时间
];

User.php(Model)

Login.php

isPost()) {
            return show(config('code.error'), '您没有权限', [], 403);
        }
        $param = input('param.');
        if (empty($param['phone'])) {
            return show(config('code.error'), '手机不合法', [], 404);
        }
        if (empty($param['code'])) {
            return show(config('code.error'), '手机短信验证码不合法', [], 404);
        }
        //validate 严格检验 自行完成
        $code = Alidayu::getInstance()->checkSmsIdentify($param['phone']);
        if ($code != $param['code']) {
            return show(config('code.error'), '手机短信验证码不存在', [], 404);
        }
        $token = IAuth::setAppLoginToken($param['phone']);
        $data = [
            'token' => $token,
            'time_out' => strtotime("+" . config('app.login_time_out_day') . ' days'),
        ];
        //查询这个手机号是否存在
        $user = User::get(['phone' => $param['phone']]);
        //halt($user);
        if ($user && $user->status == 1) {
            $id = model('User')->save($data, ['phone' => $param['phone']]);
        }else{
            //第一次登陆 注册数据
            $data['username']= 'singwa粉-' . $param['phone'];
            $data['status']=1;
            $data['phone']= $param['phone'];
            $id = model('User')->add($data);

        }
        $obj = new Aes();
        if ($id) {
            $result = [
                //'token' => $obj->encryt($token . '||' . $id.time()),
                'token' => $token,
            ];
            return show(config('code.success'), 'OK', $result);
        } else {
            return show(config('code.error'), 'error', [], 404);
        }

    }
}

Test.php

encryt(json_encode(input('post.'))),
            201);
    }

    public function testSend()
    {
        $obj=Alidayu::getInstance()->setSmsIdentify('18617156713');
        if($obj){
            echo 'true';
        }
    }

    public function token(){
        echo IAuth::setAppLoginToken('');
    }
}

[PHP高可用后端]④④--登陆功能_第1张图片
image.png

你可能感兴趣的:([PHP高可用后端]④④--登陆功能)