<?php
namespace WeChat;
use WeChat\Contracts\BasicWeChat;
class Oauth extends BasicWeChat
{
public function getOauthRedirect($redirect_url, $state = '', $scope = 'snsapi_base')
{
$appid = $this->config->get('appid');
$redirect_uri = urlencode($redirect_url);
return "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$appid}&redirect_uri={$redirect_uri}&response_type=code&scope={$scope}&state={$state}#wechat_redirect";
}
public function getOauthAccessToken()
{
$appid = $this->config->get('appid');
$appsecret = $this->config->get('appsecret');
$code = isset($_GET['code']) ? $_GET['code'] : '';
$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$appid}&secret={$appsecret}&code={$code}&grant_type=authorization_code";
return $this->httpGetForJson($url);
}
public function getOauthRefreshToken($refresh_token)
{
$appid = $this->config->get('appid');
$url = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid={$appid}&grant_type=refresh_token&refresh_token={$refresh_token}";
return $this->httpGetForJson($url);
}
public function checkOauthAccessToken($access_token, $openid)
{
$url = "https://api.weixin.qq.com/sns/auth?access_token={$access_token}&openid={$openid}";
return $this->httpGetForJson($url);
}
public function getUserInfo($access_token, $openid, $lang = 'zh_CN')
{
$url = "https://api.weixin.qq.com/sns/userinfo?access_token={$access_token}&openid={$openid}&lang={$lang}";
return $this->httpGetForJson($url);
}
}