36 changed files with 1724 additions and 242 deletions
@ -0,0 +1,57 @@ |
|||
package com.bnyer.img.api.model; |
|||
|
|||
import com.bnyer.common.core.vo.CreatorLoginVo; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @author chengkun |
|||
* @date 2022/5/30 16:25 |
|||
*/ |
|||
|
|||
/** |
|||
* 艺术家信息 |
|||
*/ |
|||
@Data |
|||
public class LoginCreator implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** |
|||
* 艺术家唯一标识 |
|||
*/ |
|||
private String token; |
|||
|
|||
/** |
|||
* 主键id |
|||
*/ |
|||
private Long creatorId; |
|||
|
|||
/** |
|||
* 艺术家手机号 |
|||
*/ |
|||
private String creatorPhone; |
|||
|
|||
/** |
|||
* 登录时间 |
|||
*/ |
|||
private Long loginTime; |
|||
|
|||
/** |
|||
* 过期时间 |
|||
*/ |
|||
private Long expireTime; |
|||
|
|||
/** |
|||
* 登录IP地址 |
|||
*/ |
|||
private String ipaddr; |
|||
|
|||
/** |
|||
* 艺术家信息 |
|||
*/ |
|||
private CreatorLoginVo creator; |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,60 @@ |
|||
package com.bnyer.img.api.model; |
|||
|
|||
import com.bnyer.common.core.vo.FhUserLoginVo; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @author chengkun |
|||
* @date 2022/5/30 16:25 |
|||
*/ |
|||
|
|||
/** |
|||
* 快手小程序用户信息 |
|||
*/ |
|||
@Data |
|||
public class LoginFhUser implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** |
|||
* 快手小程序用户唯一标识 |
|||
*/ |
|||
private String token; |
|||
|
|||
/** |
|||
* 主键id |
|||
*/ |
|||
private Long fhUserId; |
|||
|
|||
/** |
|||
* 快手小程序用户开放Id |
|||
*/ |
|||
private String fhUserOpenId; |
|||
|
|||
/** |
|||
* 快手小程序用户昵称 |
|||
*/ |
|||
private String fhUserName; |
|||
|
|||
/** |
|||
* 登录时间 |
|||
*/ |
|||
private Long loginTime; |
|||
|
|||
/** |
|||
* 过期时间 |
|||
*/ |
|||
private Long expireTime; |
|||
|
|||
/** |
|||
* 登录IP地址 |
|||
*/ |
|||
private String ipaddr; |
|||
|
|||
/** |
|||
* 快手小程序用户信息 |
|||
*/ |
|||
private FhUserLoginVo fhUser; |
|||
} |
|||
@ -0,0 +1,60 @@ |
|||
package com.bnyer.img.api.model; |
|||
|
|||
import com.bnyer.common.core.vo.TiktokUserLoginVo; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @author chengkun |
|||
* @date 2022/5/30 16:25 |
|||
*/ |
|||
|
|||
/** |
|||
* 抖音小程序用户信息 |
|||
*/ |
|||
@Data |
|||
public class LoginTiktokUser implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** |
|||
* 抖音小程序用户唯一标识 |
|||
*/ |
|||
private String token; |
|||
|
|||
/** |
|||
* 主键id |
|||
*/ |
|||
private Long tiktokUserId; |
|||
|
|||
/** |
|||
* 抖音小程序用户开放Id |
|||
*/ |
|||
private String tiktokUserOpenId; |
|||
|
|||
/** |
|||
* 抖音小程序用户昵称 |
|||
*/ |
|||
private String tiktokUserName; |
|||
|
|||
/** |
|||
* 登录时间 |
|||
*/ |
|||
private Long loginTime; |
|||
|
|||
/** |
|||
* 过期时间 |
|||
*/ |
|||
private Long expireTime; |
|||
|
|||
/** |
|||
* 登录IP地址 |
|||
*/ |
|||
private String ipaddr; |
|||
|
|||
/** |
|||
* 抖音小程序用户信息 |
|||
*/ |
|||
private TiktokUserLoginVo tiktokUser; |
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
package com.bnyer.auth.controller; |
|||
|
|||
import com.bnyer.auth.service.CreatorLoginService; |
|||
import com.bnyer.common.core.domain.R; |
|||
import com.bnyer.common.core.dto.CreatorLoginDto; |
|||
import com.bnyer.common.security.service.CreatorTokenService; |
|||
import com.bnyer.common.security.utils.SecurityUtils; |
|||
import com.bnyer.img.api.model.LoginCreator; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import io.swagger.annotations.ApiParam; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.validation.annotation.Validated; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
|
|||
/** |
|||
* 艺术家token 控制 |
|||
* |
|||
* @author penny |
|||
*/ |
|||
@RestController |
|||
public class CreatorController |
|||
{ |
|||
@Autowired |
|||
private CreatorTokenService creatorTokenService; |
|||
|
|||
@Autowired |
|||
private CreatorLoginService creatorService; |
|||
|
|||
|
|||
@PostMapping("/creatorLogin") |
|||
@ApiOperation("小程序艺术家登录") |
|||
public R<?> login(@Validated @ApiParam("艺术家数据") @RequestBody CreatorLoginDto param) |
|||
{ |
|||
// 用户登录
|
|||
LoginCreator login = creatorService.login(param); |
|||
// 获取登录token
|
|||
return R.ok(creatorTokenService.createToken(login)); |
|||
} |
|||
|
|||
@PostMapping("/creatorLogout") |
|||
public R<?> logout(HttpServletRequest request) |
|||
{ |
|||
String token = SecurityUtils.getToken(request); |
|||
creatorTokenService.delLoginCreator(token); |
|||
return R.ok(); |
|||
} |
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
package com.bnyer.auth.controller; |
|||
|
|||
import com.bnyer.auth.service.FhUserLoginService; |
|||
import com.bnyer.common.core.domain.R; |
|||
import com.bnyer.common.core.dto.FhLoginDto; |
|||
import com.bnyer.common.security.service.FhUserTokenService; |
|||
import com.bnyer.common.security.utils.SecurityUtils; |
|||
import com.bnyer.img.api.model.LoginFhUser; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import io.swagger.annotations.ApiParam; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.validation.annotation.Validated; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
|
|||
/** |
|||
* 快手小程序token 控制 |
|||
* |
|||
* @author penny |
|||
*/ |
|||
@RestController |
|||
public class FhUserController |
|||
{ |
|||
@Autowired |
|||
private FhUserLoginService fhUserLoginService; |
|||
|
|||
@Autowired |
|||
private FhUserTokenService fUserTokenService; |
|||
|
|||
@ApiOperation(value="快手小程序用户登录") |
|||
@PostMapping(value = "/fhUserLogin") |
|||
public R<?> loginFh(@Validated @RequestBody @ApiParam("登录对象") FhLoginDto dto){ |
|||
LoginFhUser loginFhUser = fhUserLoginService.login(dto); |
|||
return R.ok(fUserTokenService.createToken(loginFhUser)); |
|||
} |
|||
|
|||
@PostMapping("/fhUserLogout") |
|||
@ApiOperation("快手小程序用户注销") |
|||
public R<?> logout(HttpServletRequest request) |
|||
{ |
|||
String token = SecurityUtils.getToken(request); |
|||
//删除快手用户缓存
|
|||
fUserTokenService.delLoginFhUser(token); |
|||
return R.ok(); |
|||
} |
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
package com.bnyer.auth.controller; |
|||
|
|||
import com.bnyer.auth.service.TiktokUserLoginService; |
|||
import com.bnyer.common.core.domain.R; |
|||
import com.bnyer.common.core.dto.TiktokLoginDto; |
|||
import com.bnyer.common.security.service.TiktokUserTokenService; |
|||
import com.bnyer.common.security.utils.SecurityUtils; |
|||
import com.bnyer.img.api.model.LoginTiktokUser; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import io.swagger.annotations.ApiParam; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.validation.annotation.Validated; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
|
|||
/** |
|||
* 抖音小程序token 控制 |
|||
* |
|||
* @author penny |
|||
*/ |
|||
@RestController |
|||
public class TiktokUserController |
|||
{ |
|||
@Autowired |
|||
private TiktokUserLoginService tiktokUserLoginService; |
|||
|
|||
@Autowired |
|||
private TiktokUserTokenService tiktokUserTokenService; |
|||
|
|||
@ApiOperation(value="抖音小程序用户登录") |
|||
@PostMapping(value = "/tiktokUserLogin") |
|||
public R<?> loginFh(@Validated @RequestBody @ApiParam("登录对象") TiktokLoginDto dto){ |
|||
LoginTiktokUser loginTiktokUser = tiktokUserLoginService.login(dto); |
|||
return R.ok(tiktokUserTokenService.createToken(loginTiktokUser)); |
|||
} |
|||
|
|||
@PostMapping("/tiktokUserLogout") |
|||
@ApiOperation("抖音小程序用户注销") |
|||
public R<?> logout(HttpServletRequest request) |
|||
{ |
|||
String token = SecurityUtils.getToken(request); |
|||
//删除快手用户缓存
|
|||
tiktokUserTokenService.delLoginFhUser(token); |
|||
return R.ok(); |
|||
} |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
package com.bnyer.auth.service; |
|||
|
|||
import com.bnyer.common.core.constant.TiktokConstant; |
|||
import com.bnyer.common.core.domain.R; |
|||
import com.bnyer.common.core.dto.CreatorLoginDto; |
|||
import com.bnyer.common.core.exception.ServiceException; |
|||
import com.bnyer.img.api.RemoteImgService; |
|||
import com.bnyer.img.api.model.LoginCreator; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
/** |
|||
* 艺术家端登录校验方法 |
|||
* |
|||
* @author penny |
|||
*/ |
|||
@Component |
|||
public class CreatorLoginService { |
|||
|
|||
@Autowired |
|||
private RemoteImgService remoteImgService; |
|||
|
|||
public LoginCreator login(CreatorLoginDto dto) { |
|||
R<LoginCreator> creatorInfo = remoteImgService.getCreatorInfo(dto); |
|||
if(creatorInfo.getData() == null){ |
|||
throw new ServiceException("手机号或密码不正确!", TiktokConstant.TIKTOK_CREATOR_PWD_ERROR); |
|||
} |
|||
if(creatorInfo.getData().getCreator().getStatus().equals("0")){ |
|||
throw new ServiceException("当前艺术家暂未审核,请耐心等待或联系客服!",TiktokConstant.TIKTOK_CREATOR_NOT_PASS_ERROR); |
|||
} |
|||
if(creatorInfo.getData().getCreator().getStatus().equals("2")){ |
|||
throw new ServiceException("当前艺术家被封禁,请联系客服处理!",TiktokConstant.TIKTOK_CREATOR_BANED_ERROR); |
|||
} |
|||
return creatorInfo.getData(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
package com.bnyer.auth.service; |
|||
|
|||
import com.bnyer.common.core.dto.FhLoginDto; |
|||
import com.bnyer.img.api.RemoteImgService; |
|||
import com.bnyer.img.api.model.LoginFhUser; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
/** |
|||
* 快手小程序端用户登录校验方法 |
|||
* |
|||
* @author penny |
|||
*/ |
|||
@Component |
|||
public class FhUserLoginService { |
|||
|
|||
@Autowired |
|||
private RemoteImgService remoteImgService; |
|||
|
|||
public LoginFhUser login(FhLoginDto dto) { |
|||
return remoteImgService.getFhLoginUserByLoginParam(dto).getData(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
package com.bnyer.auth.service; |
|||
|
|||
import com.bnyer.common.core.dto.TiktokLoginDto; |
|||
import com.bnyer.img.api.RemoteImgService; |
|||
import com.bnyer.img.api.model.LoginTiktokUser; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
/** |
|||
* 抖音小程序端用户登录校验方法 |
|||
* |
|||
* @author penny |
|||
*/ |
|||
@Component |
|||
public class TiktokUserLoginService { |
|||
|
|||
@Autowired |
|||
private RemoteImgService remoteImgService; |
|||
|
|||
public LoginTiktokUser login(TiktokLoginDto dto) { |
|||
return remoteImgService.getTiktokLoginUserByLoginParam(dto).getData(); |
|||
} |
|||
|
|||
} |
|||
@ -1,18 +0,0 @@ |
|||
package com.bnyer.common.core.annotation; |
|||
|
|||
import java.lang.annotation.ElementType; |
|||
import java.lang.annotation.Retention; |
|||
import java.lang.annotation.RetentionPolicy; |
|||
import java.lang.annotation.Target; |
|||
|
|||
/** |
|||
* 小程序用户token检测注解 |
|||
* |
|||
* @author chengkun |
|||
*/ |
|||
@Target(ElementType.METHOD) |
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
public @interface TokenCheck |
|||
{ |
|||
|
|||
} |
|||
@ -1,4 +1,4 @@ |
|||
package com.bnyer.img.vo; |
|||
package com.bnyer.common.core.vo; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import io.swagger.annotations.ApiModel; |
|||
@ -0,0 +1,45 @@ |
|||
package com.bnyer.common.core.vo; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
|
|||
|
|||
@Getter |
|||
@Setter |
|||
@ApiModel("快手小程序用户登录响应类") |
|||
public class FhUserLoginVo implements Serializable { |
|||
|
|||
@ApiModelProperty(value="id") |
|||
private Long id; |
|||
|
|||
@ApiModelProperty(value="用户昵称") |
|||
private String username; |
|||
|
|||
@ApiModelProperty(value="快手id") |
|||
private String fhCode; |
|||
|
|||
@ApiModelProperty(value="是否为vip(0->否;1->是)") |
|||
private String isVip; |
|||
|
|||
@ApiModelProperty(value="头像img地址") |
|||
private String img; |
|||
|
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@ApiModelProperty(value="创建时间") |
|||
private Date createTime; |
|||
|
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@ApiModelProperty(value="更新时间") |
|||
private Date updateTime; |
|||
|
|||
@ApiModelProperty(value="排序") |
|||
private Integer sort; |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
package com.bnyer.common.core.vo; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
|
|||
|
|||
@Getter |
|||
@Setter |
|||
@ApiModel("抖音小程序用户登录响应类") |
|||
public class TiktokUserLoginVo implements Serializable { |
|||
|
|||
@ApiModelProperty(value="id") |
|||
private Long id; |
|||
|
|||
@ApiModelProperty(value="用户昵称") |
|||
private String username; |
|||
|
|||
@ApiModelProperty(value="抖音id") |
|||
private String tiktokCode; |
|||
|
|||
@ApiModelProperty(value="是否为vip(0->否;1->是)") |
|||
private String isVip; |
|||
|
|||
@ApiModelProperty(value="头像img地址") |
|||
private String img; |
|||
|
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@ApiModelProperty(value="创建时间") |
|||
private Date createTime; |
|||
|
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@ApiModelProperty(value="更新时间") |
|||
private Date updateTime; |
|||
|
|||
@ApiModelProperty(value="排序") |
|||
private Integer sort; |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
} |
|||
@ -0,0 +1,97 @@ |
|||
package com.bnyer.common.security.service; |
|||
|
|||
import com.bnyer.common.core.constant.CacheConstants; |
|||
import com.bnyer.common.core.constant.RedisKeyConstant; |
|||
import com.bnyer.common.core.constant.SecurityConstants; |
|||
import com.bnyer.common.core.utils.JwtUtils; |
|||
import com.bnyer.common.core.utils.ServletUtils; |
|||
import com.bnyer.common.core.utils.StringUtils; |
|||
import com.bnyer.common.core.utils.ip.IpUtils; |
|||
import com.bnyer.common.core.utils.uuid.IdUtils; |
|||
import com.bnyer.common.redis.service.RedisService; |
|||
import com.bnyer.img.api.model.LoginCreator; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
import java.util.concurrent.TimeUnit; |
|||
|
|||
/** |
|||
* 艺术家端小程序token验证处理 |
|||
* |
|||
* @author penny |
|||
*/ |
|||
@Component |
|||
public class CreatorTokenService |
|||
{ |
|||
@Autowired |
|||
private RedisService redisService; |
|||
|
|||
protected static final long MILLIS_SECOND = 1000; |
|||
|
|||
protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND; |
|||
|
|||
private final static long expireTime = CacheConstants.EXPIRATION; |
|||
|
|||
private final static String ACCESS_TOKEN = RedisKeyConstant.WECHAT_CREATOR_LOGIN_KEY; |
|||
|
|||
/** |
|||
* 创建令牌 |
|||
*/ |
|||
public Map<String, Object> createToken(LoginCreator loginCreator) |
|||
{ |
|||
String token = IdUtils.fastUUID(); |
|||
Long creatorId = loginCreator.getCreator().getId(); |
|||
String creatorPhone = loginCreator.getCreator().getPhone(); |
|||
loginCreator.setToken(token); |
|||
loginCreator.setCreatorId(creatorId); |
|||
loginCreator.setCreatorPhone(creatorPhone); |
|||
loginCreator.setIpaddr(IpUtils.getIpAddr(ServletUtils.getRequest())); |
|||
refreshToken(loginCreator); |
|||
|
|||
// Jwt存储信息
|
|||
Map<String, Object> claimsMap = new HashMap<String, Object>(); |
|||
claimsMap.put(SecurityConstants.CREATOR_KEY, token); |
|||
claimsMap.put(SecurityConstants.DETAILS_CREATOR_ID, creatorId); |
|||
claimsMap.put(SecurityConstants.DETAILS_PHONE, creatorPhone); |
|||
|
|||
// 接口返回信息
|
|||
Map<String, Object> rspMap = new HashMap<String, Object>(); |
|||
rspMap.put("access_token", JwtUtils.createToken(claimsMap)); |
|||
rspMap.put("userInfo",loginCreator.getCreator()); |
|||
rspMap.put("expires_in", expireTime); |
|||
return rspMap; |
|||
} |
|||
|
|||
/** |
|||
* 删除用户缓存信息 |
|||
*/ |
|||
public void delLoginCreator(String token) |
|||
{ |
|||
if (StringUtils.isNotEmpty(token)) |
|||
{ |
|||
String creatorKey = JwtUtils.getCreatorKey(token); |
|||
redisService.deleteObject(getTokenKey(creatorKey)); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 刷新令牌有效期 |
|||
* |
|||
* @param loginCreator 艺术家登录信息 |
|||
*/ |
|||
public void refreshToken(LoginCreator loginCreator) |
|||
{ |
|||
loginCreator.setLoginTime(System.currentTimeMillis()); |
|||
loginCreator.setExpireTime(loginCreator.getLoginTime() + expireTime * MILLIS_MINUTE); |
|||
// 根据uuid将loginCreator缓存
|
|||
String creatorKey = getTokenKey(loginCreator.getToken()); |
|||
redisService.setCacheObject(creatorKey, loginCreator, expireTime, TimeUnit.MINUTES); |
|||
} |
|||
|
|||
private String getTokenKey(String token) |
|||
{ |
|||
return ACCESS_TOKEN + token; |
|||
} |
|||
} |
|||
@ -0,0 +1,100 @@ |
|||
package com.bnyer.common.security.service; |
|||
|
|||
import com.bnyer.common.core.constant.CacheConstants; |
|||
import com.bnyer.common.core.constant.RedisKeyConstant; |
|||
import com.bnyer.common.core.constant.SecurityConstants; |
|||
import com.bnyer.common.core.utils.JwtUtils; |
|||
import com.bnyer.common.core.utils.ServletUtils; |
|||
import com.bnyer.common.core.utils.StringUtils; |
|||
import com.bnyer.common.core.utils.ip.IpUtils; |
|||
import com.bnyer.common.core.utils.uuid.IdUtils; |
|||
import com.bnyer.common.redis.service.RedisService; |
|||
import com.bnyer.img.api.model.LoginFhUser; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
import java.util.concurrent.TimeUnit; |
|||
|
|||
/** |
|||
* 快手端小程序token验证处理 |
|||
* |
|||
* @author penny |
|||
*/ |
|||
@Component |
|||
public class FhUserTokenService |
|||
{ |
|||
@Autowired |
|||
private RedisService redisService; |
|||
|
|||
protected static final long MILLIS_SECOND = 1000; |
|||
|
|||
protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND; |
|||
|
|||
private final static long expireTime = CacheConstants.EXPIRATION; |
|||
|
|||
private final static String ACCESS_TOKEN = RedisKeyConstant.FH_USER_LOGIN_KEY; |
|||
|
|||
/** |
|||
* 创建令牌 |
|||
*/ |
|||
public Map<String, Object> createToken(LoginFhUser loginFhUser) |
|||
{ |
|||
String token = IdUtils.fastUUID(); |
|||
Long fhUserId = loginFhUser.getFhUser().getId(); |
|||
String fhUserName = loginFhUser.getFhUser().getUsername(); |
|||
String openId = loginFhUser.getFhUser().getFhCode(); |
|||
loginFhUser.setToken(token); |
|||
loginFhUser.setFhUserId(fhUserId); |
|||
loginFhUser.setFhUserName(fhUserName); |
|||
loginFhUser.setFhUserOpenId(openId); |
|||
loginFhUser.setIpaddr(IpUtils.getIpAddr(ServletUtils.getRequest())); |
|||
refreshToken(loginFhUser); |
|||
|
|||
// Jwt存储信息
|
|||
Map<String, Object> claimsMap = new HashMap<String, Object>(); |
|||
claimsMap.put(SecurityConstants.FH_USER_KEY, token); |
|||
claimsMap.put(SecurityConstants.DETAILS_FH_USER_ID, fhUserId); |
|||
claimsMap.put(SecurityConstants.DETAILS_FH_USERNAME, fhUserName); |
|||
claimsMap.put(SecurityConstants.DETAILS_FH_OPENID,openId); |
|||
|
|||
// 接口返回信息
|
|||
Map<String, Object> rspMap = new HashMap<String, Object>(); |
|||
rspMap.put("access_token", JwtUtils.createToken(claimsMap)); |
|||
rspMap.put("userInfo",loginFhUser.getFhUser()); |
|||
rspMap.put("expires_in", expireTime); |
|||
return rspMap; |
|||
} |
|||
|
|||
/** |
|||
* 删除快手小程序用户缓存信息 |
|||
*/ |
|||
public void delLoginFhUser(String token) |
|||
{ |
|||
if (StringUtils.isNotEmpty(token)) |
|||
{ |
|||
String fhUserKey = JwtUtils.getFhUserKey(token); |
|||
redisService.deleteObject(getTokenKey(fhUserKey)); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 刷新令牌有效期 |
|||
* |
|||
* @param loginFhUser 快手小程序用户登录信息 |
|||
*/ |
|||
public void refreshToken(LoginFhUser loginFhUser) |
|||
{ |
|||
loginFhUser.setLoginTime(System.currentTimeMillis()); |
|||
loginFhUser.setExpireTime(loginFhUser.getLoginTime() + expireTime * MILLIS_MINUTE); |
|||
// 根据uuid将loginFhUser缓存
|
|||
String fhUserKey = getTokenKey(loginFhUser.getToken()); |
|||
redisService.setCacheObject(fhUserKey, loginFhUser, expireTime, TimeUnit.MINUTES); |
|||
} |
|||
|
|||
private String getTokenKey(String token) |
|||
{ |
|||
return ACCESS_TOKEN + token; |
|||
} |
|||
} |
|||
@ -0,0 +1,100 @@ |
|||
package com.bnyer.common.security.service; |
|||
|
|||
import com.bnyer.common.core.constant.CacheConstants; |
|||
import com.bnyer.common.core.constant.RedisKeyConstant; |
|||
import com.bnyer.common.core.constant.SecurityConstants; |
|||
import com.bnyer.common.core.utils.JwtUtils; |
|||
import com.bnyer.common.core.utils.ServletUtils; |
|||
import com.bnyer.common.core.utils.StringUtils; |
|||
import com.bnyer.common.core.utils.ip.IpUtils; |
|||
import com.bnyer.common.core.utils.uuid.IdUtils; |
|||
import com.bnyer.common.redis.service.RedisService; |
|||
import com.bnyer.img.api.model.LoginTiktokUser; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
import java.util.concurrent.TimeUnit; |
|||
|
|||
/** |
|||
* 抖音端小程序token验证处理 |
|||
* |
|||
* @author penny |
|||
*/ |
|||
@Component |
|||
public class TiktokUserTokenService |
|||
{ |
|||
@Autowired |
|||
private RedisService redisService; |
|||
|
|||
protected static final long MILLIS_SECOND = 1000; |
|||
|
|||
protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND; |
|||
|
|||
private final static long expireTime = CacheConstants.EXPIRATION; |
|||
|
|||
private final static String ACCESS_TOKEN = RedisKeyConstant.TIKTOK_USER_LOGIN_KEY; |
|||
|
|||
/** |
|||
* 创建令牌 |
|||
*/ |
|||
public Map<String, Object> createToken(LoginTiktokUser loginTiktokUser) |
|||
{ |
|||
String token = IdUtils.fastUUID(); |
|||
Long tiktokUserId = loginTiktokUser.getTiktokUser().getId(); |
|||
String tiktokUserName = loginTiktokUser.getTiktokUser().getUsername(); |
|||
String openId = loginTiktokUser.getTiktokUser().getTiktokCode(); |
|||
loginTiktokUser.setToken(token); |
|||
loginTiktokUser.setTiktokUserId(tiktokUserId); |
|||
loginTiktokUser.setTiktokUserName(tiktokUserName); |
|||
loginTiktokUser.setTiktokUserOpenId(openId); |
|||
loginTiktokUser.setIpaddr(IpUtils.getIpAddr(ServletUtils.getRequest())); |
|||
refreshToken(loginTiktokUser); |
|||
|
|||
// Jwt存储信息
|
|||
Map<String, Object> claimsMap = new HashMap<String, Object>(); |
|||
claimsMap.put(SecurityConstants.TIKTOK_USER_KEY, token); |
|||
claimsMap.put(SecurityConstants.DETAILS_TIKTOK_USER_ID, tiktokUserId); |
|||
claimsMap.put(SecurityConstants.DETAILS_TIKTOK_USERNAME, tiktokUserName); |
|||
claimsMap.put(SecurityConstants.DETAILS_TIKTOK_OPENID,openId); |
|||
|
|||
// 接口返回信息
|
|||
Map<String, Object> rspMap = new HashMap<String, Object>(); |
|||
rspMap.put("access_token", JwtUtils.createToken(claimsMap)); |
|||
rspMap.put("userInfo",loginTiktokUser.getTiktokUser()); |
|||
rspMap.put("expires_in", expireTime); |
|||
return rspMap; |
|||
} |
|||
|
|||
/** |
|||
* 删除抖音小程序用户缓存信息 |
|||
*/ |
|||
public void delLoginFhUser(String token) |
|||
{ |
|||
if (StringUtils.isNotEmpty(token)) |
|||
{ |
|||
String tiktokUserKey = JwtUtils.getTiktokUserKey(token); |
|||
redisService.deleteObject(getTokenKey(tiktokUserKey)); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 刷新令牌有效期 |
|||
* |
|||
* @param loginTiktokUser 抖音小程序用户登录信息 |
|||
*/ |
|||
public void refreshToken(LoginTiktokUser loginTiktokUser) |
|||
{ |
|||
loginTiktokUser.setLoginTime(System.currentTimeMillis()); |
|||
loginTiktokUser.setExpireTime(loginTiktokUser.getLoginTime() + expireTime * MILLIS_MINUTE); |
|||
// 根据uuid将loginTiktokUser缓存
|
|||
String tiktokUserKey = getTokenKey(loginTiktokUser.getToken()); |
|||
redisService.setCacheObject(tiktokUserKey, loginTiktokUser, expireTime, TimeUnit.MINUTES); |
|||
} |
|||
|
|||
private String getTokenKey(String token) |
|||
{ |
|||
return ACCESS_TOKEN + token; |
|||
} |
|||
} |
|||
@ -1,6 +1,9 @@ |
|||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ |
|||
com.bnyer.common.security.config.WebMvcConfig,\ |
|||
com.bnyer.common.security.service.TokenService,\ |
|||
com.bnyer.common.security.service.CreatorTokenService,\ |
|||
com.bnyer.common.security.service.FhUserTokenService,\ |
|||
com.bnyer.common.security.service.TiktokUserTokenService,\ |
|||
com.bnyer.common.security.aspect.PreAuthorizeAspect,\ |
|||
com.bnyer.common.security.aspect.InnerAuthAspect,\ |
|||
com.bnyer.common.security.handler.GlobalExceptionHandler |
|||
|
|||
Loading…
Reference in new issue