Java Code Examples for me.zhyd.oauth.model.AuthToken#getOpenId()
The following examples show how to use
me.zhyd.oauth.model.AuthToken#getOpenId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuthQqRequest.java From JustAuth with MIT License | 6 votes |
/** * 获取QQ用户的OpenId,支持自定义是否启用查询unionid的功能,如果启用查询unionid的功能, * 那就需要开发者先通过邮件申请unionid功能,参考链接 {@see http://wiki.connect.qq.com/unionid%E4%BB%8B%E7%BB%8D} * * @param authToken 通过{@link AuthQqRequest#getAccessToken(AuthCallback)}获取到的{@code authToken} * @return openId */ private String getOpenId(AuthToken authToken) { String response = new HttpUtils(config.getHttpConfig()).get(UrlBuilder.fromBaseUrl("https://graph.qq.com/oauth2.0/me") .queryParam("access_token", authToken.getAccessToken()) .queryParam("unionid", config.isUnionId() ? 1 : 0) .build()); String removePrefix = response.replace("callback(", ""); String removeSuffix = removePrefix.replace(");", ""); String openId = removeSuffix.trim(); JSONObject object = JSONObject.parseObject(openId); if (object.containsKey("error")) { throw new AuthException(object.get("error") + ":" + object.get("error_description")); } authToken.setOpenId(object.getString("openid")); if (object.containsKey("unionid")) { authToken.setUnionId(object.getString("unionid")); } return StringUtils.isEmpty(authToken.getUnionId()) ? authToken.getOpenId() : authToken.getUnionId(); }
Example 2
Source File: AuthWeChatMpRequest.java From JustAuth with MIT License | 5 votes |
@Override protected AuthUser getUserInfo(AuthToken authToken) { String openId = authToken.getOpenId(); String response = doGetUserInfo(authToken); JSONObject object = JSONObject.parseObject(response); this.checkResponse(object); String location = String.format("%s-%s-%s", object.getString("country"), object.getString("province"), object.getString("city")); if (object.containsKey("unionid")) { authToken.setUnionId(object.getString("unionid")); } return AuthUser.builder() .rawUserInfo(object) .username(object.getString("nickname")) .nickname(object.getString("nickname")) .avatar(object.getString("headimgurl")) .location(location) .uuid(openId) .gender(AuthUserGender.getWechatRealGender(object.getString("sex"))) .token(authToken) .source(source.toString()) .build(); }
Example 3
Source File: AuthWeChatOpenRequest.java From JustAuth with MIT License | 5 votes |
@Override protected AuthUser getUserInfo(AuthToken authToken) { String openId = authToken.getOpenId(); String response = doGetUserInfo(authToken); JSONObject object = JSONObject.parseObject(response); this.checkResponse(object); String location = String.format("%s-%s-%s", object.getString("country"), object.getString("province"), object.getString("city")); if (object.containsKey("unionid")) { authToken.setUnionId(object.getString("unionid")); } return AuthUser.builder() .rawUserInfo(object) .username(object.getString("nickname")) .nickname(object.getString("nickname")) .avatar(object.getString("headimgurl")) .location(location) .uuid(openId) .gender(AuthUserGender.getWechatRealGender(object.getString("sex"))) .token(authToken) .source(source.toString()) .build(); }