瀏覽代碼

扫码登陆

zouxuan 1 年之前
父節點
當前提交
b4dcd68288

+ 16 - 3
mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/service/impl/CbsQrCodeScanServiceImpl.java

@@ -4,18 +4,19 @@ import com.dayaedu.cbs.openfeign.service.CbsQrCodeScanService;
 import com.dayaedu.cbs.openfeign.wrapper.qrcode.CbsQrCodeScanWrapper;
 import com.dayaedu.cbs.openfeign.wrapper.qrcode.CbsQrCodeScanWrapper;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.client.SysUserFeignService;
+import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.auth.core.service.CustomTokenServices;
 import com.ym.mec.auth.core.service.CustomTokenServices;
+import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.exception.BizException;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.HttpStatus;
 import org.springframework.security.oauth2.common.OAuth2AccessToken;
 import org.springframework.security.oauth2.common.OAuth2AccessToken;
 import org.springframework.security.oauth2.provider.OAuth2Authentication;
 import org.springframework.security.oauth2.provider.OAuth2Authentication;
-import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices;
 import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;
 import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
 import java.util.HashMap;
 import java.util.HashMap;
+import java.util.Map;
 
 
 @Service
 @Service
 public class CbsQrCodeScanServiceImpl implements CbsQrCodeScanService {
 public class CbsQrCodeScanServiceImpl implements CbsQrCodeScanService {
@@ -41,7 +42,19 @@ public class CbsQrCodeScanServiceImpl implements CbsQrCodeScanService {
         OAuth2AccessToken oAuth2AccessToken = redisTokenStore.readAccessToken(req.getPassword());
         OAuth2AccessToken oAuth2AccessToken = redisTokenStore.readAccessToken(req.getPassword());
         if (oAuth2AccessToken != null) {
         if (oAuth2AccessToken != null) {
             OAuth2Authentication authentication = redisTokenStore.readAuthentication(req.getPassword());
             OAuth2Authentication authentication = redisTokenStore.readAuthentication(req.getPassword());
-            HashMap<String,String> hashMap = objectMapper.convertValue(authentication.getDetails(), HashMap.class);
+            Map<String,String> hashMap = objectMapper.convertValue(authentication.getPrincipal(), HashMap.class);
+            String userId = hashMap.get("userId");
+            SysUser sysUser = sysUserFeignService.queryUserById(Integer.parseInt(userId));
+            if (sysUser == null) {
+                throw new BizException(HttpStatus.UNAUTHORIZED.value(), "用户不存在");
+            }
+            HttpResponseResult<Map<String, Object>> result = sysUserFeignService.usernameLogin(sysUser.getPhone(), sysUser.getPassword(), req.getClientId(), req.getClientSecret());
+            if (result.getCode() != 200) {
+                throw new BizException(result.getCode(), result.getMsg());
+            }
+            CbsQrCodeScanWrapper.QrCodeScanToken qrCodeScanToken = new CbsQrCodeScanWrapper.QrCodeScanToken();
+            qrCodeScanToken.setTokenData(result.getData().get("access_token"));
+            return qrCodeScanToken;
         }
         }
         return null;
         return null;
     }
     }