|
@@ -0,0 +1,80 @@
|
|
|
+package com.fdkankan.ucenter.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fdkankan.common.constant.ErrorCode;
|
|
|
+import com.fdkankan.common.exception.BusinessException;
|
|
|
+import com.fdkankan.common.util.JwtUtil;
|
|
|
+import com.fdkankan.redis.constant.RedisKey;
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
|
+import com.fdkankan.ucenter.common.Result;
|
|
|
+import com.fdkankan.ucenter.entity.ScenePlus;
|
|
|
+import com.fdkankan.ucenter.entity.ScenePro;
|
|
|
+import com.fdkankan.ucenter.entity.User;
|
|
|
+import com.fdkankan.ucenter.service.IInnerService;
|
|
|
+import com.fdkankan.ucenter.service.IScenePlusService;
|
|
|
+import com.fdkankan.ucenter.service.ISceneProService;
|
|
|
+import com.fdkankan.ucenter.service.IUserService;
|
|
|
+import com.fdkankan.web.util.WebUtil;
|
|
|
+import java.util.Objects;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * TODO
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author dengsixing
|
|
|
+ * @since 2022/9/27
|
|
|
+ **/
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class InnerServiceImpl implements IInnerService {
|
|
|
+
|
|
|
+ @Value("${inner.customToken}")
|
|
|
+ private String customToken;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISceneProService sceneProService;
|
|
|
+ @Autowired
|
|
|
+ private IScenePlusService scenePlusService;
|
|
|
+ @Autowired
|
|
|
+ private IUserService userService;
|
|
|
+ @Autowired
|
|
|
+ private RedisUtil redisUtil;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result createTokenByNum(String num, String customToken) {
|
|
|
+
|
|
|
+ log.info(this.customToken);
|
|
|
+ log.info(customToken);
|
|
|
+
|
|
|
+ if(!this.customToken.equals(customToken)){
|
|
|
+ return Result.failure("无权访问");
|
|
|
+ }
|
|
|
+
|
|
|
+ Long userId = null;
|
|
|
+ ScenePro scenePro = sceneProService.getByNum(num);
|
|
|
+ if(Objects.nonNull(scenePro)){
|
|
|
+ userId = scenePro.getUserId();
|
|
|
+ }else{
|
|
|
+ ScenePlus scenePlus = scenePlusService.getByNum(num);
|
|
|
+ if(Objects.isNull(scenePlus)){
|
|
|
+ return Result.failure("场景为空");
|
|
|
+ }
|
|
|
+ userId = scenePlus.getUserId();
|
|
|
+ }
|
|
|
+ User user = userService.getById(userId);
|
|
|
+ String token = JwtUtil.createJWT(-1, user.getUserName(), "user");
|
|
|
+ String redisKey = String.format(RedisKey.TOKEN_V3,token);
|
|
|
+ redisUtil.set(redisKey, JSON.toJSONString(user), RedisKey.EXPIRE_TIME_2_HOUR);
|
|
|
+
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ object.put("token", token);
|
|
|
+
|
|
|
+ return Result.success(object);
|
|
|
+ }
|
|
|
+}
|