Browse Source

企业微信api完善

develop
lau572 5 months ago
parent
commit
7ec3804405
  1. 2
      ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java
  2. 11
      zc-business/src/main/java/com/zc/business/utils/QYWXUtil.java

2
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) public Long getExpire(final String key)
{ {
return redisTemplate.getExpire(key); return redisTemplate.getExpire(key,TimeUnit.SECONDS);
} }
/** /**

11
zc-business/src/main/java/com/zc/business/utils/QYWXUtil.java

@ -95,8 +95,9 @@ public class QYWXUtil {
int iErrorCode = objJsonObject.getIntValue("errcode"); int iErrorCode = objJsonObject.getIntValue("errcode");
if (iErrorCode == 0) { if (iErrorCode == 0) {
String strAccessToken = objJsonObject.getString("access_token"); String strAccessToken = objJsonObject.getString("access_token");
Integer expiresIn = objJsonObject.getInteger("expires_in");
// 设置到redis里,目前的存活时间为120分钟(7200秒) // 设置到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; return strAccessToken;
} }
} }
@ -137,11 +138,11 @@ public class QYWXUtil {
if (iErrorCode == 0) { if (iErrorCode == 0) {
//返回用户id //返回用户id
return objJsonObject.getString("userid"); return objJsonObject.getString("userid");
} else if (iErrorCode == 42001){ } else if (iErrorCode == 42001 || iErrorCode == 40014){
//access_token过期,重新获取 //access_token过期,重新获取
getAccessTokenByHttp(); getAccessTokenByHttp();
//重新获取userId //重新获取userId
getUserIdByMobile(mobile); return getUserIdByMobile(mobile);
} }
System.out.println("通过手机号获取userId失败! 错误码:" + iErrorCode + ", 错误信息:" + objJsonObject.getString("errmsg")); System.out.println("通过手机号获取userId失败! 错误码:" + iErrorCode + ", 错误信息:" + objJsonObject.getString("errmsg"));
} }
@ -209,11 +210,11 @@ public class QYWXUtil {
result.put("code","1"); result.put("code","1");
result.put("msg","发送企业微信消息成功!"); result.put("msg","发送企业微信消息成功!");
result.put("data",msgId); result.put("data",msgId);
} else if (iErrorCode == 42001){ } else if (iErrorCode == 42001 || iErrorCode == 40014){
//access_token过期,重新获取 //access_token过期,重新获取
getAccessTokenByHttp(); getAccessTokenByHttp();
//重新发送文本消息 //重新发送文本消息
sendMessageByWxUserId(userId,content); return sendMessageByWxUserId(userId,content);
} else { } else {
result.put("code","0"); result.put("code","0");
result.put("msg","发送企业微信消息失败!错误码:" + iErrorCode + ", 错误信息:" + objJsonObject.getString("errmsg")); result.put("msg","发送企业微信消息失败!错误码:" + iErrorCode + ", 错误信息:" + objJsonObject.getString("errmsg"));

Loading…
Cancel
Save