|
|
@ -53,8 +53,6 @@ import com.taobao.dingtalk.vo.result.AccessTokenResult; |
|
|
|
import com.taobao.dingtalk.vo.result.UserBaseInfo; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
@ -73,7 +71,6 @@ import java.util.stream.Collectors; |
|
|
|
@Service |
|
|
|
public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResolver { |
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ThirdLoginServiceImpl.class); |
|
|
|
@Autowired |
|
|
|
private JwtTokenUtils jwtTokenUtils; |
|
|
|
@Autowired |
|
|
@ -99,6 +96,17 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
@Autowired |
|
|
|
private ThirdOpenFeignClient thirdOpenFeignClient; |
|
|
|
|
|
|
|
/** |
|
|
|
* 工作端:gov、居民端:resi、运营端:oper |
|
|
|
*/ |
|
|
|
private static final String APP = "resi"; |
|
|
|
|
|
|
|
private static final String APP_ID = "wx07674c23af51b521"; |
|
|
|
|
|
|
|
private static final String SESSION_KEY = "a2fd0d29b007cbbcf8c8dda8c693d99b"; |
|
|
|
|
|
|
|
private static final String CLIENT = "wxmp"; |
|
|
|
|
|
|
|
/** |
|
|
|
* @param formDTO |
|
|
|
* @return |
|
|
@ -137,6 +145,33 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
return userTokenResultDTO; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public UserTokenResultDTO resiLoginByOpenId(String openId) { |
|
|
|
// 1、确定用户是否注册,如果没有,直接注册
|
|
|
|
WxUserFormDTO wxUser = new WxUserFormDTO(); |
|
|
|
wxUser.setApp(APP); |
|
|
|
UserWechatDTO wechatDTO = new UserWechatDTO(); |
|
|
|
wechatDTO.setWxOpenId(openId); |
|
|
|
wxUser.setWechatDTO(wechatDTO); |
|
|
|
UserDTO userDTO = epmetUserOpenFeignClient.saveWxUser(wxUser).getData(); |
|
|
|
// 2、封装数据
|
|
|
|
wechatDTO.setSessionKey(SESSION_KEY); |
|
|
|
wechatDTO.setUserId(userDTO.getId()); |
|
|
|
wechatDTO.setCustomerId(userDTO.getCustomerId()); |
|
|
|
LoginFormDTO loginDto = new LoginFormDTO(); |
|
|
|
loginDto.setClient(CLIENT); |
|
|
|
loginDto.setApp(APP); |
|
|
|
//3.生成业务token
|
|
|
|
String token = generateToken(loginDto, userDTO.getId()); |
|
|
|
//4.存放Redis
|
|
|
|
saveTokenDto(loginDto, userDTO.getId(), wechatDTO, token, userDTO.getCustomerId()); |
|
|
|
//5.接口返参
|
|
|
|
UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); |
|
|
|
userTokenResultDTO.setToken(token); |
|
|
|
return userTokenResultDTO; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 居民端登陆生成业务token的key |
|
|
|
**/ |
|
|
@ -709,8 +744,8 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 获取客户信息 |
|
|
|
* @param appId |
|
|
|
* @Description 获取客户信息 |
|
|
|
* @author zxc |
|
|
|
*/ |
|
|
|
public PaCustomerDTO getCustomerInfo(String appId) { |
|
|
@ -735,8 +770,8 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 获取UserWechatDTO |
|
|
|
* @param resiLoginFormDTO |
|
|
|
* @Description 获取UserWechatDTO |
|
|
|
* @author zxc |
|
|
|
*/ |
|
|
|
public UserWechatDTO getUserWeChat(WxLoginFormDTO resiLoginFormDTO) { |
|
|
@ -837,8 +872,8 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 发送登录事件 |
|
|
|
* @return |
|
|
|
* @Description 发送登录事件 |
|
|
|
* @author wxz |
|
|
|
* @date 2021.06.08 15:27 |
|
|
|
*/ |
|
|
@ -869,6 +904,7 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
// (2)通过1、2拿到手机号之后,根据mobile+customerId去user_base_info表找userId,
|
|
|
|
// 是否注册居民:register_relation
|
|
|
|
// (3)没有则生成user、user_Base_info表记录
|
|
|
|
|
|
|
|
/** |
|
|
|
* 钉钉应用的登录-居民端 |
|
|
|
* |
|
|
@ -1032,16 +1068,16 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
* 企业内部应用开发,不授权了 |
|
|
|
* https://open.dingtalk.com/document/orgapp-server/enterprise-internal-application-logon-free
|
|
|
|
* 建议用户信息保存在前端缓存中(dd.setStorage)或者cookie中,避免每次进入应用都调用钉钉接口进行免登。 |
|
|
|
* |
|
|
|
* <p> |
|
|
|
* 获取免登授权码。 |
|
|
|
* 小程序免登 |
|
|
|
* 微应用免登 |
|
|
|
* 获取AccessToken。 |
|
|
|
* 调用接口获取access_token,详情请参考获取企业内部应用的access_token。 |
|
|
|
* |
|
|
|
* <p> |
|
|
|
* 获取userid。 |
|
|
|
* 调用接口获取用户的userid,详情请参考通过免登码获取用户信息。 |
|
|
|
* |
|
|
|
* <p> |
|
|
|
* 获取用户详情。 |
|
|
|
* 调用接口获取用户详细信息,详情请参考根据userId获取用户详情。 |
|
|
|
* |
|
|
@ -1116,6 +1152,7 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
|
|
|
|
/** |
|
|
|
* 最原始的企业内部应用开发,不授权给产品服务商 |
|
|
|
* |
|
|
|
* @param miniAppId |
|
|
|
* @param authCode |
|
|
|
* @return |
|
|
@ -1172,6 +1209,7 @@ public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResol |
|
|
|
|
|
|
|
/** |
|
|
|
* 客户写死吧 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private String getCurrentCustomerId() { |
|
|
|