|
@@ -32,6 +32,7 @@ import io.swagger.annotations.Api;
|
|
|
import java.io.File;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -118,7 +119,7 @@ public class UserController extends BaseApiController {
|
|
|
appSecret = userAppSecret;
|
|
|
}
|
|
|
//调用微信后台接口获取openId
|
|
|
- String res = wxLoginCheck(wxLoginParams, appId, appSecret);
|
|
|
+ String res = wxLoginCheck(wxLoginParams.getCode(), appId, appSecret);
|
|
|
JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
String openId = jsonObject.getString("openid");
|
|
|
String sessionKey = jsonObject.getString("session_key");
|
|
@@ -195,8 +196,18 @@ public class UserController extends BaseApiController {
|
|
|
}
|
|
|
phoneInfo = jsonObject.getJSONObject("phone_info");
|
|
|
} else {
|
|
|
- BASE64Encoder encoder = new BASE64Encoder();
|
|
|
- String res = weixinDecrypt(wxLoginParams.getEncryptedData(), encoder.encode(appSecret.getBytes()), wxLoginParams.getIv());
|
|
|
+ //调用微信后台接口获取openId
|
|
|
+ String rtn = wxLoginCheck(wxLoginParams.getLoginCode(), appId, appSecret);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(rtn);
|
|
|
+ String openId = jsonObject.getString("openid");
|
|
|
+ String sessionKey = jsonObject.getString("session_key");
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(openId) || StringUtils.isBlank(sessionKey)) {
|
|
|
+ LogUtil.error(logger, "微信登录失败:" + jsonObject.toJSONString());
|
|
|
+ return error("登录失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ String res = weixinDecrypt(wxLoginParams.getEncryptedData(), sessionKey, wxLoginParams.getIv());
|
|
|
if (StringUtils.isBlank(res)) {
|
|
|
return error("手机号获取失败");
|
|
|
}
|
|
@@ -302,8 +313,8 @@ public class UserController extends BaseApiController {
|
|
|
* @param
|
|
|
* @return
|
|
|
*/
|
|
|
- private String wxLoginCheck(WxLoginParams params, String appId, String appSecret) {
|
|
|
- String param = "appid=" + appId + "&secret=" + appSecret + "&js_code=" + params.getCode()
|
|
|
+ private String wxLoginCheck(String code, String appId, String appSecret) {
|
|
|
+ String param = "appid=" + appId + "&secret=" + appSecret + "&js_code=" + code
|
|
|
+ "&grant_type=authorization_code";
|
|
|
String res = HttpUtils.sendGet("https://api.weixin.qq.com/sns/jscode2session", param);
|
|
|
return res;
|
|
@@ -419,6 +430,13 @@ public class UserController extends BaseApiController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ public static void main(String[] args) {
|
|
|
+ UserController userController = new UserController();
|
|
|
+ BASE64Encoder encoder = new BASE64Encoder();
|
|
|
+ String sessionKey = encoder.encode("f7a104e09d6c2e55445be2a45c4ab551".getBytes(
|
|
|
+ StandardCharsets.UTF_8));
|
|
|
+ System.out.println(sessionKey);
|
|
|
+ System.out.println(userController.weixinDecrypt("1U2iT7fucPip+hYDO+fcksOJCyFMIzxe5qXKGPbLZVfz2kwlKkbRDbfjECRHtjg0yFiTXpHuvR9gBShL9Id7p8KO1w2Y2vhgj5idU/VYSOhF7IRyXEObDApMCs4JSWuS997hIl/JMX3N43IHC99Ak5aeTuk4UHtvHeJsTYfvNKrp7c4fDt0n9yX9MJijsoOjFQ/TFh0jJuWKpzS2QwhdGg==", sessionKey, "C9Kc2ibw/cy7U0Vv6vneOg=="));
|
|
|
+ }
|
|
|
|
|
|
}
|