本文整理汇总了PHP中Wechat::authorize方法的典型用法代码示例。如果您正苦于以下问题:PHP Wechat::authorize方法的具体用法?PHP Wechat::authorize怎么用?PHP Wechat::authorize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Wechat
的用法示例。
在下文中一共展示了Wechat::authorize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
function index()
{
if (!session('openid_' . $this->token)) {
$this->info = M('wxuser')->where(array('token' => $this->token))->find();
vendor("Oauth2.OAuth2", LIB_PATH . '../Extend/Vendor');
vendor("Oauth2.Provider.Wechat", LIB_PATH . '../Extend/Vendor');
$wechat = new Wechat();
$wechat->config(array('id' => $this->info['appid'], 'secret' => $this->info['appsecret']));
$redirect_uri = C('site_url') . '/index.php/Wap/Login/index?token=' . $this->token . '&url=' . $this->url;
if (!$_GET['code']) {
// By sending no options it'll come back here
$url = $wechat->authorize(array('redirect_uri' => $redirect_uri));
redirect($url);
} else {
try {
// Have a go at creating an access token from the code
$access_token = $wechat->access($_GET['code'], array('redirect_uri' => $redirect_uri));
// Use this object to try and get some user details (username, full name, etc)
$user = $wechat->get_user_info($access_token);
$this->save_wechat_user($user);
session('openid_' . $this->token, $user->openid);
} catch (OAuth2_Exception $e) {
print_r($e);
die;
}
}
}
if ($this->url) {
redirect($this->url);
}
}
示例2: index
public function index()
{
if (!session('openid_' . $this->token)) {
$this->info = M('wxuser')->where(array('token' => $this->token))->find();
vendor("Oauth2.OAuth2", LIB_PATH . '../Extend/Vendor');
vendor("Oauth2.Provider.Wechat", LIB_PATH . '../Extend/Vendor');
$wechat = new Wechat();
$wechat->config(array('id' => $this->info['appid'], 'secret' => $this->info['appsecret']));
$redirect_uri = C('site_url') . '/index.php/Wap/Coupons/index?token=' . $this->token . '&coupon_id=' . $this->coupon_id;
if (!$_GET['code']) {
// By sending no options it'll come back here
$url = $wechat->authorize(array('redirect_uri' => $redirect_uri));
redirect($url);
} else {
try {
// Have a go at creating an access token from the code
$token = $wechat->access($_GET['code'], array('redirect_uri' => $redirect_uri));
// Use this object to try and get some user details (username, full name, etc)
$user = $wechat->get_user_info($token);
$this->openid = $user->openid;
session('openid_' . $this->token, $user->openid);
} catch (OAuth2_Exception $e) {
print_r($e);
die;
}
}
} else {
$this->openid = session('openid_' . $this->token);
}
$url = C('site_url') . "/index.php?g=Wap&m=Coupon&a=index&type=1&token=" . $this->token . '&id=' . $this->coupon_id . '&wecha_id=' . $this->openid;
header('Location:' . $url);
}
示例3: Oauth2
public function Oauth2()
{
if (!session('openid_' . $this->token)) {
$this->info = M('wxuser')->where(array('token' => $this->token))->find();
vendor("Oauth2.OAuth2", LIB_PATH . '../Extend/Vendor');
vendor("Oauth2.Provider.Wechat", LIB_PATH . '../Extend/Vendor');
$wechat = new Wechat();
$wechat->config(array('id' => $this->info['appid'], 'secret' => $this->info['appsecret']));
$redirect_uri = $_GET['method_name'];
if (!$_GET['code']) {
$redirect_uri = C('site_url') . '/index.php/Fxs/Fxs/Oauth2?token=' . $this->token . '&method_name=' . $_GET['method_name'];
// By sending no options it'll come back here
$url = $wechat->authorize(array('redirect_uri' => $redirect_uri));
redirect($url);
} else {
try {
// Have a go at creating an access token from the code
$token = $wechat->access($_GET['code'], array('method_name' => $redirect_uri));
// Use this object to try and get some user details (username, full name, etc)
$user = $wechat->get_user_info($token);
session('openid_' . $this->token, $user->openid);
} catch (OAuth2_Exception $e) {
print_r($e);
die;
}
}
}
if (session('openid_' . $this->token)) {
$user = M('reguser')->where(array('token' => $this->token, 'openid' => session('openid_' . $this->token)))->find();
if (!$user) {
session_destroy();
}
}
header('Location:' . U('Fxs/' . $_GET['method_name'], array('token' => $this->token)));
}