|
|
@ -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")); |
|
|
|