OAuth::init PHP Method

init() public static method

初始化
public static init ( $client_id, $client_secret )
$client_id 即 appid
$client_secret 即 appkey
    public static function init($client_id, $client_secret)
    {
        if (!$client_id || !$client_secret) {
            exit('client_id or client_secret is null');
        }
        self::$client_id = $client_id;
        self::$client_secret = $client_secret;
    }

Usage Example

Exemplo n.º 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::init