mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-05 17:38:05 +08:00
#697 企业微信OAuth2.0增加对snsapi_userinfo和snsapi_privateinfo的支持
This commit is contained in:
parent
013835fc31
commit
c29a3e5f01
@ -234,10 +234,16 @@ public class WxConsts {
|
||||
* 不弹出授权页面,直接跳转,只能获取用户openid.
|
||||
*/
|
||||
public static final String SNSAPI_BASE = "snsapi_base";
|
||||
|
||||
/**
|
||||
* 弹出授权页面,可通过openid拿到昵称、性别、所在地。并且,即使在未关注的情况下,只要用户授权,也能获取其信息.
|
||||
*/
|
||||
public static final String SNSAPI_USERINFO = "snsapi_userinfo";
|
||||
|
||||
/**
|
||||
* 手动授权,可获取成员的详细信息,包含手机、邮箱。只适用于企业微信或企业号.
|
||||
*/
|
||||
public static final String SNSAPI_PRIVATEINFO = "snsapi_privateinfo";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,6 +34,19 @@ public interface WxCpOAuth2Service {
|
||||
*/
|
||||
String buildAuthorizationUrl(String redirectUri, String state);
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 构造oauth2授权的url连接
|
||||
* 详情请见: http://qydev.weixin.qq.com/wiki/index.php?title=企业获取code
|
||||
* </pre>
|
||||
*
|
||||
* @param redirectUri 跳转链接地址
|
||||
* @param state 状态码
|
||||
* @param scope 取值参考me.chanjar.weixin.common.api.WxConsts.OAuth2Scope类
|
||||
* @return url
|
||||
*/
|
||||
String buildAuthorizationUrl(String redirectUri, String state, String scope);
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 用oauth2获取用户信息
|
||||
@ -78,7 +91,7 @@ public interface WxCpOAuth2Service {
|
||||
* 需要有对应应用的使用权限,且成员必须在授权应用的可见范围内。
|
||||
* </pre>
|
||||
*
|
||||
* @param userTicket 成员票据
|
||||
* @param userTicket 成员票据
|
||||
*/
|
||||
WxCpUserDetail getUserDetail(String userTicket) throws WxErrorException;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.URIUtil;
|
||||
import me.chanjar.weixin.common.util.json.GsonHelper;
|
||||
@ -37,16 +38,22 @@ public class WxCpOAuth2ServiceImpl implements WxCpOAuth2Service {
|
||||
|
||||
@Override
|
||||
public String buildAuthorizationUrl(String redirectUri, String state) {
|
||||
String url = "https://open.weixin.qq.com/connect/oauth2/authorize?";
|
||||
url += "appid=" + this.mainService.getWxCpConfigStorage().getCorpId();
|
||||
url += "&redirect_uri=" + URIUtil.encodeURIComponent(redirectUri);
|
||||
url += "&response_type=code";
|
||||
url += "&scope=snsapi_base";
|
||||
return this.buildAuthorizationUrl(redirectUri, state, WxConsts.OAuth2Scope.SNSAPI_BASE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildAuthorizationUrl(String redirectUri, String state, String scope) {
|
||||
StringBuilder url = new StringBuilder("https://open.weixin.qq.com/connect/oauth2/authorize?");
|
||||
url.append("appid=").append(this.mainService.getWxCpConfigStorage().getCorpId());
|
||||
url.append("&redirect_uri=").append(URIUtil.encodeURIComponent(redirectUri));
|
||||
url.append("&response_type=code");
|
||||
url.append("&scope=").append(scope);
|
||||
|
||||
if (state != null) {
|
||||
url += "&state=" + state;
|
||||
url.append("&state=").append(state);
|
||||
}
|
||||
url += "#wechat_redirect";
|
||||
return url;
|
||||
url.append("#wechat_redirect");
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user