处理token 失效问题
This commit is contained in:
parent
011dbf48c6
commit
a6ab62fa82
@ -6,6 +6,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
@ -98,13 +99,7 @@ public class LoginServiceImpl implements LoginService {
|
|||||||
String res = LoginUtil.checkSessionKey(accessTokenService.getAccessToken(), openid, hmac.digestHex(""));
|
String res = LoginUtil.checkSessionKey(accessTokenService.getAccessToken(), openid, hmac.digestHex(""));
|
||||||
JSONObject jo = JSONUtil.parseObj(res);
|
JSONObject jo = JSONUtil.parseObj(res);
|
||||||
if (jo.getInt("errcode") == 0) {
|
if (jo.getInt("errcode") == 0) {
|
||||||
//Map<String, String> m = tokenBuilder(wuid);
|
Map<String, String> m = tokenBuilder(wuid);
|
||||||
String wxToken= String.valueOf(redisUtil.get(HDConstant.wxToken + wuid));
|
|
||||||
//刷新token的过期时间
|
|
||||||
redisUtil.set(HDConstant.wxToken + wuid, wxToken, tokenExpHour * 3600L);
|
|
||||||
Map<String, String> m = new HashMap<String, String>();
|
|
||||||
m.put("wuid", wuid);
|
|
||||||
m.put("wxToken", wxToken);
|
|
||||||
return new Result<Map<String, String>>().success(m);
|
return new Result<Map<String, String>>().success(m);
|
||||||
}
|
}
|
||||||
return new Result<Map<String, String>>().error(CodeMsg.WECHAT_SERRION_ERROR, jo);
|
return new Result<Map<String, String>>().error(CodeMsg.WECHAT_SERRION_ERROR, jo);
|
||||||
@ -137,10 +132,16 @@ public class LoginServiceImpl implements LoginService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> tokenBuilder(String wuid) {
|
public Map<String, String> tokenBuilder(String wuid) {
|
||||||
String randomStr = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_FORMATTER);
|
//获取redis中的token
|
||||||
String wxToken = XCXUtil.wechatToken(wuid, randomStr);
|
String wxToken = ((redisUtil.hasKey(HDConstant.wxToken + wuid) && !ObjectUtils.isEmpty(redisUtil.get(HDConstant.wxToken + wuid))) ? String.valueOf(redisUtil.get(HDConstant.wxToken + wuid)) : null);
|
||||||
|
if(StringUtils.isEmpty(wxToken)) {
|
||||||
|
String randomStr = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_FORMATTER);
|
||||||
|
wxToken = XCXUtil.wechatToken(wuid, randomStr);
|
||||||
|
redisUtil.set(HDConstant.tokenRandomStr + wuid, randomStr);
|
||||||
|
}
|
||||||
|
//刷新token
|
||||||
redisUtil.set(HDConstant.wxToken + wuid, wxToken, tokenExpHour * 3600L);
|
redisUtil.set(HDConstant.wxToken + wuid, wxToken, tokenExpHour * 3600L);
|
||||||
redisUtil.set(HDConstant.tokenRandomStr + wuid, randomStr);
|
|
||||||
Map<String, String> m = new HashMap<String, String>();
|
Map<String, String> m = new HashMap<String, String>();
|
||||||
m.put("wuid", wuid);
|
m.put("wuid", wuid);
|
||||||
m.put("wxToken", wxToken);
|
m.put("wxToken", wxToken);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user