|  | @@ -0,0 +1,67 @@
 | 
	
		
			
				|  |  | +package com.yonge.cooleshow.auth.service.impl;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | +import com.dayaedu.cbs.openfeign.wrapper.qrcode.CbsQrCodeScanWrapper;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.auth.api.entity.SysUser;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.auth.core.service.CustomTokenServices;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.auth.dal.dao.SysConfigDao;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.auth.service.SysUserService;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.common.entity.HttpResponseResult;
 | 
	
		
			
				|  |  | +import com.yonge.toolset.base.exception.BizException;
 | 
	
		
			
				|  |  | +import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | +import org.springframework.http.HttpStatus;
 | 
	
		
			
				|  |  | +import org.springframework.security.oauth2.provider.OAuth2Authentication;
 | 
	
		
			
				|  |  | +import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import javax.annotation.Resource;
 | 
	
		
			
				|  |  | +import java.util.Map;
 | 
	
		
			
				|  |  | +import java.util.UUID;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +@Service
 | 
	
		
			
				|  |  | +public class CbsQrCodeScanServiceImpl {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private CustomTokenServices customTokenServices;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private SysUserService sysUserService;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private SysUserFeignService sysUserFeignService;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private SysConfigDao sysConfigDao;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public CbsQrCodeScanWrapper.UserInfo userInfo(CbsQrCodeScanWrapper.QrCodeScanUserInfoReq req) {
 | 
	
		
			
				|  |  | +        CbsQrCodeScanWrapper.UserInfo userInfo = new CbsQrCodeScanWrapper.UserInfo();
 | 
	
		
			
				|  |  | +        userInfo.setUsername(customTokenServices.loadAuthentication(req.getToken()).getName().split(":")[1]);
 | 
	
		
			
				|  |  | +        userInfo.setClientTypes("TEACHER");
 | 
	
		
			
				|  |  | +        return userInfo;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public CbsQrCodeScanWrapper.QrCodeScanToken login(CbsQrCodeScanWrapper.QrCodeScanReq req) {
 | 
	
		
			
				|  |  | +        //校验是否过期
 | 
	
		
			
				|  |  | +        OAuth2Authentication auth2Authentication = customTokenServices.loadAuthentication(req.getPassword());
 | 
	
		
			
				|  |  | +        String phone = auth2Authentication.getName().split(":")[1];
 | 
	
		
			
				|  |  | +        SysUser sysUser = sysUserService.queryByPhone(phone);
 | 
	
		
			
				|  |  | +        if (sysUser == null) {
 | 
	
		
			
				|  |  | +            throw new BizException(HttpStatus.UNAUTHORIZED.value(), "用户不存在");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //获取需要排除的用户编号
 | 
	
		
			
				|  |  | +        String excludeUserIds = sysConfigDao.findConfigValue("exclude_user_ids");
 | 
	
		
			
				|  |  | +        if(StringUtils.isNotEmpty(excludeUserIds) && excludeUserIds.contains(sysUser.getId().toString())){
 | 
	
		
			
				|  |  | +            throw new BizException("扫码登陆失败: 用户已锁定");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //调用登陆接口
 | 
	
		
			
				|  |  | +        HttpResponseResult<Map<String,Object>> result = sysUserFeignService.smsLogin(phone, UUID.randomUUID().toString(),"SMS", req.getClientId(), req.getClientSecret());
 | 
	
		
			
				|  |  | +        if (result != null){
 | 
	
		
			
				|  |  | +            if(result.getCode() != 200){
 | 
	
		
			
				|  |  | +                throw new BizException("扫码登陆失败", result.getMsg());
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            CbsQrCodeScanWrapper.QrCodeScanToken qrCodeScanToken = new CbsQrCodeScanWrapper.QrCodeScanToken();
 | 
	
		
			
				|  |  | +            JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(result.getData().get("authentication")));
 | 
	
		
			
				|  |  | +            qrCodeScanToken.setTokenData(jsonObject.getString("access_token"));
 | 
	
		
			
				|  |  | +            return qrCodeScanToken;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        throw new BizException("扫码登陆失败", "调用登陆接口失败");
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 |