|
|
|
@ -0,0 +1,81 @@
|
|
|
|
|
package mashibing.online.text.controller;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import com.mashibing.dto.ResponseResult;
|
|
|
|
|
import com.mashibing.dto.TokenResult;
|
|
|
|
|
import com.mashibing.util.JwtUtils;
|
|
|
|
|
import com.mashibing.util.RediesPreKeyUtil;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import mashibing.online.text.consonant.PassengerConsonant;
|
|
|
|
|
import mashibing.online.text.dto.TokenQequstVo;
|
|
|
|
|
import mashibing.online.text.dto.UserInfo;
|
|
|
|
|
import mashibing.online.text.utils.BussizParaTokenUtil;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Copyright© 2020.10.20 by 博纳德集团有限公司.All rights reserved.
|
|
|
|
|
* 1.版权归博纳德集团公司所有;
|
|
|
|
|
* 2.未经原作者允许不得转载本代码内容,否则将视为侵权;
|
|
|
|
|
* 3.对于不遵守此声明或者其他违法使用本代码内容者,本公司依法保留追究权。.
|
|
|
|
|
* <b>Description:</b><br>
|
|
|
|
|
*
|
|
|
|
|
* @author nod
|
|
|
|
|
* <b>ProjectName:</b> onelinetextplublic
|
|
|
|
|
* <br><b>PackageName:</b> mashibing.online.text.controller
|
|
|
|
|
* <br><b>ClassName:</b>
|
|
|
|
|
* <br><b>Date:</b> 2022/10/20 15:36
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@RestController
|
|
|
|
|
public class TokenController {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private StringRedisTemplate stringRedisTemplate;
|
|
|
|
|
|
|
|
|
|
@PostMapping("/parsetReshToken")
|
|
|
|
|
public ResponseResult parsetReshToken(@RequestBody TokenQequstVo tokenQequstVo){
|
|
|
|
|
if(ObjectUtil.isNull(tokenQequstVo) || ObjectUtil.isEmpty(tokenQequstVo.getReshToken())){
|
|
|
|
|
return ResponseResult.fail(1002,"reshToken 不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TokenResult tokenResult = BussizParaTokenUtil.pareToken(tokenQequstVo.getReshToken());
|
|
|
|
|
if(ObjectUtil.isNull(tokenResult)){
|
|
|
|
|
log.error("解析 reshToken 异常");
|
|
|
|
|
return ResponseResult.fail(1003,"解析 reshToken 异常");
|
|
|
|
|
}
|
|
|
|
|
String tokenType=tokenResult.getTokenType();
|
|
|
|
|
String phoneNum = tokenResult.getPhoneNum();
|
|
|
|
|
String idendity = tokenResult.getIdendity();
|
|
|
|
|
String reshTokenRedisKey= RediesPreKeyUtil.generateKeyPre(tokenType,phoneNum,idendity);
|
|
|
|
|
String redisToken = stringRedisTemplate.opsForValue().get(reshTokenRedisKey);
|
|
|
|
|
log.info("reshTokenKey ={},refshToken={}",reshTokenRedisKey,redisToken);
|
|
|
|
|
if(StringUtils.isBlank(redisToken) || !tokenQequstVo.getReshToken().equals(redisToken)){
|
|
|
|
|
return ResponseResult.fail(1005,"reshToken 无效");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.info("解析 reshToken 成功!");
|
|
|
|
|
String accessToken = JwtUtils.genaroteToken(phoneNum, PassengerConsonant.PassengerIdendity,PassengerConsonant.ACCESS_TOKEN_TYPE);
|
|
|
|
|
String refshToken = JwtUtils.genaroteToken(phoneNum, PassengerConsonant.PassengerIdendity,PassengerConsonant.REFLSH_TOKEN_TYPE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UserInfo userInfo =new UserInfo();
|
|
|
|
|
userInfo.setPhoneNumber(phoneNum);
|
|
|
|
|
userInfo.setAccessToken(accessToken);
|
|
|
|
|
userInfo.setRefshToken(refshToken);
|
|
|
|
|
String accessTokenKey= RediesPreKeyUtil.generateKeyPre(PassengerConsonant.ACCESS_TOKEN_TYPE,phoneNum,PassengerConsonant.PassengerIdendity);
|
|
|
|
|
stringRedisTemplate.opsForValue().set(accessTokenKey,
|
|
|
|
|
accessToken,15, TimeUnit.SECONDS);
|
|
|
|
|
|
|
|
|
|
stringRedisTemplate.opsForValue().set(reshTokenRedisKey,
|
|
|
|
|
refshToken,55,TimeUnit.SECONDS);
|
|
|
|
|
|
|
|
|
|
return ResponseResult.success(userInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|