diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java index 2f468cb8..1cc5efeb 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java @@ -75,7 +75,7 @@ public class RedisCache */ public Long getExpire(final String key) { - return redisTemplate.getExpire(key); + return redisTemplate.getExpire(key,TimeUnit.SECONDS); } /** diff --git a/zc-business/src/main/java/com/zc/business/utils/QYWXUtil.java b/zc-business/src/main/java/com/zc/business/utils/QYWXUtil.java index 879fb0db..28135beb 100644 --- a/zc-business/src/main/java/com/zc/business/utils/QYWXUtil.java +++ b/zc-business/src/main/java/com/zc/business/utils/QYWXUtil.java @@ -95,8 +95,9 @@ public class QYWXUtil { int iErrorCode = objJsonObject.getIntValue("errcode"); if (iErrorCode == 0) { String strAccessToken = objJsonObject.getString("access_token"); + Integer expiresIn = objJsonObject.getInteger("expires_in"); // 设置到redis里,目前的存活时间为120分钟(7200秒) - redisCache.setCacheObject(RedisKeyConstants.QYWX_ACCESS_TOKEN,strAccessToken,7200, TimeUnit.SECONDS); + redisCache.setCacheObject(RedisKeyConstants.QYWX_ACCESS_TOKEN,strAccessToken,expiresIn, TimeUnit.SECONDS); return strAccessToken; } } @@ -137,11 +138,11 @@ public class QYWXUtil { if (iErrorCode == 0) { //返回用户id return objJsonObject.getString("userid"); - } else if (iErrorCode == 42001){ + } else if (iErrorCode == 42001 || iErrorCode == 40014){ //access_token过期,重新获取 getAccessTokenByHttp(); //重新获取userId - getUserIdByMobile(mobile); + return getUserIdByMobile(mobile); } System.out.println("通过手机号获取userId失败! 错误码:" + iErrorCode + ", 错误信息:" + objJsonObject.getString("errmsg")); } @@ -209,11 +210,11 @@ public class QYWXUtil { result.put("code","1"); result.put("msg","发送企业微信消息成功!"); result.put("data",msgId); - } else if (iErrorCode == 42001){ + } else if (iErrorCode == 42001 || iErrorCode == 40014){ //access_token过期,重新获取 getAccessTokenByHttp(); //重新发送文本消息 - sendMessageByWxUserId(userId,content); + return sendMessageByWxUserId(userId,content); } else { result.put("code","0"); result.put("msg","发送企业微信消息失败!错误码:" + iErrorCode + ", 错误信息:" + objJsonObject.getString("errmsg"));