package cn.ksource.core.util;
|
|
import cn.ksource.config.SysConfigConstants;
|
|
/**
|
* QQ登录工具类
|
* @author jxl
|
*/
|
|
public class QQUtil {
|
|
private static String APP_ID = "101340494";
|
|
private static String APP_KEY = "587691fdc52f023afcc8d9707d4fe6a1";
|
|
|
//QQ回调地址
|
private static String back_url = SysConfigConstants.WEBCHAT_ADDRESS+"/business/loginCallBack.html";
|
|
/**
|
* Authorization Code 链接
|
*/
|
private static String authorization_Code_Url = "https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=[YOUR_APPID]&redirect_uri=[YOUR_REDIRECT_URI]&scope=[THE_SCOPE]";
|
|
|
/**
|
* 获取Authorization Code 链接
|
* @return
|
*/
|
public static String getAuthorizationCodeUrl() {
|
String url = authorization_Code_Url.replace("[YOUR_APPID]", APP_ID).replace("[YOUR_REDIRECT_URI]", back_url).replace("[THE_SCOPE]", "get_user_info");
|
return url;
|
}
|
|
|
/**
|
* 通过Authorization Code获取Access Token的链接
|
*/
|
private static String access_token_url = "https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=[YOUR_APP_ID]&client_secret=[YOUR_APP_Key]&code=[The_AUTHORIZATION_CODE]&state=[The_CLIENT_STATE]&redirect_uri=[YOUR_REDIRECT_URI]";
|
|
|
/**
|
* 通过Authorization Code获取Access Token
|
*/
|
public static String getAccessTokenUrl(String code) {
|
String url = access_token_url.replace("[YOUR_APP_ID]", APP_ID).replace("[YOUR_APP_Key]", APP_KEY).replace("[The_AUTHORIZATION_CODE]", code).replace("[The_CLIENT_STATE]", "0").replace("[YOUR_REDIRECT_URI]", back_url);
|
return url;
|
}
|
|
|
|
/**
|
* 通过AccessToken获取OpenId链接
|
*/
|
private static String openId_url = "https://graph.qq.com/oauth2.0/me?access_token=YOUR_ACCESS_TOKEN";
|
|
/**
|
* 获取openId链接
|
*/
|
public static String getOpenIdUrl(String accessToken) {
|
String url = openId_url.replace("YOUR_ACCESS_TOKEN", accessToken);
|
return url;
|
}
|
|
|
/**
|
* 用户昵称信息链接
|
*/
|
private static String get_user_info_url = "https://graph.qq.com/user/get_user_info?access_token=YOUR_ACCESS_TOKEN&oauth_consumer_key=YOUR_APP_ID&openid=YOUR_OPENID";
|
|
/**
|
* 获取用户昵称链接
|
*/
|
public static String getUserInfoUrl(String accessToken,String openId) {
|
String url = get_user_info_url.replace("YOUR_ACCESS_TOKEN", accessToken).replace("YOUR_APP_ID", APP_ID).replace("YOUR_OPENID", openId);
|
return url;
|
}
|
}
|