1.fix token 2.interface to rest style

main
Gary 10 months ago
parent b1fd675442
commit 4af43dd130

@ -10,8 +10,6 @@ import enums.RequestFrequencyTypeEnum;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface GlobalInterceptor {
boolean checkLogin() default false;
boolean checkAppUserLogin() default false;
boolean checkAdminLogin() default false;

@ -6,6 +6,9 @@ public class Constants {
public static final String REDIS_KEY_IMAGE_CHECK_CODE = "redis_key_image_check_code_";
public static final String REDIS_KEY_MOBILE_CHECK_CODE = "redis_key_mobile_check_code_";
public static final String TOKEN_PREFIX = "Bearer ";
public static final int TOKEN_PREFIX_LENGTH = TOKEN_PREFIX.length();
public static final String TOKEN_ROLE = "roles";
public static final String TOKEN_ROLE_APP_USER = "user";

@ -6,6 +6,7 @@ import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.boot.context.properties.ConfigurationProperties;
import constants.Constants;
import dto.UserLoginDto;
import java.util.Date;
@ -68,11 +69,12 @@ public class JwtUtil {
.getBody();
}
public UserLoginDto getUserLoginDto(String token) {
public UserLoginDto getUserLoginDto(String authorization) {
try {
if (StringTools.isEmpty(token)) {
if (StringTools.isEmpty(authorization)||!authorization.startsWith(Constants.TOKEN_PREFIX)) {
return null;
}
String token = authorization.substring(Constants.TOKEN_PREFIX_LENGTH);
UserLoginDto userLoginDto=new UserLoginDto();
Claims claims = parseJWT(token);
userLoginDto.setUserId(claims.getId());

@ -18,15 +18,11 @@ import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import com.luoo.music.util.RedisUtils;
import constants.Constants;
import annotation.GlobalInterceptor;
import annotation.VerifyParam;
import api.StatusCode;
import constants.Constants;
import dto.UserLoginDto;
import enums.RequestFrequencyTypeEnum;
import exception.BizException;
import util.JwtUtil;
import util.StringTools;
@ -42,24 +38,14 @@ public class OperationAspect {
@Autowired
private JwtUtil jwtUtil;
@Autowired
private RedisUtils redisUtils;
@Before("@annotation(annotation.GlobalInterceptor)")
public void interceptorDo(JoinPoint point) {
Object[] arguments = point.getArgs();
Object target = point.getTarget();
Method method = ((MethodSignature) point.getSignature()).getMethod();
GlobalInterceptor interceptor = method.getAnnotation(GlobalInterceptor.class);
if (null == interceptor) {
return;
}
/**
*
*/
if (interceptor.checkLogin()) {
checkLogin();
}
/**
*
@ -82,26 +68,7 @@ public class OperationAspect {
validateParams(method, arguments);
}
/**
*
*/
if (interceptor.frequencyType() != RequestFrequencyTypeEnum.NO_LIMIT && interceptor.requestFrequencyThreshold() != 0) {
String fullMethodName = target.getClass().getName() + "." + method.getName();
checkRequestFrequency(fullMethodName, interceptor.frequencyType(), interceptor.requestFrequencyThreshold());
}
}
private void checkRequestFrequency(String fullMethodName, RequestFrequencyTypeEnum frequencyTyp, Integer threshold) {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String ip = getIpAddr(request);
ip = ip.replace(":", "");
String redisKey = fullMethodName + ip;
Object count=redisUtils.get(redisKey);
Integer cuCount= null==count?0:Integer.valueOf((String)count);
if (cuCount != null && cuCount > threshold - 1) {
throw new BizException(StatusCode.REQUEST_TOO_FREQUENCY);
}
redisUtils.increment(redisKey, 1, frequencyTyp.getSeconds());
}
private void checkAppUserLogin() {
UserLoginDto userLoginDto = getUserLoginDtoFromToken();
if (userLoginDto == null) {
@ -122,18 +89,11 @@ public class OperationAspect {
}
}
private void checkLogin() {
UserLoginDto userLoginDto = getUserLoginDtoFromToken();
if (userLoginDto == null) {
throw new BizException(StatusCode.UNAUTHORIZED);
}
}
private UserLoginDto getUserLoginDtoFromToken() {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
.getRequest();
String token = request.getHeader("token");
return jwtUtil.getUserLoginDto(token);
String authorization = request.getHeader("Authorization");
return jwtUtil.getUserLoginDto(authorization);
}
private void validateParams(Method method, Object[] arguments) {
@ -190,32 +150,4 @@ public class OperationAspect {
throw new BizException(StatusCode.VALIDATE_FAILED);
}
}
private String getIpAddr(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
// 多次反向代理后会有多个ip值第一个ip才是真实ip
if (ip.indexOf(",") != -1) {
ip = ip.split(",")[0];
}
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_CLIENT_IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("X-Real-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}
}

@ -47,12 +47,13 @@ public class JournalController {
@Autowired
private JwtUtil jwtUtil;
@ApiOperation(value = "1.查询期刊信息", notes = "若token为空或token校验失败默认返回最新的10期期刊筛选条件对游客不可用")
@ApiOperation(value = "1.查询期刊信息", notes = "若authorization为空或authorization校验失败默认返回最新的10期期刊筛选条件对游客不可用")
@GetMapping("/list")
@GlobalInterceptor
public Result<PageResult<JournalRespDTO>> page(@RequestHeader(value = "token", required = false) String token,
public Result<PageResult<JournalRespDTO>> page(
@RequestHeader(value = "Authorization", required = false) String authorization,
@VerifyParam JournalQueryReq queryReq) {
UserLoginDto user = jwtUtil.getUserLoginDto(token);
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
if (null == user) {
queryReq.setLanguage(null);
queryReq.setStyle(null);
@ -75,6 +76,7 @@ public class JournalController {
@GetMapping("/collect/{userId}/{pageNum}/{pageSize}")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<PageResult<JournalRespDTO>> collectPage(
@RequestHeader(value = "Authorization", required = false) String authorization,
@PathVariable @VerifyParam(required = true)String userId,
@PathVariable @VerifyParam(required = true)Integer pageNum,
@PathVariable @VerifyParam(required = true)Integer pageSize) {
@ -89,9 +91,9 @@ public class JournalController {
@ApiOperation(value = "3.根据期刊id查询期刊信息")
@GetMapping("/{id}")
@GlobalInterceptor
public Result<JournalRespDTO> findById(@RequestHeader(value = "token", required = false) String token,
public Result<JournalRespDTO> findById(@RequestHeader(value = "Authorization", required = false) String authorization,
@PathVariable @VerifyParam(required = true) String id) {
UserLoginDto user = jwtUtil.getUserLoginDto(token);
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
Article journal=articleService.findById(id);
Set<String> journalCollectSet = null==user?Collections.emptySet():userCollectService.getCollectSet(user.getUserId(),CollectTypeEnum.JOURNAL);
return Result.success(getJournalRespDTO(journal, journalCollectSet));

@ -58,9 +58,10 @@ public class SongController {
@ApiOperation(value = "1.根据期刊号查询歌曲信息", notes = "若为游客期刊号须在最新10期内")
@GetMapping("/getByJournalNo/{journalNo}")
@GlobalInterceptor
public Result<List<SongRespDTO>> getByJournalNo(@RequestHeader(value = "token", required = false) String token,
public Result<List<SongRespDTO>> getByJournalNo(
@RequestHeader(value = "Authorization", required = false) String authorization,
@PathVariable String journalNo) {
UserLoginDto user = jwtUtil.getUserLoginDto(token);
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
if (null == user && !isLatest10(journalNo)) {
return Result.unauthorized(null);
}
@ -82,7 +83,9 @@ public class SongController {
@ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true) })
@GetMapping("/collect/{userId}/{pageNum}/{pageSize}")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<PageResult<SongRespDTO>> collectPage(@PathVariable @VerifyParam(required = true) String userId,
public Result<PageResult<SongRespDTO>> collectPage(
@RequestHeader(value = "Authorization", required = false) String authorization,
@PathVariable @VerifyParam(required = true) String userId,
@PathVariable @VerifyParam(required = true) Integer pageNum,
@PathVariable @VerifyParam(required = true) Integer pageSize) {
List<String> objectIds = userCollectService.getCollectList(userId, pageNum, pageSize, CollectTypeEnum.SONG);
@ -98,10 +101,11 @@ public class SongController {
@ApiImplicitParams({ @ApiImplicitParam(name = "limit", value = "随机歌曲数最少1首最多30首", required = false) })
@GetMapping("/random/{limit}")
@GlobalInterceptor
public Result<List<SongRespDTO>> random(@RequestHeader(value = "token", required = false) String token,
public Result<List<SongRespDTO>> random(
@RequestHeader(value = "Authorization", required = false) String authorization,
@PathVariable @VerifyParam(required = true, regex = VerifyRegexEnum.RANDOM_SONG_LIMIT) Integer limit) {
List<Song> songs = songService.random(limit);
UserLoginDto user = jwtUtil.getUserLoginDto(token);
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
Set<String> songCollectSet = null == user ? Collections.emptySet()
: userCollectService.getCollectSet(user.getUserId(), CollectTypeEnum.SONG);
List<SongRespDTO> results = songs.stream().map(s -> getSongRespDTO(s, songCollectSet))
@ -112,9 +116,9 @@ public class SongController {
@ApiOperation(value = "4.根据歌曲id查询歌曲信息")
@GetMapping("/{id}")
@GlobalInterceptor
public Result<SongRespDTO> findById(@RequestHeader(value = "token", required = false) String token,
public Result<SongRespDTO> findById(@RequestHeader(value = "Authorization", required = false) String authorization,
@PathVariable @VerifyParam(required = true) String id) {
UserLoginDto user = jwtUtil.getUserLoginDto(token);
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
Song song = songService.findById(id);
Set<String> songCollectSet = null == user ? Collections.emptySet()
: userCollectService.getCollectSet(user.getUserId(), CollectTypeEnum.SONG);
@ -154,99 +158,72 @@ public class SongController {
* @param size
* @return
*/
@PostMapping("/search/{page}/{size}")
public Result<PageResult<Song>> findSearch(@RequestBody Map searchMap, @PathVariable int page,
@PathVariable int size) {
Page<Song> pageList = songService.findSearch(searchMap, page, size);
return Result.success(new PageResult<Song>(pageList.getTotalElements(), pageList.getContent()));
}
@PostMapping("/init")
public Result<Void> init(@RequestBody Map map) {
List<Map> data = (List) map.get("data");
System.out.println(data.size());
Song song = new Song();
Set<Article> set = new HashSet<Article>();
int temp = 0;
int num = 0;
for (Map dataMap : data) {
Article article = new Article();
article.setVolid(dataMap.get("id") + "");
article.setTitle(dataMap.get("title") + "");
String avatar = "0000" + dataMap.get("id");
String substring = avatar.substring(avatar.length() - 5);
System.out.println(substring);
article.setImage(substring + "/00.jpg");
if (temp == (int) dataMap.get("id")) {
num = num + 1;
} else {
num = 0;
}
temp = (int) dataMap.get("id");
String numstr = "0000" + (num + 1);
System.out.println(numstr.substring(numstr.length() - 2));
song.setAlbum(dataMap.get("album") + "");
song.setArtist(dataMap.get("artist") + "");
song.setName(dataMap.get("name") + "");
song.setVolid(dataMap.get("id") + "");
song.setUrl(substring + "/" + numstr.substring(numstr.length() - 2) + ".mp3");
song.setSongno(num + 1);
songService.add(song);
set.add(article);
}
System.out.println(set.size());
for (Article pojo : set) {
// articleService.add(pojo);
}
return Result.success();
}
/**
*
/*
* @PostMapping("/search/{page}/{size}") public Result<PageResult<Song>>
* findSearch(@RequestBody Map searchMap, @PathVariable int page,
*
* @param searchMap
* @return
*/
@PostMapping("/search")
public Result<List<Song>> findSearch(@RequestBody Map searchMap) {
return Result.success(songService.findSearch(searchMap));
}
/**
*
* @PathVariable int size) { Page<Song> pageList =
* songService.findSearch(searchMap, page, size); return Result.success(new
* PageResult<Song>(pageList.getTotalElements(), pageList.getContent())); }
*
* @param song
*/
@PostMapping
public Result<Void> add(@RequestBody Song song) {
songService.add(song);
return Result.success();
}
/**
*
* @PostMapping("/init") public Result<Void> init(@RequestBody Map map) {
* List<Map> data = (List) map.get("data"); System.out.println(data.size());
* Song song = new Song(); Set<Article> set = new HashSet<Article>();
*
* @param song
*/
@PutMapping("/{id}")
public Result<Void> update(@RequestBody Song song, @PathVariable String id) {
song.setId(id);
songService.update(song);
return Result.success();
}
/**
*
* int temp = 0; int num = 0; for (Map dataMap : data) { Article article = new
* Article(); article.setVolid(dataMap.get("id") + "");
* article.setTitle(dataMap.get("title") + ""); String avatar = "0000" +
* dataMap.get("id"); String substring = avatar.substring(avatar.length() - 5);
* System.out.println(substring); article.setImage(substring + "/00.jpg"); if
* (temp == (int) dataMap.get("id")) { num = num + 1; } else { num = 0; } temp =
* (int) dataMap.get("id"); String numstr = "0000" + (num + 1);
* System.out.println(numstr.substring(numstr.length() - 2));
*
* @param id
*/
@DeleteMapping("/{id}")
public Result<Void> delete(@PathVariable String id) {
songService.deleteById(id);
return Result.success();
}
* song.setAlbum(dataMap.get("album") + "");
* song.setArtist(dataMap.get("artist") + ""); song.setName(dataMap.get("name")
* + ""); song.setVolid(dataMap.get("id") + ""); song.setUrl(substring + "/" +
* numstr.substring(numstr.length() - 2) + ".mp3"); song.setSongno(num + 1);
*
* songService.add(song); set.add(article); } System.out.println(set.size());
*
* for (Article pojo : set) { // articleService.add(pojo); } return
* Result.success(); }
*
*//**
*
*
* @param searchMap
* @return
*/
/*
* @PostMapping("/search") public Result<List<Song>> findSearch(@RequestBody Map
* searchMap) { return Result.success(songService.findSearch(searchMap)); }
*
*//**
*
*
* @param song
*/
/*
* @PostMapping public Result<Void> add(@RequestBody Song song) {
* songService.add(song); return Result.success(); }
*
*//**
*
*
* @param song
*/
/*
* @PutMapping("/{id}") public Result<Void> update(@RequestBody Song
* song, @PathVariable String id) { song.setId(id); songService.update(song);
* return Result.success(); }
*
*//**
*
*
* @param id
*//*
* @DeleteMapping("/{id}") public Result<Void> delete(@PathVariable String id) {
* songService.deleteById(id); return Result.success(); }
*/
}

@ -53,12 +53,6 @@ public class OperationAspect {
if (null == interceptor) {
return;
}
/**
*
*/
if (interceptor.checkLogin()) {
checkLogin();
}
/**
*
@ -121,18 +115,11 @@ public class OperationAspect {
}
}
private void checkLogin() {
UserLoginDto userLoginDto = getUserLoginDtoFromToken();
if (userLoginDto == null) {
throw new BizException(StatusCode.UNAUTHORIZED);
}
}
private UserLoginDto getUserLoginDtoFromToken() {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
.getRequest();
String token = request.getHeader("token");
return jwtUtil.getUserLoginDto(token);
String authorization = request.getHeader("Authorization");
return jwtUtil.getUserLoginDto(authorization);
}
private void validateParams(Method method, Object[] arguments) {

@ -22,7 +22,7 @@ public class IndexController {
private CarouselService carouselService;
@ApiOperation(value = "1.获取轮播图", notes = "返回5个")
@GetMapping("/loadCarousel")
@GetMapping("/carousel")
public Result<List<Carousel>> loadCarousel() {
List<Carousel> carouselList = carouselService.loadCarousel();
return Result.success(carouselList);

@ -100,7 +100,7 @@ public class LoginController extends BaseController {
return Result.success();
}
@ApiOperation(value = "2.登录/注册", notes = "成功后返回token")
@ApiOperation(value = "2.登录/注册", notes = "成功后返回authorization")
@ApiImplicitParams({ @ApiImplicitParam(name = "mobile", value = "手机号", required = true),
@ApiImplicitParam(name = "mobileCheckCode", value = "6位验证码", required = true),
@ApiImplicitParam(name = "deviceId", value = "设备id", required = true),
@ -134,7 +134,7 @@ public class LoginController extends BaseController {
}
/**
* token
* authorization
*/
@ApiOperation(value = "3.token续期", notes = "有效期7天")
@ApiImplicitParams({ @ApiImplicitParam(name = "deviceId", value = "设备id", required = true),
@ -142,10 +142,10 @@ public class LoginController extends BaseController {
@PostMapping("/autoLogin")
@GlobalInterceptor
public Result<String> autoLogin(HttpServletRequest request,
@RequestHeader(value = "token", required = false) String token,
@RequestHeader(value = "Authorization", required = false) String authorization,
@VerifyParam(required = true) @RequestParam("deviceId") String deviceId,
@RequestParam("deviceBrand") String deviceBrand) {
return Result.success(userInfoService.autoLogin(token, deviceId, deviceBrand, getIpAddr(request)));
return Result.success(userInfoService.autoLogin(authorization, deviceId, deviceBrand, getIpAddr(request)));
}
/**

@ -24,6 +24,7 @@ import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
@ -74,10 +75,10 @@ public class MyController extends BaseController {
public static String UPLOAD_DIRECTORY = "user/avatar/";
@ApiOperation(value = "1.获取个人信息", notes = "游客无法获取个人信息")
@GetMapping("/getUserInfo")
@GetMapping("/userInfo")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<UserRespDTO> getUserInfo(@RequestHeader(value = "token", required = false) String token) {
UserLoginDto userLoginDto = getUserLoginDto(token);
public Result<UserRespDTO> getUserInfo(@RequestHeader(value = "Authorization", required = false) String authorization) {
UserLoginDto userLoginDto = getUserLoginDto(authorization);
if (null == userLoginDto) {
return Result.unauthorized(null);
}
@ -118,11 +119,11 @@ public class MyController extends BaseController {
}
@ApiOperation(value = "2.更新个人信息", notes = "游客无法编辑个人信息")
@PostMapping("/updateUserInfo")
@PutMapping("/userInfo")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<Void> updateUserInfo(@RequestHeader(value = "token", required = false) String token,
public Result<Void> updateUserInfo(@RequestHeader(value = "Authorization", required = false) String authorization,
@VerifyParam(required = true) @RequestBody UserInfoUpdateDto userInfoUpdateDto) {
UserLoginDto userLoginDto = getUserLoginDto(token);
UserLoginDto userLoginDto = getUserLoginDto(authorization);
UserInfo user = userInfoService.findById(userLoginDto.getUserId());
String nickName = userInfoUpdateDto.getNickName();
if (!StringTools.isEmpty(nickName) && !nickName.equals(user.getNickName())) {
@ -151,11 +152,11 @@ public class MyController extends BaseController {
}
@ApiOperation(value = "3.上传个人头像", notes = "图片压缩为70X70 JPEG存入S3桶为indie目录为 user/avatar/")
@PostMapping("/uploadAvatar")
@GlobalInterceptor(checkLogin = true)
public Result<String> uploadAvatar(@RequestHeader(value = "token", required = false) String token,
@PostMapping("/avatar")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<String> uploadAvatar(@RequestHeader(value = "Authorization", required = false) String authorization,
@VerifyParam(required = true) MultipartFile file) throws IOException {
UserLoginDto userLoginDto = getUserLoginDto(token);
UserLoginDto userLoginDto = getUserLoginDto(authorization);
byte[] thumbnail = ScaleFilter.createThumbnail(file.getInputStream(), Constants.LENGTH_70, Constants.LENGTH_70);
String avatarName = userLoginDto.getUserId() + "_" + idWorker.nextId()
@ -171,9 +172,10 @@ public class MyController extends BaseController {
}
@ApiOperation(value = "4.查看他人信息", notes = "游客无法查看他人信息")
@GetMapping("/getOtherUserInfo/{userId}")
@GetMapping("/otherUserInfo/{userId}")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<UserRespDTO> getOtherUserInfo(@VerifyParam(required = true) @PathVariable String userId) {
public Result<UserRespDTO> getOtherUserInfo(@RequestHeader(value = "Authorization", required = false) String authorization,
@VerifyParam(required = true) @PathVariable String userId) {
UserInfo user = userInfoService.findById(userId);
if (null == user) {
return Result.failed(StatusCode.USER_INVALID_USER_ID);

@ -15,7 +15,7 @@ import util.JwtUtil;
@Api(tags = "UserCollectController")
@RestController
@RequestMapping("/userCollect")
@RequestMapping("/collect")
public class UserCollectController {
@Autowired
private JwtUtil jwtUtil;
@ -29,12 +29,12 @@ public class UserCollectController {
//@ApiImplicitParam(name = "collectType", value = "0:歌曲1:期刊2:关注3:黑名单4:点赞", required = true) })
@ApiImplicitParam(name = "objectId", value = "喜欢歌曲/收藏期刊的id", required = true),
@ApiImplicitParam(name = "collectType", value = "0:歌曲1:期刊", required = true) })
@PostMapping("/addCollect")
@GlobalInterceptor(checkLogin = true)
public Result<Void> addCollect(@RequestHeader(value = "token", required = false) String token,
@PostMapping
@GlobalInterceptor(checkAppUserLogin = true)
public Result<Void> addCollect(@RequestHeader(value = "Authorization", required = false) String authorization,
@VerifyParam(required = true) @RequestParam("objectId") String objectId,
@VerifyParam(required = true) @RequestParam("collectType") Integer collectType) {
UserLoginDto loginDto = jwtUtil.getUserLoginDto(token);
UserLoginDto loginDto = jwtUtil.getUserLoginDto(authorization);
userCollectService.saveCollect(loginDto.getUserId(), objectId, collectType);
return Result.success();
}
@ -46,12 +46,12 @@ public class UserCollectController {
//@ApiImplicitParam(name = "collectType", value = "0:歌曲1:期刊2:关注3:黑名单4:点赞", required = true) })
@ApiImplicitParam(name = "objectId", value = "喜欢歌曲/收藏期刊的id", required = true),
@ApiImplicitParam(name = "collectType", value = "0:歌曲1:期刊", required = true) })
@DeleteMapping("/cancelCollect")
@GlobalInterceptor(checkLogin = true)
public Result<Void> cancelCollect(@RequestHeader(value = "token", required = false) String token,
@DeleteMapping
@GlobalInterceptor(checkAppUserLogin = true)
public Result<Void> cancelCollect(@RequestHeader(value = "Authorization", required = false) String authorization,
@VerifyParam(required = true) @RequestParam("objectId") String objectId,
@VerifyParam(required = true) @RequestParam("collectType") Integer collectType) {
UserLoginDto loginDto = jwtUtil.getUserLoginDto(token);
UserLoginDto loginDto = jwtUtil.getUserLoginDto(authorization);
userCollectService.deleteByUserIdAndObjectIdAndCollectType(loginDto.getUserId(), objectId,
collectType);
return Result.success();

@ -31,11 +31,9 @@ public class UserRespDTO {
@ApiModelProperty(value = "喜欢歌曲数")
private int songCount;
private Set songSet;
@ApiModelProperty(value = "收藏期刊数")
private int journalCount;
private Set journalSet;
@ApiModelProperty(value = "获得评论数")
private int commentReplyCount;
@ApiModelProperty(value = "生日,格式为: yyyy.MM.dd")

@ -266,8 +266,8 @@ public class UserInfoService {
return userInfo;
}
public String autoLogin(String token, String deviceId, String deviceBrand, String ip) {
UserLoginDto userLoginDto=jwtUtil.getUserLoginDto(token);
public String autoLogin(String authorization, String deviceId, String deviceBrand, String ip) {
UserLoginDto userLoginDto=jwtUtil.getUserLoginDto(authorization);
if (null==userLoginDto) {
return null;
}
@ -280,7 +280,7 @@ public class UserInfoService {
userInfo.setLastUseDeviceId(deviceId);
userInfo.setLastUseDeviceBrand(deviceBrand);
userInfoDao.save(userInfo);
return jwtUtil.createJWT(userLoginDto.getUserId(), userInfo.getNickName(), userLoginDto.getRoles());
return Constants.TOKEN_PREFIX+jwtUtil.createJWT(userLoginDto.getUserId(), userInfo.getNickName(), userLoginDto.getRoles());
}
public long countByNickName(String nickName) {
@ -304,7 +304,7 @@ public class UserInfoService {
}
user.setLastLoginTime(new Date());
userInfoDao.save(user);
return jwtUtil.createJWT(user.getId(),user.getNickName(),Constants.TOKEN_ROLE_APP_USER);
return Constants.TOKEN_PREFIX+jwtUtil.createJWT(user.getId(),user.getNickName(),Constants.TOKEN_ROLE_APP_USER);
}
public List<UserInfo> orderByField(List<String> idList) {

Loading…
Cancel
Save