Search in sources :

Example 6 with OauthConfig

use of com.publiccms.view.pojo.oauth.OauthConfig in project PublicCMS-preview by sanluan.

the class QQOauthComponent method getUserInfo.

/*
     * http://wiki.connect.qq.com/get_user_info
     */
@Override
public OauthUser getUserInfo(short siteId, OauthAccess oauthAccess) throws ClientProtocolException, IOException {
    OauthConfig config = getConfig(siteId);
    if (null != oauthAccess && null != config) {
        StringBuilder sb = new StringBuilder("https://graph.qq.com/user/get_user_info?access_token=");
        sb.append(oauthAccess.getAccessToken()).append("&oauth_consumer_key=").append(config.getAppKey()).append("&openid=").append(oauthAccess.getOpenId()).append("&format=format");
        String html = get(sb.toString());
        if (CommonUtils.notEmpty(html)) {
            Map<String, Object> map = objectMapper.readValue(html, new TypeReference<Map<String, Object>>() {
            });
            if (0 == (Integer) map.get("ret")) {
                return new OauthUser(oauthAccess.getOpenId(), (String) map.get("nickname"), (String) map.get("figureurl_qq_2"), "男".equals(map.get("gender")) ? "m" : "f");
            }
        }
    }
    return null;
}
Also used : OauthConfig(com.publiccms.view.pojo.oauth.OauthConfig) Map(java.util.Map) OauthUser(com.publiccms.view.pojo.oauth.OauthUser)

Example 7 with OauthConfig

use of com.publiccms.view.pojo.oauth.OauthConfig in project PublicCMS-preview by sanluan.

the class WechatOauthComponent method getAccessToken.

/*
     * 
     */
@Override
public OauthAccess getAccessToken(short siteId, String code) throws ClientProtocolException, IOException {
    OauthConfig config = getConfig(siteId);
    if (null != config) {
        StringBuilder sb = new StringBuilder("https://api.weixin.qq.com/sns/oauth2/access_token?appid=");
        sb.append(config.getAppKey()).append("&secret=").append(config.getAppSecret()).append("&code=").append(code).append("&grant_type=authorization_code");
        String html = get(sb.toString());
        Map<String, Object> map = objectMapper.readValue(html, new TypeReference<Map<String, Object>>() {
        });
        if (null != map.get("access_token")) {
            return new OauthAccess(code, (String) map.get("access_token"), (String) map.get("openid"));
        }
    }
    return null;
}
Also used : OauthAccess(com.publiccms.view.pojo.oauth.OauthAccess) OauthConfig(com.publiccms.view.pojo.oauth.OauthConfig) Map(java.util.Map)

Example 8 with OauthConfig

use of com.publiccms.view.pojo.oauth.OauthConfig in project PublicCMS-preview by sanluan.

the class WeiboOauthComponent method getAuthorizeUrl.

/*
     * http://open.weibo.com/wiki/Oauth2/authorize
     */
public String getAuthorizeUrl(short siteId, String state, boolean mobile) {
    OauthConfig config = getConfig(siteId);
    if (null != config) {
        StringBuilder sb = new StringBuilder("https://api.weibo.com/oauth2/authorize?client_id=");
        sb.append(config.getAppKey()).append("&redirect_uri=").append(config.getReturnUrl()).append("&scope=email&state=").append(state);
        if (mobile) {
            sb.append("&display=mobile");
        }
        return sb.toString();
    }
    return null;
}
Also used : OauthConfig(com.publiccms.view.pojo.oauth.OauthConfig)

Aggregations

OauthConfig (com.publiccms.view.pojo.oauth.OauthConfig)8 OauthAccess (com.publiccms.view.pojo.oauth.OauthAccess)3 Map (java.util.Map)3 OauthUser (com.publiccms.view.pojo.oauth.OauthUser)1 HashMap (java.util.HashMap)1