添加可自定义oauth2 redirectURI的方法

This commit is contained in:
SimonDolph 2015-04-01 17:14:37 +08:00
parent a5d05d3458
commit 37c8ebac2c
2 changed files with 18 additions and 1 deletions

View File

@ -387,6 +387,18 @@ public interface WxMpService {
*/
public String oauth2buildAuthorizationUrl(String scope, String state);
/**
* <pre>
* 构造oauth2授权的url连接
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=网页授权获取用户基本信息
* </pre>
* @param redirectURI
* 用户授权完成后的重定向链接无需urlencode, 方法内会进行encode
* @param scope
* @param state
* @return code
*/
public String oauth2buildAuthorizationUrl(String redirectURI, String scope, String state);
/**
* <pre>
* 用code换取oauth2的access token

View File

@ -363,9 +363,14 @@ public class WxMpServiceImpl implements WxMpService {
@Override
public String oauth2buildAuthorizationUrl(String scope, String state) {
return this.oauth2buildAuthorizationUrl(wxMpConfigStorage.getOauth2redirectUri(), scope, state);
}
@Override
public String oauth2buildAuthorizationUrl(String redirectURI, String scope, String state) {
String url = "https://open.weixin.qq.com/connect/oauth2/authorize?" ;
url += "appid=" + wxMpConfigStorage.getAppId();
url += "&redirect_uri=" + URIUtil.encodeURIComponent(wxMpConfigStorage.getOauth2redirectUri());
url += "&redirect_uri=" + URIUtil.encodeURIComponent(redirectURI);
url += "&response_type=code";
url += "&scope=" + scope;
if (state != null) {