OAuth::checkOAuthValid PHP Method

checkOAuthValid() public static method

验证授权是否有效
public static checkOAuthValid ( )
    public static function checkOAuthValid()
    {
        $r = json_decode(Tencent::api('user/info'), true);
        if ($r['data']['name']) {
            return true;
        } else {
            self::clearOAuthInfo();
            return false;
        }
    }

Usage Example

示例#1
0
 public function shouquan($code, $openid, $openkey, $redirect_uri)
 {
     OAuth::init($this->client_id, $this->client_secret);
     Tencent::$debug = $this->debug;
     $callback = $redirect_uri;
     //回调url
     if ($code) {
         //已获得code
         //获取授权token
         $url = OAuth::getAccessToken($code, $callback);
         $r = Http::request($url);
         parse_str($r, $out);
         //存储授权数据
         if (@$out['access_token']) {
             $_SESSION['t_access_token'] = $out['access_token'];
             $_SESSION['t_refresh_token'] = $out['refresh_token'];
             $_SESSION['t_expire_in'] = $out['expires_in'];
             $_SESSION['t_code'] = $code;
             $_SESSION['t_openid'] = $openid;
             $_SESSION['t_openkey'] = $openkey;
             //验证授权
             $r = OAuth::checkOAuthValid();
             if ($r) {
                 //echo('<h3>授权成功!!!</h3><br>');
                 //print_r($r);exit;
                 //header('Location: ' . $callback);//刷新页面
                 return $r;
             } else {
                 exit('<h3>授权失败,请重试</h3>');
             }
         } else {
             exit($r);
         }
     }
 }
All Usage Examples Of OAuth::checkOAuthValid