コード例 #1
0
 /**
  * Show the application login form.
  *
  * @return \Illuminate\Http\Response
  */
 public function getLogin()
 {
     if (view()->exists('auth.authenticate')) {
         return view('auth.authenticate');
     }
     $o = new SaeTOAuthV2(WeiboConfig::appKey(), WeiboConfig::securityKey());
     $weibo_url = $o->getAuthorizeURL(WeiboConfig::callbackUrl());
     return view('auth.login', compact('weibo_url'));
 }
コード例 #2
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function callback(Request $request)
 {
     //
     $o = new SaeTOAuthV2(WeiboConfig::appKey(), WeiboConfig::securityKey());
     $success = false;
     $weibo_user = null;
     $token = null;
     $user = null;
     if ($request->has('code')) {
         $keys = array();
         $keys['code'] = $request->input('code');
         $keys['redirect_uri'] = WeiboConfig::callbackUrl();
         try {
             $token = $o->getAccessToken('code', $keys);
             $success = $token != null;
         } catch (OAuthException $e) {
         }
     }
     if ($token) {
         $success = true;
         $request->session()->put('token', $token);
         $c = new SaeTClientV2(WeiboConfig::appKey(), WeiboConfig::securityKey(), $token['access_token']);
         $uid_get = $c->get_uid();
         $uid = $uid_get['uid'];
         $weibo_user = $c->show_user_by_id($uid);
         //根据ID获取用户等基本信息
         $user = WeiboUtils::createUser($weibo_user);
         if ($user != null) {
             Log::debug('login:'******'email' => $user->email, 'password' => '111111'], true);
             return redirect('/');
         }
     }
     $view = view('weibo.callback', compact('success', 'weibo_user', 'user'));
     $response = Response($view);
     return $response;
 }