qq third party login code tears

In the past, the project asked me to add a third party to log in. In order to avoid trouble, I will fill in the main steps this time. Here I use oauth2.0 of the official website, But just now I looked at the Internet. Yesterday on the official website, I said that it seems that the path of using url spell will be stopped, but I still published it. I came according to the steps of the official website. First, you need to put a third-party login button on a page, and then, give it a hyperlink to connect to the following website:


Https://graph.qq.com/oauth2.0/authorize? Response ﹐ type = code & client ﹐ id = your ID & redirect ﹐ URI = http: / / callback domain COM / index / QQ ﹐ login & state = Xiaoqing

Next, according to your callback domain, find the corresponding controller and method, and receive them in the method. My method here is qq_login, so,

   public function qq_login()
    {
        
        $access_token = 'https://Graph. QQ. COM / oauth2.0/token? Grant_type = authorization_code & client_id = 00000 & client_secret = 7e65c2c83b4cdd2ee65b4119c3fb0b6f & code = '. $_get ['code']. '& redirect_uri = http: / / callback domain com/index/qq_login';
        $access_token_content = file_get_contents($access_token);
        $params = $this->access_token($access_token_content);
        
        $user_id = 'https://graph.qq.com/oauth2.0/me?access_token='.$params['access_token'];
        $data = file_get_contents($user_id);
        $data = str_replace('callback(','', $data);
        $data = str_replace(');','', $data);
        $open_id = json_decode($data,true);
        $openid=$open_id['openid'];
        Session::put('openid',$openid);
        $user_url = 'https://graph.qq.com/user/get_user_info?access_token='.$params['access_token'].'&oauth_consumer_key=000000&openid='.$openid;
        $user_message = json_decode(file_get_contents($user_url), true);
        
        //Query whether the user binds the mobile number or email
        //print_r(strlen($openid));die;
          $res = DB::table('users_oauth')->where('open_id','=',$openid)->first();
          
          if($res)
          {
            $data = User::where('id',$res->user_id)->first()->toArray();
            \Session::put('user',$data);
            //I used buckle to log in before
            return redirect()->action('IndexController@index');
           }else{
            return redirect()->action('LoginController@user_bind', ['status' => 0, 'nickname' => $user_message['nickname']]);
          }              
        
    }

      //Get the access Ou token of the withholding user
    public function access_token($access_token_content)
    {
        $queryParts = explode('&', $access_token_content);
        $params = array();
        foreach ($queryParts as $param) {
          $item = explode('=', $param);
          $params[$item[0]] = $item[1];
        }  
        return $params;
    }
The above code I pasted directly from the project uses laravel 5.2 third-party login code. You can learn from it. Here, some json data that needs to be processed for third-party login has been processed, but the most depressing thing for me is that it happened. Please see





Conclusion: Phoenix courting or captivating

Tags: Session Mobile Laravel JSON

Posted on Tue, 05 May 2020 09:14:59 -0400 by Shaun13