Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

企业微信OAuth2.0缺少对snsapi_userinfo和snsapi_privateinfo的支持 #697

Closed
webcreazy opened this issue Aug 3, 2018 · 3 comments
Closed

Comments

@webcreazy
Copy link

webcreazy commented Aug 3, 2018

企业微信OAuth2.0缺少snsapi_userinfo和snsapi_privateinfo

@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";
    if (state != null) {
      url += "&state=" + state;
    }
    url += "#wechat_redirect";
    return url;
  }

weixin-java-cp中WxCpOAuth2ServiceImpl类

  @Override
  public String[] getUserInfo(Integer agentId, String code) throws WxErrorException {
    String url = String.format("https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?code=%s&agentid=%d",
      code, agentId);
    String responseText = this.mainService.get(url, null);
    JsonElement je = new JsonParser().parse(responseText);
    JsonObject jo = je.getAsJsonObject();
    return new String[]{GsonHelper.getString(jo, "UserId"),
      GsonHelper.getString(jo, "DeviceId"),
      GsonHelper.getString(jo, "OpenId")};
  }

中得到的userTicket没有返回
无法调用
getUserDetail(String userTicket)

@webcreazy
Copy link
Author

注意:企业自建应用可以根据userid获取成员详情,无需使用snsapi_userinfo和snsapi_privateinfo两种scope。
企业成员可以用userid通过通讯录相关接口得到用户信息
但是非企业成员授权时只能得到openId,我觉得这两个会有用

@binarywang
Copy link
Member

非常感谢及时提出。看了下,你应该是提了两个问题,以后最好每个问题单独提吧。

@binarywang binarywang changed the title 企业微信OAuth2.0缺少snsapi_userinfo和snsapi_privateinfo 企业微信OAuth2.0缺少对snsapi_userinfo和snsapi_privateinfo的支持 Aug 4, 2018
@binarywang
Copy link
Member

3.1.4.BETA测试版本 已增加相关支持。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants