|
@@ -26,10 +26,12 @@ public class WeiXinUserUtil {
|
|
|
//public final static String weiXinUserInfo_url = "https://api.weixin.qq.com/sns/userinfo?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN";
|
|
|
//凭证获取路径
|
|
|
public final static String token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET";
|
|
|
+
|
|
|
//微信小程序路径获取openID "https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=APPSECRET&js_code=CODE&grant_type=authorization_code";
|
|
|
- public final static String openID_url ="https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=APPSECRET&js_code=CODE&grant_type=authorization_code";
|
|
|
- //根据 appID secret code
|
|
|
- //public final static String request_Url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code";
|
|
|
+ public final static String OPENID_URL ="https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=APPSECRET&js_code=CODE&grant_type=authorization_code";
|
|
|
+
|
|
|
+ //微信公众号获取通过code换取网页授权access_token
|
|
|
+ public final static String GZHAUTHORIZEINFO_URL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code";
|
|
|
|
|
|
//获取UnionId
|
|
|
public final static String unionId_Url ="https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN";
|
|
@@ -37,8 +39,20 @@ public class WeiXinUserUtil {
|
|
|
//日志
|
|
|
private static final Logger logger = LoggerFactory.getLogger(WeiXinUserUtil.class);
|
|
|
|
|
|
-// @Resource
|
|
|
-// private RedisCacheUtil redisCacheUtil;
|
|
|
+ /*
|
|
|
+ * 获取用户公众号的授权信息
|
|
|
+ * @param appId
|
|
|
+ * @param appSecret
|
|
|
+ * @param code
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static JSONObject getGzhAuthorizeInfo(String appId, String appSecret, String code){
|
|
|
+ logger.info("appId参数: "+ appId+" ;appSecret参数: " +appSecret +" ;code参数: " +code);
|
|
|
+ String requestUrl = GZHAUTHORIZEINFO_URL.replace("APPID", appId).replace("SECRET", appSecret).replace("CODE", code);
|
|
|
+ JSONObject jsonObject = HttpRequestUtil.getHttpsRequestData(requestUrl, "GET", null);
|
|
|
+ logger.info("获取用户公众号的授权后信息:" + jsonObject.toString());
|
|
|
+ return jsonObject;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/*
|
|
@@ -62,7 +76,7 @@ public class WeiXinUserUtil {
|
|
|
* @return
|
|
|
*/
|
|
|
public static Map<String, Object> getUserSessionKeyAndOpenID(String appId, String appSecret, String code){
|
|
|
- String requestUrl = openID_url.replace("APPID", appId).replace("APPSECRET", appSecret).replace("CODE", code);
|
|
|
+ String requestUrl = OPENID_URL.replace("APPID", appId).replace("APPSECRET", appSecret).replace("CODE", code);
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
//发起GET请求
|
|
|
JSONObject jsonObject = HttpRequestUtil.getHttpsRequestData(requestUrl, "GET", null);
|