use of com.diboot.mobile.dto.MobileCredential in project diboot by dibo-software.
the class WxAuthServiceImpl method initBaseJwtAuthToken.
/**
* 初始化JwtAuthToken实例
* @param credential
* @return
*/
private BaseJwtAuthToken initBaseJwtAuthToken(AuthCredential credential) {
MobileCredential wxMpCredential = (MobileCredential) credential;
BaseJwtAuthToken token = new BaseJwtAuthToken(getAuthType(), wxMpCredential.getUserTypeClass());
// 设置登陆的
token.setAuthAccount(wxMpCredential.getAuthAccount());
token.setRememberMe(wxMpCredential.isRememberMe());
// 生成token
return token.generateAuthtoken(getExpiresInMinutes());
}
use of com.diboot.mobile.dto.MobileCredential in project diboot by dibo-software.
the class WxMpMemberAuthServiceImpl method applyToken.
@Override
@Transactional(rollbackFor = Exception.class)
public String applyToken(String code, String state) throws Exception {
// 校验STATE
if (V.notEmpty(STATE) && !STATE.equals(state)) {
throw new BusinessException(Status.FAIL_INVALID_PARAM, "非法来源");
}
if (V.isEmpty(code)) {
log.error("请求参数有误: code = null");
throw new BusinessException(Status.FAIL_INVALID_PARAM, "请求参数有误: code is null");
}
WxOAuth2AccessToken accessToken = wxMpService.getOAuth2Service().getAccessToken(code);
// 获取用户信息
IamAccount account = iamAccountService.getSingleEntity(Wrappers.<IamAccount>lambdaQuery().eq(IamAccount::getUserType, IamMember.class.getSimpleName()).eq(IamAccount::getAuthAccount, accessToken.getOpenId()).eq(IamAccount::getAuthType, Cons.DICTCODE_AUTH_TYPE.WX_MP.name()));
MobileCredential credential = new MobileCredential(accessToken.getOpenId());
credential.setAuthType(Cons.DICTCODE_AUTH_TYPE.WX_MP.name());
credential.setUserTypeClass(IamMember.class);
// 账户存在,直接登陆
if (V.notEmpty(account)) {
return AuthServiceFactory.getAuthService(Cons.DICTCODE_AUTH_TYPE.WX_MP.name()).applyToken(credential);
}
// 账户不存在,表示首次进入,那么需要存储信息
WxOAuth2UserInfo userInfo = wxMpService.getOAuth2Service().getUserInfo(accessToken, null);
IamMember iamMember = mpInfo2IamMemberEntity(userInfo).setUserId(0L).setOrgId(0L).setUserType(IamMember.class.getSimpleName());
iamMemberService.createEntity(iamMember);
// 创建iam_account账号
IamAccount iamAccount = createIamAccountEntity(iamMember, iamMember.getId(), IamMember.class);
iamAccountService.createEntity(iamAccount);
return AuthServiceFactory.getAuthService(Cons.DICTCODE_AUTH_TYPE.WX_MP.name()).applyToken(credential);
}
use of com.diboot.mobile.dto.MobileCredential in project diboot by dibo-software.
the class WxMpUserAuthServiceImpl method applyToken.
@Override
@Transactional(rollbackFor = Exception.class)
public String applyToken(String code, String state) throws Exception {
// 校验STATE
if (V.notEmpty(STATE) && !STATE.equals(state)) {
throw new BusinessException(Status.FAIL_INVALID_PARAM, "非法来源");
}
if (V.isEmpty(code)) {
log.error("请求参数有误: code = null");
throw new BusinessException(Status.FAIL_INVALID_PARAM, "请求参数有误: code is null");
}
WxOAuth2AccessToken accessToken = wxMpService.getOAuth2Service().getAccessToken(code);
// 获取用户信息
IamAccount account = iamAccountService.getSingleEntity(Wrappers.<IamAccount>lambdaQuery().eq(IamAccount::getUserType, IamUser.class.getSimpleName()).eq(IamAccount::getAuthAccount, accessToken.getOpenId()).eq(IamAccount::getAuthType, Cons.DICTCODE_AUTH_TYPE.WX_MP.name()));
MobileCredential credential = new MobileCredential(accessToken.getOpenId());
credential.setAuthType(Cons.DICTCODE_AUTH_TYPE.WX_MP.name());
// 账户存在,直接登陆
if (V.isEmpty(account)) {
throw new BusinessException(Status.FAIL_INVALID_PARAM, "请登陆后绑定再使用快捷登陆");
}
return AuthServiceFactory.getAuthService(Cons.DICTCODE_AUTH_TYPE.WX_MP.name()).applyToken(credential);
}
Aggregations