|
@@ -4,18 +4,19 @@ import com.dayaedu.cbs.openfeign.service.CbsQrCodeScanService;
|
|
|
import com.dayaedu.cbs.openfeign.wrapper.qrcode.CbsQrCodeScanWrapper;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
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.common.entity.HttpResponseResult;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
|
|
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.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Service
|
|
|
public class CbsQrCodeScanServiceImpl implements CbsQrCodeScanService {
|
|
@@ -41,7 +42,19 @@ public class CbsQrCodeScanServiceImpl implements CbsQrCodeScanService {
|
|
|
OAuth2AccessToken oAuth2AccessToken = redisTokenStore.readAccessToken(req.getPassword());
|
|
|
if (oAuth2AccessToken != null) {
|
|
|
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;
|
|
|
}
|