package cn.ksource.core.util;
|
|
import cn.ksource.config.SysConfigConstants;
|
|
/**
|
* 微信登录工具类
|
* @author jxl
|
* @微信开放平台账户:ksource6366@126.com
|
* @微信开放平台密码:63661766
|
*/
|
|
public class WechatUtil {
|
|
private static String APP_ID = "wxffa85f040c3f2209";
|
|
private static String APP_KEY = "141db7caef0c200bcf54322666a42d1a";
|
|
//备份APPSECRET
|
//private static String APP_KEY = "141db7caef0c200bcf54322666a42d1a";
|
|
|
//微信回调地址
|
private static String back_url = SysConfigConstants.WEBCHAT_ADDRESS+"/business/wechatCallBack.html";
|
|
/**
|
* Authorization Code 链接
|
*/
|
private static String authorization_Code_Url = "https://open.weixin.qq.com/connect/qrconnect?appid=[YOUR_APPID]&redirect_uri=[YOUR_REDIRECT_URI]&response_type=code&scope=[THE_SCOPE]&state=[THE_STATE]#wechat_redirect";
|
|
|
/**
|
* 获取 Code 链接
|
* @return
|
*/
|
public static String getAuthorizationCodeUrl(String state) {
|
String url = authorization_Code_Url.replace("[YOUR_APPID]", APP_ID).replace("[YOUR_REDIRECT_URI]", back_url).replace("[THE_SCOPE]", "snsapi_login").replace("[THE_STATE]", state);
|
return url;
|
}
|
|
|
/**
|
* 通过 Code获取Access Token的链接
|
*/
|
private static String access_token_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=[YOUR_APP_ID]&secret=[YOUR_APP_Key]&code=[The_AUTHORIZATION_CODE]&grant_type=[the_grant_type]";
|
|
|
/**
|
* 通过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_grant_type]", "authorization_code");
|
return url;
|
}
|
|
|
|
/**
|
* 获取用户个人信息
|
*/
|
private static String get_user_info_url = "https://api.weixin.qq.com/sns/userinfo?access_token=YOUR_ACCESS_TOKEN&openid=YOUR_OPENID";
|
|
/**
|
* 获取用户昵称链接
|
*/
|
public static String getUserInfoUrl(String accessToken,String openId) {
|
String url = get_user_info_url.replace("YOUR_ACCESS_TOKEN", accessToken).replace("YOUR_OPENID", openId);
|
return url;
|
}
|
}
|