Merge remote-tracking branch 'refs/remotes/origin/debug-login'

# Conflicts:
#	smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/auth/wx/AccessTokenUtil.java
#	smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/constant/CacheConstants.java
This commit is contained in:
墨大叔 2024-09-23 19:47:17 +08:00
commit cc1da5cc4a
2 changed files with 21 additions and 17 deletions

View File

@ -8,17 +8,13 @@ import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.concurrent.TimeUnit;
public class AccessTokenUtil {
/** 缓存token */
private static String cachedToken;
/** token过期时间 */
private static long tokenExpirationTime;
public static final String APPID = SpringUtils.getRequiredProperty("wx.appid");
public static final String APP_SECRET = SpringUtils.getRequiredProperty("wx.appSecret");
@SneakyThrows
public static String getToken() {
@ -26,12 +22,10 @@ public class AccessTokenUtil {
String token = redisCache.getCacheObject(CacheConstants.WX_ACCESS_TOKEN);
if (StringUtils.isBlank(token)) {
String APPID = SpringUtils.getRequiredProperty("wx.appid");
String APPSECRET = SpringUtils.getRequiredProperty("wx.appSecret");
WxMaService wxMaService = new WxMaServiceImpl();
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
config.setAppid(APPID);
config.setSecret(APPSECRET);
config.setSecret(APP_SECRET);
wxMaService.setWxMaConfig(config);
token = wxMaService.getAccessToken();
@ -39,9 +33,4 @@ public class AccessTokenUtil {
}
return token;
}
/**判断token是否过期*/
private static boolean isTokenExpired() {
return cachedToken == null || System.currentTimeMillis() > tokenExpirationTime;
}
}

View File

@ -18,6 +18,7 @@ import com.ruoyi.ss.user.service.ISmUserService;
import com.ruoyi.ss.account.service.AccountService;
import com.ruoyi.ss.account.domain.enums.AccountType;
import com.ruoyi.system.service.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
@ -54,6 +55,7 @@ import java.util.Objects;
* @author ruoyi
*/
@Component
@Slf4j
public class SysLoginService
{
@Autowired
@ -267,6 +269,7 @@ public class SysLoginService
// 通过授权码获取微信手机号
String phoneNumber = getWxPhoneNumber(body.getMobileCode());
ServiceUtil.assertion(StringUtils.isBlank(phoneNumber), "获取授权手机号失败");
// 判断用户是否注册未注册的自动注册
user = smUserService.selectUserByPhone(phoneNumber);
@ -341,11 +344,23 @@ public class SysLoginService
JSONObject jsonObject = new JSONObject();
jsonObject.put("code", mobileCode);
String post = HttpUtils.sendPost(url, jsonObject.toString());
log.info("获取手机号body:{}", post);
// 获取微信用户手机号
JSONObject jsonObject1 = JSONObject.parseObject(post);
String phoneInfo = jsonObject1.getString("phone_info");
JSONObject body = JSONObject.parseObject(post);
if (body == null) {
return null;
}
Integer errcode = body.getInteger("errcode");
if (errcode == null || !errcode.equals(0)) {
throw new ServiceException("获取手机号失败:" + body.getString("errmsg"));
}
String phoneInfo = body.getString("phone_info");
WxMaPhoneNumberInfo wxMaPhoneNumberInfo = JSONObject.parseObject(phoneInfo, WxMaPhoneNumberInfo.class);
if (wxMaPhoneNumberInfo == null) {
return null;
}
return wxMaPhoneNumberInfo.getPhoneNumber();
}