|
|
@ -12,6 +12,7 @@ import cc.yunxi.service.IClientService;
|
|
|
|
import cc.yunxi.service.ICommonService;
|
|
|
|
import cc.yunxi.service.ICommonService;
|
|
|
|
import cc.yunxi.service.IRecyclerService;
|
|
|
|
import cc.yunxi.service.IRecyclerService;
|
|
|
|
import cc.yunxi.utils.JwtTool;
|
|
|
|
import cc.yunxi.utils.JwtTool;
|
|
|
|
|
|
|
|
import cc.yunxi.utils.RedisTool;
|
|
|
|
import cc.yunxi.utils.WeChatUtil;
|
|
|
|
import cc.yunxi.utils.WeChatUtil;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
@ -22,12 +23,15 @@ import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 统一服务类
|
|
|
|
* 统一服务类
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
@Slf4j
|
|
|
|
@Slf4j
|
|
|
|
|
|
|
|
//@CacheConfig(cacheNames = "AUTH_TOKEN")
|
|
|
|
public class CommonService implements ICommonService {
|
|
|
|
public class CommonService implements ICommonService {
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
@ -36,15 +40,23 @@ public class CommonService implements ICommonService {
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private IClientService clientService;
|
|
|
|
private IClientService clientService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private RedisTool redisTool;
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private WxHsyProperties wxHsyProperties;
|
|
|
|
private WxHsyProperties wxHsyProperties;
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private WxShProperties wxShProperties;
|
|
|
|
private WxShProperties wxShProperties;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private JwtTool jwtTool;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String code2SessionUrl = "https://api.weixin.qq.com/sns/jscode2session";
|
|
|
|
private static final String code2SessionUrl = "https://api.weixin.qq.com/sns/jscode2session";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final String TOKEN_KEY = "AUTH_TOKEN_";
|
|
|
|
|
|
|
|
|
|
|
|
private UserDTO wxAuthentication(WxLoginDTO wxLoginDTO) {
|
|
|
|
private UserDTO wxAuthentication(WxLoginDTO wxLoginDTO) {
|
|
|
|
log.info("login request body:{}", wxLoginDTO);
|
|
|
|
log.info("login request body:{}", wxLoginDTO);
|
|
|
|
// String url = code2SessionUrl +"?appid=" + wxHsyProperties.getAppId() +
|
|
|
|
// String url = code2SessionUrl +"?appid=" + wxHsyProperties.getAppId() +
|
|
|
@ -92,6 +104,7 @@ public class CommonService implements ICommonService {
|
|
|
|
userDTO.setStationId(recycler.getStationId());
|
|
|
|
userDTO.setStationId(recycler.getStationId());
|
|
|
|
userDTO.setUserType(UserTypeEnum.RECYCLER);
|
|
|
|
userDTO.setUserType(UserTypeEnum.RECYCLER);
|
|
|
|
userDTO.setUsername(recycler.getStaffsName());
|
|
|
|
userDTO.setUsername(recycler.getStaffsName());
|
|
|
|
|
|
|
|
userDTO.setToken(this.createToken(userDTO));
|
|
|
|
return userDTO;
|
|
|
|
return userDTO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -106,6 +119,34 @@ public class CommonService implements ICommonService {
|
|
|
|
userDTO.setId(client.getId());
|
|
|
|
userDTO.setId(client.getId());
|
|
|
|
userDTO.setUserType(UserTypeEnum.CLIENT);
|
|
|
|
userDTO.setUserType(UserTypeEnum.CLIENT);
|
|
|
|
userDTO.setUsername(client.getNickName());
|
|
|
|
userDTO.setUsername(client.getNickName());
|
|
|
|
|
|
|
|
userDTO.setToken(this.createToken(userDTO));
|
|
|
|
return userDTO;
|
|
|
|
return userDTO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void logout(String token) {
|
|
|
|
|
|
|
|
removeToken(token);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 创建token
|
|
|
|
|
|
|
|
* @param userDTO
|
|
|
|
|
|
|
|
* @return token
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private String createToken(UserDTO userDTO) {
|
|
|
|
|
|
|
|
String token = jwtTool.createToken(userDTO);
|
|
|
|
|
|
|
|
userDTO.setToken(token);
|
|
|
|
|
|
|
|
// 缓存token
|
|
|
|
|
|
|
|
redisTool.setValue(TOKEN_KEY + token, userDTO, userDTO.getTimeExpire());
|
|
|
|
|
|
|
|
return token;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 删除token
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public void removeToken(String token) {
|
|
|
|
|
|
|
|
redisTool.expireKeyAt(TOKEN_KEY + token, new Date());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|