|
|
@ -4,11 +4,14 @@ import com.epmet.commons.security.jwt.JwtUtils; |
|
|
|
import com.epmet.commons.tools.redis.RedisKeys; |
|
|
|
import com.epmet.commons.tools.redis.RedisUtils; |
|
|
|
import com.epmet.config.OpenApiConfig; |
|
|
|
import com.epmet.dto.result.openapi.GetAccessTokenResultDTO; |
|
|
|
import com.epmet.openapi.constant.RequestParamKeys; |
|
|
|
import com.epmet.service.OpenApiAccessTokenService; |
|
|
|
import org.joda.time.DateTime; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
@Service |
|
|
@ -24,15 +27,19 @@ public class OpenApiAccessTokenServiceImpl implements OpenApiAccessTokenService |
|
|
|
private RedisUtils redisUtils; |
|
|
|
|
|
|
|
@Override |
|
|
|
public String getAccessToken(String appId, String secret) { |
|
|
|
public GetAccessTokenResultDTO getAccessToken(String appId, String secret) { |
|
|
|
HashMap<String, Object> claim = new HashMap<>(); |
|
|
|
claim.put(RequestParamKeys.APP_ID, appId); |
|
|
|
|
|
|
|
String token = jwtTokenUtils.createToken(claim, openApiConfig.getAccessTokenExpire(), secret); |
|
|
|
|
|
|
|
Date expireTime = DateTime.now().plusSeconds(openApiConfig.getAccessTokenExpire()).toDate(); |
|
|
|
String token = jwtTokenUtils.createToken(claim, expireTime, secret); |
|
|
|
// 缓存token
|
|
|
|
redisUtils.set(RedisKeys.getOpenApiAccessTokenKey(appId), token, openApiConfig.getAccessTokenExpire()); |
|
|
|
|
|
|
|
return token; |
|
|
|
GetAccessTokenResultDTO content = new GetAccessTokenResultDTO(); |
|
|
|
content.setAccessToken(token); |
|
|
|
content.setExpireTime(expireTime.getTime()); |
|
|
|
|
|
|
|
return content; |
|
|
|
} |
|
|
|
} |
|
|
|