|
|
|
@ -12,7 +12,7 @@ class WeChatOAuth {
|
|
|
|
|
// 微信授权URL模板
|
|
|
|
|
$url = "https://open.weixin.qq.com/connect/oauth2/authorize?"
|
|
|
|
|
. "appid=" . WECHAT_APPID
|
|
|
|
|
. "&redirect_uri=" . urlencode("http://".$_SERVER['HTTP_HOST']."/".$redirect_uri)
|
|
|
|
|
. "&redirect_uri=" . urlencode("http://" . $_SERVER['HTTP_HOST'] . "/" . $redirect_uri)
|
|
|
|
|
. "&response_type=code&scope=" . $scope
|
|
|
|
|
. "&state=" . $state . "#wechat_redirect";
|
|
|
|
|
|
|
|
|
@ -102,3 +102,8 @@ class WeChatOAuth {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
getCode方法:用于获取微信授权的URL并跳转用户到微信授权页面。处理 redirect_uri,构造微信授权URL,并使用 Location 头进行页面重定向。
|
|
|
|
|
getAccessTokenAndOpenId方法:通过授权码获取 access_token 和 openid。构造微信API获取 access_token 的URL,发送请求并解析返回的JSON数据。
|
|
|
|
|
refreshToken方法:使用 refresh_token 刷新 access_token。构造微信API刷新 access_token 的URL,发送请求并解析返回的JSON数据。
|
|
|
|
|
getUserInfo方法:获取用户的基本信息。构造微信API获取用户信息的URL,发送请求并解析返回的JSON数据。
|
|
|
|
|
checkAccessToken方法:检查 access_token 是否有效。构造微信API验证 access_token 有效性的URL,发送请求并解析返回的结果。
|