| @@ -143,7 +143,7 @@ public class WxInfoController extends BaseController { | |||||
| } else { | } else { | ||||
| // 检查token是否已过期, 小时就重新获取 | // 检查token是否已过期, 小时就重新获取 | ||||
| Date curDate = new Date(); | Date curDate = new Date(); | ||||
| if(curDate.getTime() > wxAppinfo.getLastTokenTime().getTime() + Constant.C_EXPIRE) { | |||||
| if(curDate.getTime() > wxAppinfo.getLastTokenTime().getTime() + Constant.H_EXPIRE) { | |||||
| try { | try { | ||||
| String accessToken = wxMaService.getAccessToken(true); | String accessToken = wxMaService.getAccessToken(true); | ||||
| wxAppinfo.setAccessToken(accessToken); | wxAppinfo.setAccessToken(accessToken); | ||||
| @@ -167,8 +167,7 @@ public class WxMerchantBUserController extends BaseController { | |||||
| } | } | ||||
| // check password | // check password | ||||
| if (user1.getUserPwd().equalsIgnoreCase(password)) { | if (user1.getUserPwd().equalsIgnoreCase(password)) { | ||||
| user1.createToken(currentDate); | |||||
| token = user1.getToken(); | |||||
| token = user1.createToken(currentDate); | |||||
| resultMap.put("token", token); | resultMap.put("token", token); | ||||
| resultMap.put("bUserId",user1.getId()); | resultMap.put("bUserId",user1.getId()); | ||||
| request.setAttribute(Constant.LOGIN_USER_KEY, user1.getId()); | request.setAttribute(Constant.LOGIN_USER_KEY, user1.getId()); | ||||
| @@ -130,7 +130,7 @@ public class WxUserGrantController extends BaseController { | |||||
| } else { | } else { | ||||
| // 检查token是否已过期, 1小时就重新获取 | // 检查token是否已过期, 1小时就重新获取 | ||||
| Date curDate = new Date(); | Date curDate = new Date(); | ||||
| if(curDate.getTime() > wxAppinfo.getLastTokenTime().getTime() + Constant.C_EXPIRE) { | |||||
| if(curDate.getTime() > wxAppinfo.getLastTokenTime().getTime() + Constant.H_EXPIRE) { | |||||
| updateAppAccessToken(wxAppinfo, wxMaService); | updateAppAccessToken(wxAppinfo, wxMaService); | ||||
| wxMaService = getWeappServiceByAppInfo(wxAppinfo); | wxMaService = getWeappServiceByAppInfo(wxAppinfo); | ||||
| } | } | ||||
| @@ -588,12 +588,12 @@ public class WxCUser implements Serializable { | |||||
| } | } | ||||
| public String createToken(Date currentDate) { | public String createToken(Date currentDate) { | ||||
| if (expireTime == null || expireTime.getTime() < currentDate.getTime()) | |||||
| if (expireTime == null || expireTime.getTime() - Constant.H_EXPIRE < currentDate.getTime()) | |||||
| { | { | ||||
| //生成一个token | //生成一个token | ||||
| this.token = UUID.randomUUID().toString(); | this.token = UUID.randomUUID().toString(); | ||||
| //过期时间 | //过期时间 | ||||
| this.expireTime = new Date(currentDate.getTime() + Constant.EXPIRE * 1000); | |||||
| this.expireTime = new Date(currentDate.getTime() + Constant.EXPIRE); | |||||
| } | } | ||||
| return this.token; | return this.token; | ||||
| } | } | ||||
| @@ -235,14 +235,15 @@ public class WxMerchantBUser implements Serializable { | |||||
| } | } | ||||
| } | } | ||||
| public void createToken(Date currentDate) { | |||||
| if (expireTime == null || expireTime.getTime() < currentDate.getTime()) { | |||||
| //生成一个token | |||||
| public String createToken(Date currentDate) { | |||||
| if (expireTime == null || expireTime.getTime() - Constant.H_EXPIRE < currentDate.getTime()) { | |||||
| //提前一小时, 新生成一个token | |||||
| String token = UUID.randomUUID().toString(); | String token = UUID.randomUUID().toString(); | ||||
| //过期时间 | //过期时间 | ||||
| Date expireTime = new Date(currentDate.getTime() + Constant.EXPIRE * 1000); | |||||
| Date expireTime = new Date(currentDate.getTime() + Constant.EXPIRE); | |||||
| setToken(token); | setToken(token); | ||||
| setExpireTime(expireTime); | setExpireTime(expireTime); | ||||
| } | } | ||||
| return this.token; | |||||
| } | } | ||||
| } | } | ||||
| @@ -3,10 +3,10 @@ package com.iformall.utils; | |||||
| public class Constant { | public class Constant { | ||||
| // 1小时过期, | // 1小时过期, | ||||
| public final static int C_EXPIRE = 3600000; | |||||
| public final static int H_EXPIRE = 3600000; | |||||
| // TOKEN过期时间, 24小时后过期 | // TOKEN过期时间, 24小时后过期 | ||||
| public final static int EXPIRE = 3600 * 24; | |||||
| public final static int EXPIRE = H_EXPIRE * 24; | |||||
| // C端token | // C端token | ||||
| public static final String LOGIN_USER_KEY = "LOGIN_USER_KEY"; | public static final String LOGIN_USER_KEY = "LOGIN_USER_KEY"; | ||||