fastadmin API自动注册

    public function test1()
    {
        $openid="7234115";
        $username="723422256";
        
        $search_res=Db::name("user")->whereOr("username",$username)->whereOr("openid",$openid)->find();
        if($search_res){
            $loginRes = $this->auth->direct($search_res["id"]);
            if($loginRes){
                
                Cookie::set('uid', $this->auth->id );
                Cookie::set('token', $this->auth->getToken());
                
                $this->success('登录成功',$loginRes);
            }
            else{
                $this->success('登录失败,未找到用户',$loginRes);
            }
        }
        else{
            $registerRes = $this->auth->register($username,$username,'','',[
                "openid"=>$openid
            ]);
            // Cookie::set('uid', $this->auth->id );
            // Cookie::set('token', $this->auth->getToken());
            
            $this->auth->logout();
            Cookie::delete('uid');
            Cookie::delete('token');
            $this->success('执行注册',$registerRes);
        }
        
        $this->success('返回成功', ['action' => 'test1']);
    }

你可能感兴趣的:(java,前端,服务器)