|
@@ -18,15 +18,8 @@ public class WxUtil {
|
|
|
* @description app端通过用户授权码获取用户openId
|
|
|
*/
|
|
|
public static String getAppOpenIdByAuthCode(String authCode) {
|
|
|
- String url = WxConstants.AppConfigConstants.USER_INFO_ACCESS_TOKEN_URL
|
|
|
- .replace("APPID", WxConstants.AppConfigConstants.APP_ID)
|
|
|
- .replace("SECRET", WxConstants.AppConfigConstants.APP_SECRET)
|
|
|
- .replace("CODE", authCode);
|
|
|
- JSONObject result = JSONUtil.parseObj(HttpUtil.get(url));
|
|
|
- if (result.containsKey("openid")) {
|
|
|
- return result.getStr("openid");
|
|
|
- }
|
|
|
- return null;
|
|
|
+ return getOpenIdByAuthCode(authCode, WxConstants.AppConfigConstants.APP_ID,
|
|
|
+ WxConstants.AppConfigConstants.APP_SECRET);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -36,9 +29,22 @@ public class WxUtil {
|
|
|
* @date 2020/4/27 10:36 上午
|
|
|
*/
|
|
|
public static String getAppletOpenIdByAuthCode(String authCode) {
|
|
|
- String url = WxConstants.AppletConfigConstants.AUTH_URL
|
|
|
- .replace("APPID", WxConstants.AppletConfigConstants.APP_ID)
|
|
|
- .replace("SECRET", WxConstants.AppletConfigConstants.APP_SECRET)
|
|
|
+ return getOpenIdByAuthCode(authCode, WxConstants.AppletConfigConstants.APP_ID,
|
|
|
+ WxConstants.AppletConfigConstants.APP_SECRET);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param authCode 授权码
|
|
|
+ * @param appId appId
|
|
|
+ * @param appSecret appSecret
|
|
|
+ * @return openId
|
|
|
+ * @description 通过授权码获取微信openId
|
|
|
+ * @date 2020/4/30 2:47 下午
|
|
|
+ */
|
|
|
+ private static String getOpenIdByAuthCode(String authCode, String appId, String appSecret) {
|
|
|
+ String url = WxConstants.USER_INFO_ACCESS_TOKEN_URL
|
|
|
+ .replace("APPID", appId)
|
|
|
+ .replace("SECRET", appSecret)
|
|
|
.replace("CODE", authCode);
|
|
|
JSONObject result = JSONUtil.parseObj(HttpUtil.get(url));
|
|
|
if (result.containsKey("openid")) {
|