Commit ea227a05 authored by 廖旭伟's avatar 廖旭伟

修改token存取方式

parent 0d7fef77
......@@ -3,10 +3,12 @@ package com.mortals.xhx.protocol.complex;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ICacheService;
import com.mortals.xhx.protocol.complex.matter.model.req.DeviceLoginReq;
import com.mortals.xhx.protocol.complex.matter.model.rsp.LoginRspInfo;
import com.mortals.xhx.protocol.complex.matter.service.IComplexMatterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.ObjectUtils;
......@@ -28,11 +30,18 @@ public abstract class AbstractComplexService implements IComplexMatterService {
//综窗接件token deviceCode--对应tokenMap
public static Map<String, String> tokenMap=new HashMap<>();
public static String DEVICE_LOGO_TOKEN = "device:logo:token";
/***/
public static Long TOKEN_TIMEOUT = 3600l;
@Autowired
private ICacheService iCacheService;
@Override
public String getToken(String deviceLogo) {
try {
String deviceToken = tokenMap.getOrDefault(deviceLogo, "");
String deviceToken = iCacheService.get(DEVICE_LOGO_TOKEN);
if (ObjectUtils.isEmpty(deviceToken)) {
DeviceLoginReq loginReq = new DeviceLoginReq();
loginReq.setDeviceLogo(deviceLogo);
......@@ -47,4 +56,9 @@ public abstract class AbstractComplexService implements IComplexMatterService {
}
}
@Override
public void setToken(String token){
iCacheService.set(DEVICE_LOGO_TOKEN,token,TOKEN_TIMEOUT);
}
}
......@@ -7,4 +7,5 @@ package com.mortals.xhx.protocol.complex;
*/
public interface IComplexService {
String getToken(String deviceLogo);
void setToken(String token);
}
......@@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.mortals.framework.common.Rest;
import com.mortals.framework.service.ICacheService;
import com.mortals.xhx.protocol.complex.AbstractComplexService;
import com.mortals.xhx.protocol.complex.ComplexApiRest;
import com.mortals.xhx.protocol.complex.matter.model.req.AcceptReq;
......@@ -23,6 +24,7 @@ import com.mortals.xhx.protocol.complex.matter.model.rsp.matter.MatterWorkInfo;
import com.mortals.xhx.protocol.complex.matter.model.rsp.work.WorkInfo;
import com.mortals.xhx.protocol.complex.matter.service.IComplexMatterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
......@@ -41,6 +43,8 @@ import java.util.Map;
@Slf4j
public class ComplexMatterServiceImpl extends AbstractComplexService implements IComplexMatterService {
//token有效期 10小时
@Override
public Rest<LoginRspInfo> deviceLogin(DeviceLoginReq loginReq) {
......@@ -54,7 +58,8 @@ public class ComplexMatterServiceImpl extends AbstractComplexService implements
//更新token
String deviceLoginToken = complexApiRest.getResult().getToken();
String deviceLogo = complexApiRest.getResult().getSelfDeviceInfo().getDeviceLogo();
this.tokenMap.put(deviceLogo, deviceLoginToken);
//this.tokenMap.put(deviceLogo, deviceLoginToken);
this.setToken(deviceLoginToken);
return Rest.ok(complexApiRest.getMessage(), complexApiRest.getResult());
}
return Rest.fail(complexApiRest.getMessage());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment