Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
P
pica-cloud-account
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
Close sidebar
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
com.pica.cloud.account
pica-cloud-account
提交
6d30d491
提交
6d30d491
编写于
4月 13, 2020
作者:
rushui.chen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
20200413 完善本地token
上级
58f83026
流水线
#24251
已失败 于阶段
in 0 second
变更
1
流水线
1
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
590 行增加
和
588 行删除
+590
-588
LoginServiceImpl.java
...account/account/server/service/impl/LoginServiceImpl.java
+590
-588
未找到文件。
server/src/main/java/com/pica/cloud/account/account/server/service/impl/LoginServiceImpl.java
浏览文件 @
6d30d491
...
@@ -249,658 +249,660 @@ public class LoginServiceImpl implements LoginService {
...
@@ -249,658 +249,660 @@ public class LoginServiceImpl implements LoginService {
if
(
productType
==
AccountTypeEnum
.
PRODUCT_TYPE_DOCTOR
.
getCode
())
{
if
(
productType
==
AccountTypeEnum
.
PRODUCT_TYPE_DOCTOR
.
getCode
())
{
result
.
setEntireFlag
(
doctorInfo
.
getEntireFlag
());
result
.
setEntireFlag
(
doctorInfo
.
getEntireFlag
());
LogLoginEntity
entity
=
AccountLogEntityUtils
.
getLogLoginEntity
(
acctId
,
productType
,
sourceType
,
LogLoginEntity
entity
=
AccountLogEntityUtils
.
getLogLoginEntity
(
acctId
,
productType
,
sourceType
,
AccountTypeEnum
.
LOGIN_PWD
.
getCode
(),
request
.
getLoginIp
(),
AccountTypeEnum
.
LOGIN_STATUS_SUCCESS
.
getCode
(),
AccountTypeEnum
.
LOGIN_PWD
.
getCode
(),
request
.
getLoginIp
(),
AccountTypeEnum
.
LOGIN_STATUS_SUCCESS
.
getCode
(),
AccountTypeEnum
.
LOG_TYPE_LOGIN
.
getCode
(),
newToken
,
1
,
request
.
getUserTokenTourist
());
AccountTypeEnum
.
LOG_TYPE_LOGIN
.
getCode
(),
newToken
,
1
,
request
.
getUserTokenTourist
());
picaLogUtils
.
info
(
entity
);
picaLogUtils
.
info
(
entity
);
// 密码登录成功以后,清除错误次数记录
// 密码登录成功以后,清除错误次数记录
String
pwdErrorNum
=
Constants
.
PWD_ERROR_NUM_KEY
.
replace
(
"{mobile}"
,
mobile
);
String
pwdErrorNum
=
Constants
.
PWD_ERROR_NUM_KEY
.
replace
(
"{mobile}"
,
mobile
);
if
(
redisClient
.
exists
(
pwdErrorNum
))
{
if
(
redisClient
.
exists
(
pwdErrorNum
))
{
redisClient
.
del
(
pwdErrorNum
);
redisClient
.
del
(
pwdErrorNum
);
}
}
}
return
result
;
return
result
;
}
}
@Override
public
LoginResult
loginAndRegister
(
BaseRequest
baseRequest
)
{
String
mobile
=
baseRequest
.
getMobile
();
AccountInfoEntity
accountInfoEntity
=
accountInfoDetailMapper
.
selectByMobile
(
AESUtil
.
encryptV0
(
mobile
));
logger
.
info
(
"loginAndRegister-accountInfoEntity is null {}, clientIp:{}"
,
(
accountInfoEntity
==
null
),
baseRequest
.
getLoginIp
());
if
(
accountInfoEntity
==
null
)
{
//说明是注册功能
accountUtils
.
checkRegisterMobilePhoneAndAuthCode
(
baseRequest
.
getMobile
(),
baseRequest
.
getFlag
()
+
""
,
baseRequest
.
getAuthCode
());
return
registerService
.
register
(
baseRequest
);
}
else
{
//登录功能
accountUtils
.
checkMobilePhoneAndAuthCode
(
baseRequest
.
getMobile
(),
AccountTypeEnum
.
SYSCODE_TYPE_LOGIN
.
getCode
()
+
""
,
baseRequest
.
getAuthCode
());
return
processLogin
(
baseRequest
,
accountInfoEntity
.
getId
(),
AccountTypeEnum
.
LOGIN_CODE
.
getCode
());
}
}
/**
* 登录逻辑处理
* 登录逻辑处理
*
* @param baseRequest
*/
private
LoginResult
processLogin
(
BaseRequest
baseRequest
,
Integer
acctId
,
Integer
loginType
)
{
return
processLogin
(
baseRequest
,
acctId
,
loginType
,
null
);
}
private
LoginResult
processLogin
(
BaseRequest
baseRequest
,
Integer
acctId
,
Integer
loginType
,
QueryMobileEntity
queryMobileEntity
)
{
@Override
Date
currentTime
=
new
Date
();
public
LoginResult
loginAndRegister
(
BaseRequest
baseRequest
)
{
Long
userId
=
accountUtils
.
getUserIdByAcctId
(
baseRequest
.
getProductType
(),
acctId
);
String
mobile
=
baseRequest
.
getMobile
();
Account
account
=
new
Account
();
AccountInfoEntity
accountInfoEntity
=
accountInfoDetailMapper
.
selectByMobile
(
AESUtil
.
encryptV0
(
mobile
));
account
.
setId
(
userId
);
logger
.
info
(
"loginAndRegister-accountInfoEntity is null {}, clientIp:{}"
,
(
accountInfoEntity
==
null
),
baseRequest
.
getLoginIp
());
account
.
setAcctId
(
acctId
);
if
(
accountInfoEntity
==
null
)
{
account
.
setCreatTime
(
currentTime
);
//说明是注册功能
account
.
setMobilePhone
(
baseRequest
.
getMobile
());
accountUtils
.
checkRegisterMobilePhoneAndAuthCode
(
baseRequest
.
getMobile
(),
baseRequest
.
getFlag
()
+
""
,
baseRequest
.
getAuthCode
());
account
.
setRegisterSource
(
baseRequest
.
getSourceType
());
return
registerService
.
register
(
baseRequest
);
String
newToken
=
tokenUtils
.
generateToken
(
account
);
}
else
{
LoginResult
result
=
new
LoginResult
();
//登录功能
result
.
setToken
(
newToken
);
accountUtils
.
checkMobilePhoneAndAuthCode
(
baseRequest
.
getMobile
(),
AccountTypeEnum
.
SYSCODE_TYPE_LOGIN
.
getCode
()
+
""
,
baseRequest
.
getAuthCode
());
result
.
setUserId
(
userId
);
return
processLogin
(
baseRequest
,
accountInfoEntity
.
getId
(),
AccountTypeEnum
.
LOGIN_CODE
.
getCode
());
result
.
setMobile
(
baseRequest
.
getMobile
());
}
result
.
setDoctorId
(
EncryptUtils
.
encryptContent
(
userId
+
""
,
EncryptConstants
.
ENCRYPT_TYPE_ID
));
//是否完善过个人信息(云鹊医app才需要)
if
(
baseRequest
.
getProductType
()
==
AccountTypeEnum
.
PRODUCT_TYPE_DOCTOR
.
getCode
())
{
Doctor
doctorEntity
=
doctorInfoMapper
.
selectByPrimaryKey
(
userId
.
intValue
());
result
.
setEntireFlag
(
doctorEntity
.
getEntireFlag
());
}
//记录登录日志
LogLoginEntity
entity
=
AccountLogEntityUtils
.
getLogLoginEntity
(
acctId
,
baseRequest
.
getProductType
(),
baseRequest
.
getSourceType
(),
loginType
,
baseRequest
.
getLoginIp
(),
AccountTypeEnum
.
LOGIN_STATUS_SUCCESS
.
getCode
(),
AccountTypeEnum
.
LOG_TYPE_LOGIN
.
getCode
(),
newToken
,
1
,
baseRequest
.
getUserTokenTourist
);
if
(
queryMobileEntity
!=
null
)
{
entity
.
setQueryMobileEntity
(
queryMobileEntity
);
}
}
picaLogUtils
.
info
(
entity
);
return
result
;
}
@Override
/**
@Transactional
* 登录逻辑处理
public
LoginResult
loginByWeChat
(
BaseRequest
request
)
{
* 登录逻辑处理
WeChatEntity
weChatEntity
=
null
;
*
if
(
null
!=
request
.
getBizType
()
&&
* @param baseRequest
request
.
getBizType
().
equals
(
1
))
{
*/
// h5微信登录 TODO 下次单独拆分出去一个新接口
private
LoginResult
processLogin
(
BaseRequest
baseRequest
,
Integer
acctId
,
Integer
loginType
)
{
weChatEntity
=
WeChatUtils
.
getAuthorizationInfo
(
appIdH5
,
appSecretH5
,
request
.
getWeChatCode
());
return
processLogin
(
baseRequest
,
acctId
,
loginType
,
null
);
}
else
{
// 原生微信登录
weChatEntity
=
WeChatUtils
.
getAuthorizationInfo
(
appId
,
appSecret
,
request
.
getWeChatCode
());
}
if
(
weChatEntity
==
null
||
StringUtils
.
isEmpty
(
weChatEntity
.
getOpenid
())
||
StringUtils
.
isEmpty
(
weChatEntity
.
getAccess_token
()))
{
throw
new
PicaException
(
AccountExceptionEnum
.
PICA_WECHAT_CODE_ERROR
.
getCode
(),
AccountExceptionEnum
.
PICA_WECHAT_CODE_ERROR
.
getMessage
());
}
}
// 微信登录获取个人信息
Map
map
=
new
HashMap
();
private
LoginResult
processLogin
(
BaseRequest
baseRequest
,
Integer
acctId
,
Integer
loginType
,
QueryMobileEntity
queryMobileEntity
)
{
map
.
put
(
"access_token"
,
weChatEntity
.
getAccess_token
());
Date
currentTime
=
new
Date
();
map
.
put
(
"openid"
,
weChatEntity
.
getOpenid
());
Long
userId
=
accountUtils
.
getUserIdByAcctId
(
baseRequest
.
getProductType
(),
acctId
);
Map
weChatUserInfo
=
WeChatUtils
.
getWeChatUserInfo
(
map
,
weChatURL
);
WeChatUserInfoEntity
weChatUserInfoEntity
=
WeChatUtils
.
mergeWechatUserInfo
(
weChatUserInfo
,
weChatEntity
.
getOpenid
());
String
unionId
=
weChatUserInfoEntity
.
getUnionid
();
AccountUnionEntity
accountUnionEntity
=
accountUnionMapper
.
selectByUnionId
(
unionId
);
//是否绑定逻辑的判断
if
(
accountUnionEntity
!=
null
)
{
Long
acctId
=
accountUnionEntity
.
getAcctId
();
Long
userId
=
accountUtils
.
getUserIdByAcctId
(
request
.
getProductType
(),
acctId
.
intValue
());
Account
account
=
new
Account
();
Account
account
=
new
Account
();
account
.
setId
(
userId
);
account
.
setId
(
userId
);
account
.
setAcctId
(
acctId
.
intValue
());
account
.
setAcctId
(
acctId
);
account
.
setCreatTime
(
new
Date
());
account
.
setCreatTime
(
currentTime
);
//account.setMobilePhone(request.getMobile());
account
.
setMobilePhone
(
baseRequest
.
getMobile
());
account
.
setMobilePhone
(
""
);
account
.
setRegisterSource
(
baseRequest
.
getSourceType
());
account
.
setRegisterSource
(
request
.
getSourceType
());
String
newToken
=
tokenUtils
.
generateToken
(
account
);
String
newToken
=
tokenUtils
.
generateToken
(
account
);
LoginResult
result
=
new
LoginResult
();
LoginResult
result
=
new
LoginResult
();
result
.
setToken
(
newToken
);
result
.
setToken
(
newToken
);
result
.
setUserId
(
userId
);
result
.
setUserId
(
userId
);
result
.
set
BindFlag
(
AccountTypeEnum
.
BIND_STATUS_SUCCESS
.
getCode
()
+
""
);
result
.
set
Mobile
(
baseRequest
.
getMobile
()
);
result
.
setDoctorId
(
EncryptUtils
.
encryptContent
(
userId
+
""
,
EncryptConstants
.
ENCRYPT_TYPE_ID
));
result
.
setDoctorId
(
EncryptUtils
.
encryptContent
(
userId
+
""
,
EncryptConstants
.
ENCRYPT_TYPE_ID
));
if
(
request
.
getProductType
()
==
AccountTypeEnum
.
PRODUCT_TYPE_DOCTOR
.
getCode
())
{
//是否完善过个人信息(云鹊医app才需要)
PICAPDoctor
doctor
=
doctorInfoMapper
.
queryDoctor
(
userId
);
if
(
baseRequest
.
getProductType
()
==
AccountTypeEnum
.
PRODUCT_TYPE_DOCTOR
.
getCode
())
{
result
.
setEntireFlag
(
doctor
.
getEntire_flag
());
Doctor
doctorEntity
=
doctorInfoMapper
.
selectByPrimaryKey
(
userId
.
intValue
());
result
.
set
Mobile
(
AESUtil
.
decryptV0
(
doctor
.
getMobile_phone
()
));
result
.
set
EntireFlag
(
doctorEntity
.
getEntireFlag
(
));
}
}
//记录登录日志
//记录登录日志
LogLoginEntity
entity
=
AccountLogEntityUtils
.
getLogLoginEntity
(
LogLoginEntity
entity
=
AccountLogEntityUtils
.
getLogLoginEntity
(
acctId
,
baseRequest
.
getProductType
(),
baseRequest
.
getSourceType
(),
Integer
.
valueOf
(
String
.
valueOf
(
acctId
)),
loginType
,
baseRequest
.
getLoginIp
(),
AccountTypeEnum
.
LOGIN_STATUS_SUCCESS
.
getCode
(),
AccountTypeEnum
.
LOG_TYPE_LOGIN
.
getCode
(),
newToken
,
1
,
baseRequest
.
getUserTokenTourist
());
request
.
getProductType
(),
request
.
getSourceType
(),
if
(
queryMobileEntity
!=
null
)
{
AccountTypeEnum
.
LOGIN_WE_CHAT
.
getCode
(),
entity
.
setQueryMobileEntity
(
queryMobileEntity
);
request
.
getLoginIp
(),
AccountTypeEnum
.
LOGIN_STATUS_SUCCESS
.
getCode
(),
AccountTypeEnum
.
LOG_TYPE_LOGIN
.
getCode
(),
newToken
,
1
,
request
.
getUserTokenTourist
());
picaLogUtils
.
info
(
entity
);
return
result
;
}
else
{
AccountWeChatInfoEntity
entity
=
accountWeChatInfoMapper
.
selectByUnionId
(
unionId
);
//如果微信信息表数据不存在,就把用户信息存储到微信信息表中。
if
(
entity
==
null
)
{
processWeChatInfoUser
(
weChatUserInfoEntity
,
request
.
getWeChatLoginType
());
}
}
LoginResult
result
=
new
LoginResult
();
picaLogUtils
.
info
(
entity
);
result
.
setUnionId
(
unionId
);
result
.
setBindFlag
(
AccountTypeEnum
.
BIND_STATUS_FAILURE
.
getCode
()
+
""
);
return
result
;
return
result
;
}
}
}
@Override
@Override
public
LoginResult
loginByWeChatStep
(
BaseRequest
request
)
{
@Transactional
//判断当前手机号是否注册过,注册过,直接登录;没有注册过,进行注册操操作
public
LoginResult
loginByWeChat
(
BaseRequest
request
)
{
AccountInfoEntity
accountInfoEntity
=
accountInfoDetailMapper
.
selectByMobile
(
AESUtil
.
encryptV0
(
request
.
getMobile
()));
WeChatEntity
weChatEntity
=
null
;
logger
.
info
(
"loginByWeChatStep-accountInfoEntity is null {}, clientIp:{}"
,
(
accountInfoEntity
==
null
),
request
.
getLoginIp
());
if
(
null
!=
request
.
getBizType
()
&&
LoginResult
result
;
request
.
getBizType
().
equals
(
1
))
{
if
(
accountInfoEntity
==
null
)
{
// h5微信登录 TODO 下次单独拆分出去一个新接口
accountUtils
.
checkRegisterMobilePhoneAndAuthCode
(
weChatEntity
=
WeChatUtils
.
getAuthorizationInfo
(
appIdH5
,
appSecretH5
,
request
.
getWeChatCode
());
request
.
getMobile
(),
}
else
{
AccountTypeEnum
.
SYSCODE_TYPE_WE_CHAT
.
getCode
()
+
""
,
// 原生微信登录
request
.
getAuthCode
());
weChatEntity
=
WeChatUtils
.
getAuthorizationInfo
(
appId
,
appSecret
,
request
.
getWeChatCode
());
result
=
registerService
.
register
(
request
);
}
if
(
doubleWritingMode
)
{
if
(
weChatEntity
==
null
||
StringUtils
.
isEmpty
(
weChatEntity
.
getOpenid
())
||
StringUtils
.
isEmpty
(
weChatEntity
.
getAccess_token
()))
{
//双写模式下,要在doctor表存储unionId
throw
new
PicaException
(
AccountExceptionEnum
.
PICA_WECHAT_CODE_ERROR
.
getCode
(),
AccountExceptionEnum
.
PICA_WECHAT_CODE_ERROR
.
getMessage
());
if
(
result
.
getUserId
()
!=
null
)
{
}
Doctor
doctor
=
new
Doctor
();
// 微信登录获取个人信息
doctor
.
setId
(
result
.
getUserId
().
intValue
());
Map
map
=
new
HashMap
();
doctor
.
setUnionid
(
request
.
getUnionId
());
map
.
put
(
"access_token"
,
weChatEntity
.
getAccess_token
());
doctorInfoMapper
.
updateByPrimaryKeySelective
(
doctor
);
map
.
put
(
"openid"
,
weChatEntity
.
getOpenid
());
Map
weChatUserInfo
=
WeChatUtils
.
getWeChatUserInfo
(
map
,
weChatURL
);
WeChatUserInfoEntity
weChatUserInfoEntity
=
WeChatUtils
.
mergeWechatUserInfo
(
weChatUserInfo
,
weChatEntity
.
getOpenid
());
String
unionId
=
weChatUserInfoEntity
.
getUnionid
();
AccountUnionEntity
accountUnionEntity
=
accountUnionMapper
.
selectByUnionId
(
unionId
);
//是否绑定逻辑的判断
if
(
accountUnionEntity
!=
null
)
{
Long
acctId
=
accountUnionEntity
.
getAcctId
();
Long
userId
=
accountUtils
.
getUserIdByAcctId
(
request
.
getProductType
(),
acctId
.
intValue
());
Account
account
=
new
Account
();
account
.
setId
(
userId
);
account
.
setAcctId
(
acctId
.
intValue
());
account
.
setCreatTime
(
new
Date
());
//account.setMobilePhone(request.getMobile());
account
.
setMobilePhone
(
""
);
account
.
setRegisterSource
(
request
.
getSourceType
());
String
newToken
=
tokenUtils
.
generateToken
(
account
);
LoginResult
result
=
new
LoginResult
();
result
.
setToken
(
newToken
);
result
.
setUserId
(
userId
);
result
.
setBindFlag
(
AccountTypeEnum
.
BIND_STATUS_SUCCESS
.
getCode
()
+
""
);
result
.
setDoctorId
(
EncryptUtils
.
encryptContent
(
userId
+
""
,
EncryptConstants
.
ENCRYPT_TYPE_ID
));
if
(
request
.
getProductType
()
==
AccountTypeEnum
.
PRODUCT_TYPE_DOCTOR
.
getCode
())
{
PICAPDoctor
doctor
=
doctorInfoMapper
.
queryDoctor
(
userId
);
result
.
setEntireFlag
(
doctor
.
getEntire_flag
());
result
.
setMobile
(
AESUtil
.
decryptV0
(
doctor
.
getMobile_phone
()));
}
}
//记录登录日志
LogLoginEntity
entity
=
AccountLogEntityUtils
.
getLogLoginEntity
(
Integer
.
valueOf
(
String
.
valueOf
(
acctId
)),
request
.
getProductType
(),
request
.
getSourceType
(),
AccountTypeEnum
.
LOGIN_WE_CHAT
.
getCode
(),
request
.
getLoginIp
(),
AccountTypeEnum
.
LOGIN_STATUS_SUCCESS
.
getCode
(),
AccountTypeEnum
.
LOG_TYPE_LOGIN
.
getCode
(),
newToken
,
1
,
request
.
getUserTokenTourist
());
picaLogUtils
.
info
(
entity
);
return
result
;
}
else
{
AccountWeChatInfoEntity
entity
=
accountWeChatInfoMapper
.
selectByUnionId
(
unionId
);
//如果微信信息表数据不存在,就把用户信息存储到微信信息表中。
if
(
entity
==
null
)
{
processWeChatInfoUser
(
weChatUserInfoEntity
,
request
.
getWeChatLoginType
());
}
LoginResult
result
=
new
LoginResult
();
result
.
setUnionId
(
unionId
);
result
.
setBindFlag
(
AccountTypeEnum
.
BIND_STATUS_FAILURE
.
getCode
()
+
""
);
return
result
;
}
}
}
else
{
accountUtils
.
checkMobilePhoneAndAuthCode
(
request
.
getMobile
(),
AccountTypeEnum
.
SYSCODE_TYPE_WE_CHAT
.
getCode
()
+
""
,
request
.
getAuthCode
());
result
=
processLogin
(
request
,
accountInfoEntity
.
getId
(),
AccountTypeEnum
.
LOGIN_WE_CHAT
.
getCode
());
}
}
result
.
setMobile
(
request
.
getMobile
());
AccountInfoEntity
accountInfo
=
accountInfoDetailMapper
.
selectByMobile
(
AESUtil
.
encryptV0
(
request
.
getMobile
()));
Integer
acctId
=
accountInfo
.
getId
();
processAccountUnion
(
acctId
,
request
.
getUnionId
(),
request
.
getProductType
());
return
result
;
}
@Override
@Override
@Transactional
public
LoginResult
loginByWeChatStep
(
BaseRequest
request
)
{
public
void
unbindWeChat
(
long
doctorId
)
{
//判断当前手机号是否注册过,注册过,直接登录;没有注册过,进行注册操操作
Integer
acctId
=
doctorInfoMapper
.
getAcctIdByDoctorId
(
doctorId
);
AccountInfoEntity
accountInfoEntity
=
accountInfoDetailMapper
.
selectByMobile
(
AESUtil
.
encryptV0
(
request
.
getMobile
()));
Map
<
String
,
Object
>
map
=
new
HashedMap
(
2
);
logger
.
info
(
"loginByWeChatStep-accountInfoEntity is null {}, clientIp:{}"
,
(
accountInfoEntity
==
null
),
request
.
getLoginIp
());
map
.
put
(
"acctId"
,
acctId
);
LoginResult
result
;
map
.
put
(
"unionType"
,
AccountTypeEnum
.
UNION_LOGIN_WE_CHAT
.
getCode
());
if
(
accountInfoEntity
==
null
)
{
accountUnionMapper
.
updateUnbindByAcctId
(
map
);
accountUtils
.
checkRegisterMobilePhoneAndAuthCode
(
if
(
doubleWritingMode
)
{
request
.
getMobile
(),
doctorService
.
unbindWeChat
(
acctId
);
AccountTypeEnum
.
SYSCODE_TYPE_WE_CHAT
.
getCode
()
+
""
,
request
.
getAuthCode
());
result
=
registerService
.
register
(
request
);
if
(
doubleWritingMode
)
{
//双写模式下,要在doctor表存储unionId
if
(
result
.
getUserId
()
!=
null
)
{
Doctor
doctor
=
new
Doctor
();
doctor
.
setId
(
result
.
getUserId
().
intValue
());
doctor
.
setUnionid
(
request
.
getUnionId
());
doctorInfoMapper
.
updateByPrimaryKeySelective
(
doctor
);
}
}
}
else
{
accountUtils
.
checkMobilePhoneAndAuthCode
(
request
.
getMobile
(),
AccountTypeEnum
.
SYSCODE_TYPE_WE_CHAT
.
getCode
()
+
""
,
request
.
getAuthCode
());
result
=
processLogin
(
request
,
accountInfoEntity
.
getId
(),
AccountTypeEnum
.
LOGIN_WE_CHAT
.
getCode
());
}
result
.
setMobile
(
request
.
getMobile
());
AccountInfoEntity
accountInfo
=
accountInfoDetailMapper
.
selectByMobile
(
AESUtil
.
encryptV0
(
request
.
getMobile
()));
Integer
acctId
=
accountInfo
.
getId
();
processAccountUnion
(
acctId
,
request
.
getUnionId
(),
request
.
getProductType
());
return
result
;
}
}
}
@Override
@Override
@Transactional
@Transactional
public
String
bindWeChat
(
long
doctorId
,
BaseRequest
request
)
{
public
void
unbindWeChat
(
long
doctorId
)
{
WeChatEntity
weChatEntity
=
WeChatUtils
.
getAuthorizationInfo
(
appId
,
appSecret
,
request
.
getWeChatCode
());
Integer
acctId
=
doctorInfoMapper
.
getAcctIdByDoctorId
(
doctorId
);
Map
map
=
new
HashMap
();
Map
<
String
,
Object
>
map
=
new
HashedMap
(
2
);
map
.
put
(
"access_token"
,
weChatEntity
.
getAccess_token
());
map
.
put
(
"acctId"
,
acctId
);
map
.
put
(
"openid"
,
weChatEntity
.
getOpenid
());
map
.
put
(
"unionType"
,
AccountTypeEnum
.
UNION_LOGIN_WE_CHAT
.
getCode
());
Map
weChatUserInfo
=
WeChatUtils
.
getWeChatUserInfo
(
map
,
weChatURL
);
accountUnionMapper
.
updateUnbindByAcctId
(
map
);
WeChatUserInfoEntity
weChatUserInfoEntity
=
WeChatUtils
.
mergeWechatUserInfo
(
weChatUserInfo
,
weChatEntity
.
getOpenid
());
if
(
doubleWritingMode
)
{
String
unionId
=
weChatUserInfoEntity
.
getUnionid
();
doctorService
.
unbindWeChat
(
acctId
);
AccountWeChatInfoEntity
entity
=
accountWeChatInfoMapper
.
selectByUnionId
(
unionId
);
}
if
(
entity
==
null
)
{
processWeChatInfoUser
(
weChatUserInfoEntity
,
request
.
getWeChatLoginType
());
}
else
{
updateWechatInfoUser
(
entity
,
weChatUserInfoEntity
);
}
}
Integer
acctId
=
doctorInfoMapper
.
getAcctIdByDoctorId
(
doctorId
);
processAccountUnion
(
acctId
,
unionId
,
request
.
getProductType
());
return
weChatUserInfoEntity
.
getNickname
();
}
/**
@Override
* 把unionId存储到联合登录表中
@Transactional
*
public
String
bindWeChat
(
long
doctorId
,
BaseRequest
request
)
{
* @param acctId
WeChatEntity
weChatEntity
=
WeChatUtils
.
getAuthorizationInfo
(
appId
,
appSecret
,
request
.
getWeChatCode
());
* @param unionId
Map
map
=
new
HashMap
();
*/
map
.
put
(
"access_token"
,
weChatEntity
.
getAccess_token
());
private
void
processAccountUnion
(
Integer
acctId
,
String
unionId
,
Integer
productType
)
{
map
.
put
(
"openid"
,
weChatEntity
.
getOpenid
());
//先查询当前产品线是否有记录?如果有就更新成delete_flag=2; 然后在插入新的绑定记录
Map
weChatUserInfo
=
WeChatUtils
.
getWeChatUserInfo
(
map
,
weChatURL
);
AccountUnionEntity
accountUnionResult
=
accountUnionMapper
.
selectByUnionId
(
unionId
);
WeChatUserInfoEntity
weChatUserInfoEntity
=
WeChatUtils
.
mergeWechatUserInfo
(
weChatUserInfo
,
weChatEntity
.
getOpenid
());
if
(
accountUnionResult
!=
null
)
{
String
unionId
=
weChatUserInfoEntity
.
getUnionid
();
throw
new
PicaException
(
AccountExceptionEnum
.
PICA_WECHAT_UNBIND
.
getCode
(),
AccountExceptionEnum
.
PICA_WECHAT_UNBIND
.
getMessage
());
AccountWeChatInfoEntity
entity
=
accountWeChatInfoMapper
.
selectByUnionId
(
unionId
);
}
if
(
entity
==
null
)
{
Map
<
String
,
Object
>
map
=
new
HashedMap
(
2
);
processWeChatInfoUser
(
weChatUserInfoEntity
,
request
.
getWeChatLoginType
());
map
.
put
(
"acctId"
,
acctId
);
}
else
{
map
.
put
(
"unionType"
,
AccountTypeEnum
.
UNION_LOGIN_WE_CHAT
.
getCode
());
updateWechatInfoUser
(
entity
,
weChatUserInfoEntity
);
AccountUnionEntity
accountUnionEntityAccount
=
accountUnionMapper
.
selectByAcctId
(
map
);
}
if
(
accountUnionEntityAccount
!=
null
)
{
Integer
acctId
=
doctorInfoMapper
.
getAcctIdByDoctorId
(
doctorId
);
throw
new
PicaException
(
AccountExceptionEnum
.
PICA_WECHAT_BIND_OTHER
.
getCode
(),
AccountExceptionEnum
.
PICA_WECHAT_BIND_OTHER
.
getMessage
());
processAccountUnion
(
acctId
,
unionId
,
request
.
getProductType
());
}
return
weChatUserInfoEntity
.
getNickname
();
AccountUnionEntity
accountUnionEntity
=
new
AccountUnionEntity
();
}
accountUnionEntity
.
setAcctId
(
acctId
.
longValue
());
accountUnionEntity
.
setDeleteFlag
(
1
);
/**
accountUnionEntity
.
setUnionId
(
unionId
);
* 把unionId存储到联合登录表中
accountUnionEntity
.
setCreatedTime
(
new
Date
());
*
accountUnionEntity
.
setModifiedTime
(
new
Date
());
* @param acctId
accountUnionEntity
.
setCreatedId
(
acctId
);
* @param unionId
accountUnionEntity
.
setModifiedId
(
acctId
);
*/
accountUnionEntity
.
setUnionType
(
AccountTypeEnum
.
UNION_LOGIN_WE_CHAT
.
getCode
());
private
void
processAccountUnion
(
Integer
acctId
,
String
unionId
,
Integer
productType
)
{
accountUnionMapper
.
insertSelective
(
accountUnionEntity
);
//先查询当前产品线是否有记录?如果有就更新成delete_flag=2; 然后在插入新的绑定记录
if
(
doubleWritingMode
)
{
//双写模式
AccountUnionEntity
accountUnionResult
=
accountUnionMapper
.
selectByUnionId
(
unionId
);
doctorService
.
bindWeChat
(
acctId
,
unionId
);
if
(
accountUnionResult
!=
null
)
{
throw
new
PicaException
(
AccountExceptionEnum
.
PICA_WECHAT_UNBIND
.
getCode
(),
AccountExceptionEnum
.
PICA_WECHAT_UNBIND
.
getMessage
());
}
Map
<
String
,
Object
>
map
=
new
HashedMap
(
2
);
map
.
put
(
"acctId"
,
acctId
);
map
.
put
(
"unionType"
,
AccountTypeEnum
.
UNION_LOGIN_WE_CHAT
.
getCode
());
AccountUnionEntity
accountUnionEntityAccount
=
accountUnionMapper
.
selectByAcctId
(
map
);
if
(
accountUnionEntityAccount
!=
null
)
{
throw
new
PicaException
(
AccountExceptionEnum
.
PICA_WECHAT_BIND_OTHER
.
getCode
(),
AccountExceptionEnum
.
PICA_WECHAT_BIND_OTHER
.
getMessage
());
}
AccountUnionEntity
accountUnionEntity
=
new
AccountUnionEntity
();
accountUnionEntity
.
setAcctId
(
acctId
.
longValue
());
accountUnionEntity
.
setDeleteFlag
(
1
);
accountUnionEntity
.
setUnionId
(
unionId
);
accountUnionEntity
.
setCreatedTime
(
new
Date
());
accountUnionEntity
.
setModifiedTime
(
new
Date
());
accountUnionEntity
.
setCreatedId
(
acctId
);
accountUnionEntity
.
setModifiedId
(
acctId
);
accountUnionEntity
.
setUnionType
(
AccountTypeEnum
.
UNION_LOGIN_WE_CHAT
.
getCode
());
accountUnionMapper
.
insertSelective
(
accountUnionEntity
);
if
(
doubleWritingMode
)
{
//双写模式
doctorService
.
bindWeChat
(
acctId
,
unionId
);
}
}
}
}
private
void
processWeChatInfoUser
(
WeChatUserInfoEntity
weChatUserInfoEntity
,
int
type
)
{
private
void
processWeChatInfoUser
(
WeChatUserInfoEntity
weChatUserInfoEntity
,
int
type
)
{
AccountWeChatInfoEntity
accountWeChatInfoEntity
=
new
AccountWeChatInfoEntity
();
AccountWeChatInfoEntity
accountWeChatInfoEntity
=
new
AccountWeChatInfoEntity
();
Date
currentTime
=
new
Date
();
Date
currentTime
=
new
Date
();
accountWeChatInfoEntity
.
setCreatedId
(
0
);
accountWeChatInfoEntity
.
setCreatedId
(
0
);
accountWeChatInfoEntity
.
setCreatedTime
(
currentTime
);
accountWeChatInfoEntity
.
setCreatedTime
(
currentTime
);
accountWeChatInfoEntity
.
setDeleteFlag
(
1
);
accountWeChatInfoEntity
.
setDeleteFlag
(
1
);
accountWeChatInfoEntity
.
setGroupid
(
weChatUserInfoEntity
.
getGroupid
()
+
""
);
accountWeChatInfoEntity
.
setGroupid
(
weChatUserInfoEntity
.
getGroupid
()
+
""
);
accountWeChatInfoEntity
.
setType
(
type
);
accountWeChatInfoEntity
.
setType
(
type
);
accountWeChatInfoEntity
.
setModifiedId
(
0
);
accountWeChatInfoEntity
.
setModifiedId
(
0
);
accountWeChatInfoEntity
.
setModifiedTime
(
currentTime
);
accountWeChatInfoEntity
.
setModifiedTime
(
currentTime
);
accountWeChatInfoEntity
.
setOpenid
(
weChatUserInfoEntity
.
getOpenid
());
accountWeChatInfoEntity
.
setOpenid
(
weChatUserInfoEntity
.
getOpenid
());
accountWeChatInfoEntity
.
setUnionid
(
weChatUserInfoEntity
.
getUnionid
());
accountWeChatInfoEntity
.
setUnionid
(
weChatUserInfoEntity
.
getUnionid
());
accountWeChatInfoEntity
.
setPrivilege
(
weChatUserInfoEntity
.
getPrivilege
());
accountWeChatInfoEntity
.
setPrivilege
(
weChatUserInfoEntity
.
getPrivilege
());
accountWeChatInfoEntity
.
setRemark
(
weChatUserInfoEntity
.
getRemark
());
accountWeChatInfoEntity
.
setRemark
(
weChatUserInfoEntity
.
getRemark
());
accountWeChatInfoEntity
.
setSubscribe
(
weChatUserInfoEntity
.
getSubscribe
());
accountWeChatInfoEntity
.
setSubscribe
(
weChatUserInfoEntity
.
getSubscribe
());
accountWeChatInfoEntity
.
setSubscribeTime
(
weChatUserInfoEntity
.
getSubscribe_time
());
accountWeChatInfoEntity
.
setSubscribeTime
(
weChatUserInfoEntity
.
getSubscribe_time
());
accountWeChatInfoEntity
.
setTagidList
(
weChatUserInfoEntity
.
getTagid_list
());
accountWeChatInfoEntity
.
setTagidList
(
weChatUserInfoEntity
.
getTagid_list
());
accountWeChatInfoEntity
.
setCity
(
weChatUserInfoEntity
.
getCity
());
accountWeChatInfoEntity
.
setCity
(
weChatUserInfoEntity
.
getCity
());
accountWeChatInfoEntity
.
setNickname
(
weChatUserInfoEntity
.
getNickname
());
accountWeChatInfoEntity
.
setNickname
(
weChatUserInfoEntity
.
getNickname
());
accountWeChatInfoEntity
.
setHeadImgUrl
(
weChatUserInfoEntity
.
getHeadimgurl
());
accountWeChatInfoEntity
.
setHeadImgUrl
(
weChatUserInfoEntity
.
getHeadimgurl
());
accountWeChatInfoEntity
.
setCountry
(
weChatUserInfoEntity
.
getCountry
());
accountWeChatInfoEntity
.
setCountry
(
weChatUserInfoEntity
.
getCountry
());
accountWeChatInfoEntity
.
setSex
(
weChatUserInfoEntity
.
getSex
());
accountWeChatInfoEntity
.
setSex
(
weChatUserInfoEntity
.
getSex
());
accountWeChatInfoEntity
.
setProvince
(
weChatUserInfoEntity
.
getProvince
());
accountWeChatInfoEntity
.
setProvince
(
weChatUserInfoEntity
.
getProvince
());
accountWeChatInfoEntity
.
setLanguage
(
weChatUserInfoEntity
.
getLanguage
());
accountWeChatInfoEntity
.
setLanguage
(
weChatUserInfoEntity
.
getLanguage
());
accountWeChatInfoMapper
.
insertSelective
(
accountWeChatInfoEntity
);
accountWeChatInfoMapper
.
insertSelective
(
accountWeChatInfoEntity
);
}
}
private
void
updateWechatInfoUser
(
AccountWeChatInfoEntity
entity
,
WeChatUserInfoEntity
weChatUserInfoEntity
)
{
private
void
updateWechatInfoUser
(
AccountWeChatInfoEntity
entity
,
WeChatUserInfoEntity
weChatUserInfoEntity
)
{
String
nickname
=
weChatUserInfoEntity
.
getNickname
();
String
nickname
=
weChatUserInfoEntity
.
getNickname
();
if
(
StringUtils
.
isNotEmpty
(
nickname
)
&&
!
nickname
.
equals
(
entity
.
getNickname
()))
{
if
(
StringUtils
.
isNotEmpty
(
nickname
)
&&
!
nickname
.
equals
(
entity
.
getNickname
()))
{
AccountWeChatInfoEntity
info
=
new
AccountWeChatInfoEntity
();
AccountWeChatInfoEntity
info
=
new
AccountWeChatInfoEntity
();
info
.
setId
(
entity
.
getId
());
info
.
setId
(
entity
.
getId
());
info
.
setNickname
(
nickname
);
info
.
setNickname
(
nickname
);
accountWeChatInfoMapper
.
updateByPrimaryKeySelective
(
info
);
accountWeChatInfoMapper
.
updateByPrimaryKeySelective
(
info
);
}
}
}
}
@Override
@Override
public
PICAPDoctor
queryDoctor
(
long
doctorId
)
{
public
PICAPDoctor
queryDoctor
(
long
doctorId
)
{
PICAPDoctor
doctor
=
doctorInfoMapper
.
queryDoctor
(
doctorId
);
PICAPDoctor
doctor
=
doctorInfoMapper
.
queryDoctor
(
doctorId
);
if
(
doctor
==
null
)
{
if
(
doctor
==
null
)
{
doctor
=
new
PICAPDoctor
();
doctor
=
new
PICAPDoctor
();
}
doctor
.
setAvatar_image_url
(
this
.
processDoctorAvatar
(
doctor
.
getAvatar_image_url
()));
return
doctor
;
}
}
doctor
.
setAvatar_image_url
(
this
.
processDoctorAvatar
(
doctor
.
getAvatar_image_url
()));
return
doctor
;
}
@Override
@Override
public
LoginResult
oneClickLogin
(
OneClickLoginReq
req
)
{
public
LoginResult
oneClickLogin
(
OneClickLoginReq
req
)
{
QueryMobileEntity
queryMobileEntity
=
oneClickProcessor
.
tokenExchangeMobile
(
req
.
getToken
(),
req
.
getSourceType
());
QueryMobileEntity
queryMobileEntity
=
oneClickProcessor
.
tokenExchangeMobile
(
req
.
getToken
(),
req
.
getSourceType
());
if
(
queryMobileEntity
==
null
||
StringUtils
.
isBlank
(
queryMobileEntity
.
getMobile
())
||
!
ValidateUtils
.
isMobile
(
queryMobileEntity
.
getMobile
()))
{
if
(
queryMobileEntity
==
null
||
StringUtils
.
isBlank
(
queryMobileEntity
.
getMobile
())
||
!
ValidateUtils
.
isMobile
(
queryMobileEntity
.
getMobile
()))
{
throw
new
PicaException
(
PicaResultCode
.
INTERFACE_INVOKE_EXCEPTION
.
code
(),
"获取手机号失败!"
);
throw
new
PicaException
(
PicaResultCode
.
INTERFACE_INVOKE_EXCEPTION
.
code
(),
"获取手机号失败!"
);
}
}
queryMobileEntity
.
setSourceType
(
req
.
getSourceType
());
queryMobileEntity
.
setSourceType
(
req
.
getSourceType
());
AccountInfoEntity
accountInfoEntity
=
accountInfoDetailMapper
.
selectByMobile
(
AESUtil
.
encryptV0
(
queryMobileEntity
.
getMobile
()));
AccountInfoEntity
accountInfoEntity
=
accountInfoDetailMapper
.
selectByMobile
(
AESUtil
.
encryptV0
(
queryMobileEntity
.
getMobile
()));
BaseRequest
baseRequest
=
new
BaseRequest
();
BaseRequest
baseRequest
=
new
BaseRequest
();
baseRequest
.
setMobile
(
queryMobileEntity
.
getMobile
());
baseRequest
.
setMobile
(
queryMobileEntity
.
getMobile
());
baseRequest
.
setSourceType
(
req
.
getSourceType
());
baseRequest
.
setSourceType
(
req
.
getSourceType
());
baseRequest
.
setProductType
(
req
.
getProductType
());
baseRequest
.
setProductType
(
req
.
getProductType
());
baseRequest
.
setLoginIp
(
req
.
getLoginIp
());
baseRequest
.
setLoginIp
(
req
.
getLoginIp
());
LoginResult
result
;
LoginResult
result
;
if
(
accountInfoEntity
==
null
)
{
if
(
accountInfoEntity
==
null
)
{
//说明是注册功能
//说明是注册功能
result
=
registerService
.
register
(
baseRequest
,
queryMobileEntity
);
result
=
registerService
.
register
(
baseRequest
,
queryMobileEntity
);
}
else
{
}
else
{
//登录功能
//登录功能
result
=
processLogin
(
baseRequest
,
accountInfoEntity
.
getId
(),
AccountTypeEnum
.
LOGIN_ONE_CLICK
.
getCode
(),
queryMobileEntity
);
result
=
processLogin
(
baseRequest
,
accountInfoEntity
.
getId
(),
AccountTypeEnum
.
LOGIN_ONE_CLICK
.
getCode
(),
queryMobileEntity
);
}
return
result
;
}
}
return
result
;
}
private
String
processDoctorAvatar
(
String
avatar_image_url
)
{
private
String
processDoctorAvatar
(
String
avatar_image_url
)
{
if
(
StringUtils
.
isEmpty
(
avatar_image_url
))
{
if
(
StringUtils
.
isEmpty
(
avatar_image_url
))
{
return
DEFAULT_DOCTOR_PICTURE_URL
;
}
else
{
int
pos
=
avatar_image_url
.
lastIndexOf
(
"."
);
if
(
pos
<
0
)
{
return
DEFAULT_DOCTOR_PICTURE_URL
;
return
DEFAULT_DOCTOR_PICTURE_URL
;
}
else
{
}
else
{
String
ext
=
avatar_image_url
.
substring
(
pos
+
1
,
avatar_image_url
.
length
()).
toLowerCase
();
int
pos
=
avatar_image_url
.
lastIndexOf
(
"."
);
return
!
PIC_TYPE_MAP
.
containsKey
(
ext
)
?
DEFAULT_DOCTOR_PICTURE_URL
:
avatar_image_url
;
if
(
pos
<
0
)
{
return
DEFAULT_DOCTOR_PICTURE_URL
;
}
else
{
String
ext
=
avatar_image_url
.
substring
(
pos
+
1
,
avatar_image_url
.
length
()).
toLowerCase
();
return
!
PIC_TYPE_MAP
.
containsKey
(
ext
)
?
DEFAULT_DOCTOR_PICTURE_URL
:
avatar_image_url
;
}
}
}
}
}
}
/**
/**
* @Description 统一校验(传空则不会校验)
* @Description 统一校验(传空则不会校验)
* @Author Chongwen.jiang
* @Author Chongwen.jiang
* @Date 2020/2/20 16:55
* @Date 2020/2/20 16:55
* @ModifyDate 2020/2/20 16:55
* @ModifyDate 2020/2/20 16:55
* @Params [request]
* @Params [request]
* @Return com.pica.cloud.foundation.entity.PicaResponse
* @Return com.pica.cloud.foundation.entity.PicaResponse
*/
*/
@Override
@Override
public
void
preLoginValidate
(
BaseRequest
request
)
{
public
void
preLoginValidate
(
BaseRequest
request
)
{
Integer
bizType
=
request
.
getBizType
();
Integer
bizType
=
request
.
getBizType
();
String
mobile
=
request
.
getMobile
();
String
mobile
=
request
.
getMobile
();
Integer
sourceType
=
request
.
getSourceType
();
Integer
sourceType
=
request
.
getSourceType
();
if
(
null
==
bizType
)
{
if
(
null
==
bizType
)
{
logger
.
info
(
"bizType is null"
);
logger
.
info
(
"bizType is null"
);
throw
new
PicaWarnException
(
PicaResultCode
.
PARAM_IS_BLANK
.
code
(),
throw
new
PicaWarnException
(
PicaResultCode
.
PARAM_IS_BLANK
.
code
(),
PicaResultCode
.
PARAM_IS_BLANK
.
message
());
PicaResultCode
.
PARAM_IS_BLANK
.
message
());
}
}
if
(
bizType
.
equals
(
2
))
{
if
(
bizType
.
equals
(
2
))
{
// 手机号规则校验
// 手机号规则校验
if
(
StringUtils
.
isNotEmpty
(
mobile
)
&&
if
(
StringUtils
.
isNotEmpty
(
mobile
)
&&
!
ValidateUtils
.
isMobile
(
mobile
))
{
!
ValidateUtils
.
isMobile
(
mobile
))
{
throw
new
PicaWarnException
(
AccountExceptionEnum
.
PICA_MOBILE_REG_FALSE
.
getCode
(),
throw
new
PicaWarnException
(
AccountExceptionEnum
.
PICA_MOBILE_REG_FALSE
.
getCode
(),
AccountExceptionEnum
.
PICA_MOBILE_REG_FALSE
.
getMessage
());
AccountExceptionEnum
.
PICA_MOBILE_REG_FALSE
.
getMessage
());
}
}
else
if
(
bizType
.
equals
(
3
))
{
// 手机号规则校验
if
(
StringUtils
.
isNotEmpty
(
mobile
)
&&
!
ValidateUtils
.
isMobile
(
mobile
))
{
throw
new
PicaWarnException
(
AccountExceptionEnum
.
PICA_MOBILE_REG_FALSE
.
getCode
(),
AccountExceptionEnum
.
PICA_MOBILE_REG_FALSE
.
getMessage
());
}
// 手机号是否注册
AccountInfoEntity
accountInfo
=
accountInfoDetailMapper
.
selectByMobile
(
AESUtil
.
encryptV0
(
mobile
));
if
(
accountInfo
==
null
)
{
if
(
sourceType
!=
null
&&
SourceTypeEnum
.
H5
.
getCode
().
equals
(
sourceType
))
{
throw
new
PicaWarnException
(
AccountExceptionEnum
.
PICA_MOBILE_NOT_REGIST_H5
.
getCode
(),
AccountExceptionEnum
.
PICA_MOBILE_NOT_REGIST_H5
.
getMessage
());
}
else
{
throw
new
PicaWarnException
(
AccountExceptionEnum
.
PICA_MOBILE_NOT_REGIST
.
getCode
(),
AccountExceptionEnum
.
PICA_MOBILE_NOT_REGIST
.
getMessage
().
replace
(
"{mobile}"
,
mobile
));
}
}
}
}
else
if
(
bizType
.
equals
(
3
))
{
// 手机号是否设置了密码
// 手机号规则校验
if
(
StringUtils
.
isEmpty
(
accountInfo
.
getPassword
()))
{
if
(
StringUtils
.
isNotEmpty
(
mobile
)
&&
if
(
sourceType
!=
null
&&
SourceTypeEnum
.
H5
.
getCode
().
equals
(
sourceType
))
{
!
ValidateUtils
.
isMobile
(
mobile
))
{
throw
new
PicaWarnException
(
AccountExceptionEnum
.
PICA_MOBILE_NOT_SETED_PASSWORD_H5
.
getCode
(),
throw
new
PicaWarnException
(
AccountExceptionEnum
.
PICA_MOBILE_REG_FALSE
.
getCode
(),
AccountExceptionEnum
.
PICA_MOBILE_NOT_SETED_PASSWORD_H5
.
getMessage
());
AccountExceptionEnum
.
PICA_MOBILE_REG_FALSE
.
getMessage
());
}
else
{
}
throw
new
PicaWarnException
(
AccountExceptionEnum
.
PICA_MOBILE_NOT_SETED_PASSWORD
.
getCode
(),
// 手机号是否注册
AccountExceptionEnum
.
PICA_MOBILE_NOT_SETED_PASSWORD
.
getMessage
().
replace
(
"{mobile}"
,
mobile
));
AccountInfoEntity
accountInfo
=
accountInfoDetailMapper
.
selectByMobile
(
AESUtil
.
encryptV0
(
mobile
));
if
(
accountInfo
==
null
)
{
if
(
sourceType
!=
null
&&
SourceTypeEnum
.
H5
.
getCode
().
equals
(
sourceType
))
{
throw
new
PicaWarnException
(
AccountExceptionEnum
.
PICA_MOBILE_NOT_REGIST_H5
.
getCode
(),
AccountExceptionEnum
.
PICA_MOBILE_NOT_REGIST_H5
.
getMessage
());
}
else
{
throw
new
PicaWarnException
(
AccountExceptionEnum
.
PICA_MOBILE_NOT_REGIST
.
getCode
(),
AccountExceptionEnum
.
PICA_MOBILE_NOT_REGIST
.
getMessage
().
replace
(
"{mobile}"
,
mobile
));
}
}
// 手机号是否设置了密码
if
(
StringUtils
.
isEmpty
(
accountInfo
.
getPassword
()))
{
if
(
sourceType
!=
null
&&
SourceTypeEnum
.
H5
.
getCode
().
equals
(
sourceType
))
{
throw
new
PicaWarnException
(
AccountExceptionEnum
.
PICA_MOBILE_NOT_SETED_PASSWORD_H5
.
getCode
(),
AccountExceptionEnum
.
PICA_MOBILE_NOT_SETED_PASSWORD_H5
.
getMessage
());
}
else
{
throw
new
PicaWarnException
(
AccountExceptionEnum
.
PICA_MOBILE_NOT_SETED_PASSWORD
.
getCode
(),
AccountExceptionEnum
.
PICA_MOBILE_NOT_SETED_PASSWORD
.
getMessage
().
replace
(
"{mobile}"
,
mobile
));
}
}
}
}
}
}
}
/**
* @Description 苹果登录授权
* @Author Chongwen.jiang
* @Date 2020/2/24 19:21
* @ModifyDate 2020/2/24 19:21
* @Params [request]
* @Return com.pica.cloud.account.account.server.entity.LoginResult
*/
@Transactional
@Override
public
LoginResult
loginByApple
(
BaseRequest
request
)
{
long
start
=
System
.
currentTimeMillis
();
// 入参非空判断
if
(
StringUtils
.
isEmpty
(
request
.
getIdentifyToken
()))
{
throw
new
PicaException
(
AccountExceptionEnum
.
PICA_PARAMS_ERROR
.
getCode
(),
AccountExceptionEnum
.
PICA_PARAMS_ERROR
.
getMessage
());
}
// identifyToken校验
if
(!
checkIdentifyToken
(
request
)){
throw
new
PicaException
(
AccountExceptionEnum
.
PICA_APPLE_TOKEN_ERROR
.
getCode
(),
AccountExceptionEnum
.
PICA_APPLE_TOKEN_ERROR
.
getMessage
());
}
}
// apple授权登录用户信息入库
AccountUnionEntity
accountUnion
=
accountUnionMapper
.
selectByUnionId
(
request
.
getAppleUserId
());
/**
//是否绑定逻辑的判断
* @Description 苹果登录授权
if
(
accountUnion
!=
null
)
{
* @Author Chongwen.jiang
Long
acctId
=
accountUnion
.
getAcctId
();
* @Date 2020/2/24 19:21
Long
userId
=
accountUtils
.
getUserIdByAcctId
(
null
,
acctId
.
intValue
());
* @ModifyDate 2020/2/24 19:21
Account
account
=
new
Account
();
* @Params [request]
account
.
setId
(
userId
);
* @Return com.pica.cloud.account.account.server.entity.LoginResult
account
.
setAcctId
(
acctId
.
intValue
());
*/
account
.
setCreatTime
(
new
Date
());
@Transactional
account
.
setMobilePhone
(
""
);
@Override
account
.
setRegisterSource
(
request
.
getSourceType
());
public
LoginResult
loginByApple
(
BaseRequest
request
)
{
String
newToken
=
tokenUtils
.
generateToken
(
account
);
long
start
=
System
.
currentTimeMillis
();
LoginResult
result
=
new
LoginResult
();
// 入参非空判断
result
.
setToken
(
newToken
);
if
(
StringUtils
.
isEmpty
(
request
.
getIdentifyToken
()))
{
result
.
setUserId
(
userId
);
throw
new
PicaException
(
AccountExceptionEnum
.
PICA_PARAMS_ERROR
.
getCode
(),
result
.
setBindFlag
(
AccountTypeEnum
.
BIND_STATUS_SUCCESS
.
getCode
()
+
""
);
AccountExceptionEnum
.
PICA_PARAMS_ERROR
.
getMessage
());
result
.
setDoctorId
(
EncryptUtils
.
encryptContent
(
userId
+
""
,
EncryptConstants
.
ENCRYPT_TYPE_ID
));
if
(
request
.
getProductType
()
==
AccountTypeEnum
.
PRODUCT_TYPE_DOCTOR
.
getCode
())
{
PICAPDoctor
doctor
=
doctorInfoMapper
.
queryDoctor
(
userId
);
result
.
setEntireFlag
(
doctor
.
getEntire_flag
());
result
.
setMobile
(
AESUtil
.
decryptV0
(
doctor
.
getMobile_phone
()));
}
}
//记录登录日志
// identifyToken校验
LogLoginEntity
entity
=
AccountLogEntityUtils
.
getLogLoginEntity
(
if
(!
checkIdentifyToken
(
request
)){
Integer
.
valueOf
(
String
.
valueOf
(
acctId
)),
throw
new
PicaException
(
request
.
getProductType
(),
request
.
getSourceType
(),
AccountExceptionEnum
.
PICA_APPLE_TOKEN_ERROR
.
getCode
(),
AccountTypeEnum
.
LOGIN_APPLE
.
getCode
(),
AccountExceptionEnum
.
PICA_APPLE_TOKEN_ERROR
.
getMessage
());
request
.
getLoginIp
(),
}
AccountTypeEnum
.
LOGIN_STATUS_SUCCESS
.
getCode
(),
// apple授权登录用户信息入库
AccountTypeEnum
.
LOG_TYPE_LOGIN
.
getCode
(),
newToken
,
1
,
request
.
getUserTokenTourist
());
AccountUnionEntity
accountUnion
=
accountUnionMapper
.
selectByUnionId
(
request
.
getAppleUserId
());
picaLogUtils
.
info
(
entity
);
//是否绑定逻辑的判断
if
(
accountUnion
!=
null
)
{
Long
acctId
=
accountUnion
.
getAcctId
();
Long
userId
=
accountUtils
.
getUserIdByAcctId
(
null
,
acctId
.
intValue
());
Account
account
=
new
Account
();
account
.
setId
(
userId
);
account
.
setAcctId
(
acctId
.
intValue
());
account
.
setCreatTime
(
new
Date
());
account
.
setMobilePhone
(
""
);
account
.
setRegisterSource
(
request
.
getSourceType
());
String
newToken
=
tokenUtils
.
generateToken
(
account
);
LoginResult
result
=
new
LoginResult
();
result
.
setToken
(
newToken
);
result
.
setUserId
(
userId
);
result
.
setBindFlag
(
AccountTypeEnum
.
BIND_STATUS_SUCCESS
.
getCode
()
+
""
);
result
.
setDoctorId
(
EncryptUtils
.
encryptContent
(
userId
+
""
,
EncryptConstants
.
ENCRYPT_TYPE_ID
));
if
(
request
.
getProductType
()
==
AccountTypeEnum
.
PRODUCT_TYPE_DOCTOR
.
getCode
())
{
PICAPDoctor
doctor
=
doctorInfoMapper
.
queryDoctor
(
userId
);
result
.
setEntireFlag
(
doctor
.
getEntire_flag
());
result
.
setMobile
(
AESUtil
.
decryptV0
(
doctor
.
getMobile_phone
()));
}
//记录登录日志
LogLoginEntity
entity
=
AccountLogEntityUtils
.
getLogLoginEntity
(
Integer
.
valueOf
(
String
.
valueOf
(
acctId
)),
request
.
getProductType
(),
request
.
getSourceType
(),
AccountTypeEnum
.
LOGIN_APPLE
.
getCode
(),
request
.
getLoginIp
(),
AccountTypeEnum
.
LOGIN_STATUS_SUCCESS
.
getCode
(),
AccountTypeEnum
.
LOG_TYPE_LOGIN
.
getCode
(),
newToken
,
1
,
request
.
getUserTokenTourist
());
picaLogUtils
.
info
(
entity
);
long
end1
=
System
.
currentTimeMillis
();
long
end1
=
System
.
currentTimeMillis
();
logger
.
info
(
"loginByApple1-duration {} millionSeconds"
,
(
end1
-
start
));
logger
.
info
(
"loginByApple1-duration {} millionSeconds"
,
(
end1
-
start
));
return
result
;
return
result
;
}
else
{
}
else
{
AccountAppleInfo
entity
=
accountAppleInfoMapper
.
selectByUserId
(
request
.
getAppleUserId
());
AccountAppleInfo
entity
=
accountAppleInfoMapper
.
selectByUserId
(
request
.
getAppleUserId
());
//如果apple信息表数据不存在,就把用户信息存储到apple信息表中。
//如果apple信息表数据不存在,就把用户信息存储到apple信息表中。
if
(
entity
==
null
)
{
if
(
entity
==
null
)
{
processAppleInfoUser
(
request
);
processAppleInfoUser
(
request
);
}
LoginResult
result
=
new
LoginResult
();
result
.
setUnionId
(
request
.
getAppleUserId
());
result
.
setBindFlag
(
AccountTypeEnum
.
BIND_STATUS_FAILURE
.
getCode
()
+
""
);
long
end1
=
System
.
currentTimeMillis
();
logger
.
info
(
"loginByApple2-duration {} millionSeconds"
,
(
end1
-
start
));
return
result
;
}
}
LoginResult
result
=
new
LoginResult
();
result
.
setUnionId
(
request
.
getAppleUserId
());
result
.
setBindFlag
(
AccountTypeEnum
.
BIND_STATUS_FAILURE
.
getCode
()
+
""
);
long
end1
=
System
.
currentTimeMillis
();
logger
.
info
(
"loginByApple2-duration {} millionSeconds"
,
(
end1
-
start
));
return
result
;
}
}
}
/**
/**
* @Description apple登录--identifyToken校验
* @Description apple登录--identifyToken校验
* @Author Chongwen.jiang
* @Author Chongwen.jiang
* @Date 2020/2/24 19:28
* @Date 2020/2/24 19:28
* @ModifyDate 2020/2/24 19:28
* @ModifyDate 2020/2/24 19:28
* @Params [identifyToekn]
* @Params [identifyToekn]
* @Return boolean false:未通过token校验,true:通过校验
* @Return boolean false:未通过token校验,true:通过校验
*/
*/
private
boolean
checkIdentifyToken
(
BaseRequest
request
)
{
private
boolean
checkIdentifyToken
(
BaseRequest
request
)
{
String
identifyToken
=
request
.
getIdentifyToken
();
String
identifyToken
=
request
.
getIdentifyToken
();
logger
.
info
(
"checkIdentifyToken-identifyToken:{}"
,
identifyToken
);
logger
.
info
(
"checkIdentifyToken-identifyToken:{}"
,
identifyToken
);
// 向苹果后台获取公钥参数
// 向苹果后台获取公钥参数
String
appleResp
=
null
;
String
appleResp
=
null
;
try
{
try
{
appleResp
=
HttpClientCloudUtils
.
getHttpExecute
(
Constants
.
APPLE_GET_PUBLIC_KEY_URL
);
appleResp
=
HttpClientCloudUtils
.
getHttpExecute
(
Constants
.
APPLE_GET_PUBLIC_KEY_URL
);
logger
.
info
(
"checkIdentifyToken-appleResp:{}"
,
appleResp
);
logger
.
info
(
"checkIdentifyToken-appleResp:{}"
,
appleResp
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
info
(
"checkIdentifyToken-get apple public key fail "
+
e
.
getMessage
());
logger
.
info
(
"checkIdentifyToken-get apple public key fail "
+
e
.
getMessage
());
throw
new
PicaException
(
"get apple public key fail Exception"
,
"get apple public key fail"
);
throw
new
PicaException
(
"get apple public key fail Exception"
,
"get apple public key fail"
);
}
}
JSONObject
appleRespJson
=
JSONObject
.
parseObject
(
appleResp
);
JSONObject
appleRespJson
=
JSONObject
.
parseObject
(
appleResp
);
String
keys
=
appleRespJson
.
getString
(
"keys"
);
String
keys
=
appleRespJson
.
getString
(
"keys"
);
JSONArray
keysArr
=
JSONObject
.
parseArray
(
keys
);
JSONArray
keysArr
=
JSONObject
.
parseArray
(
keys
);
if
(
identifyToken
.
split
(
"\\."
).
length
<
2
)
{
if
(
identifyToken
.
split
(
"\\."
).
length
<
2
)
{
throw
new
PicaException
(
"get identifyToken fail Exception"
,
"get identifyToken format Exception"
);
throw
new
PicaException
(
"get identifyToken fail Exception"
,
"get identifyToken format Exception"
);
}
}
JSONObject
useAppleAuth
=
new
JSONObject
();
JSONObject
useAppleAuth
=
new
JSONObject
();
String
inAuth
=
new
String
(
Base64
.
decodeBase64
(
identifyToken
.
split
(
"\\."
)[
0
]));
String
inAuth
=
new
String
(
Base64
.
decodeBase64
(
identifyToken
.
split
(
"\\."
)[
0
]));
String
inKid
=
JSONObject
.
parseObject
(
inAuth
).
get
(
"kid"
).
toString
();
String
inKid
=
JSONObject
.
parseObject
(
inAuth
).
get
(
"kid"
).
toString
();
for
(
Object
obj
:
keysArr
){
for
(
Object
obj
:
keysArr
){
JSONObject
appleAuth
=
JSONObject
.
parseObject
(
obj
.
toString
());
JSONObject
appleAuth
=
JSONObject
.
parseObject
(
obj
.
toString
());
if
(
inKid
.
equals
(
appleAuth
.
getString
(
"kid"
))){
if
(
inKid
.
equals
(
appleAuth
.
getString
(
"kid"
))){
useAppleAuth
=
appleAuth
;
useAppleAuth
=
appleAuth
;
logger
.
info
(
"checkIdentifyToken-jsonObject1:{}"
,
useAppleAuth
);
logger
.
info
(
"checkIdentifyToken-jsonObject1:{}"
,
useAppleAuth
);
break
;
break
;
}
}
}
}
// 通过jar生成publicKey
// 通过jar生成publicKey
PublicKey
publicKey
;
PublicKey
publicKey
;
try
{
try
{
Jwk
jwa
=
Jwk
.
fromValues
(
useAppleAuth
);
Jwk
jwa
=
Jwk
.
fromValues
(
useAppleAuth
);
publicKey
=
jwa
.
getPublicKey
();
publicKey
=
jwa
.
getPublicKey
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
info
(
"checkIdentifyToken-generate publicKey fail "
+
e
.
getMessage
());
logger
.
info
(
"checkIdentifyToken-generate publicKey fail "
+
e
.
getMessage
());
throw
new
PicaException
(
"checkIdentifyToken-generate publicKey fail"
,
"generate publicKey fail"
);
throw
new
PicaException
(
"checkIdentifyToken-generate publicKey fail"
,
"generate publicKey fail"
);
}
}
// 分割前台传过来的identifyToken(jwt格式的token)用base64解码使用
// 分割前台传过来的identifyToken(jwt格式的token)用base64解码使用
String
aud
;
String
aud
;
String
sub
;
String
sub
;
try
{
try
{
String
claim
=
new
String
(
Base64
.
decodeBase64
(
identifyToken
.
split
(
"\\."
)[
1
]));
String
claim
=
new
String
(
Base64
.
decodeBase64
(
identifyToken
.
split
(
"\\."
)[
1
]));
//logger.info("checkIdentifyToken-claim:{}", claim);
//logger.info("checkIdentifyToken-claim:{}", claim);
aud
=
JSONObject
.
parseObject
(
claim
).
get
(
"aud"
).
toString
();
aud
=
JSONObject
.
parseObject
(
claim
).
get
(
"aud"
).
toString
();
sub
=
JSONObject
.
parseObject
(
claim
).
get
(
"sub"
).
toString
();
sub
=
JSONObject
.
parseObject
(
claim
).
get
(
"sub"
).
toString
();
// appleUserId从token中解码取出后赋值
// appleUserId从token中解码取出后赋值
request
.
setAppleUserId
(
sub
);
request
.
setAppleUserId
(
sub
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
info
(
"checkIdentifyToken-token decode fail "
+
e
.
getMessage
());
logger
.
info
(
"checkIdentifyToken-token decode fail "
+
e
.
getMessage
());
throw
new
PicaException
(
"checkIdentifyToken-token decode fail Exception"
,
"token decode fail"
);
throw
new
PicaException
(
"checkIdentifyToken-token decode fail Exception"
,
"token decode fail"
);
}
return
this
.
verify
(
publicKey
,
identifyToken
,
aud
,
sub
,
request
);
}
/**
* @Description 验证苹果公钥
* @Author Chongwen.jiang
* @Date 2020/2/24 19:49
* @ModifyDate 2020/2/24 19:49
* @Params [key, jwt, audience, subject]
* @Return boolean
*/
private
boolean
verify
(
PublicKey
key
,
String
jwt
,
String
audience
,
String
subject
,
BaseRequest
request
)
{
JwtParser
jwtParser
=
Jwts
.
parser
().
setSigningKey
(
key
);
jwtParser
.
requireIssuer
(
Constants
.
APPLE_ISSUE_URL
);
jwtParser
.
requireAudience
(
audience
);
jwtParser
.
requireSubject
(
subject
);
try
{
logger
.
info
(
"checkIdentifyToken-apple-verify-starting"
);
Jws
<
Claims
>
claim
=
jwtParser
.
parseClaimsJws
(
jwt
);
logger
.
info
(
"acheckIdentifyToken-apple-verify-claim:{}"
,
JSON
.
toJSONString
(
claim
));
//logger.info("apple-verify-claim.getBody:{}", JSON.toJSONString(claim.getBody()));
if
(
claim
!=
null
&&
claim
.
getBody
().
containsKey
(
"auth_time"
))
{
request
.
setInfo
(
JSON
.
toJSONString
(
claim
.
getBody
()));
JSONObject
claimBody
=
JSONObject
.
parseObject
(
JSON
.
toJSONString
(
claim
.
getBody
()),
JSONObject
.
class
);
request
.
setAppleId
(
claimBody
.
getString
(
"email"
));
return
true
;
}
return
false
;
}
catch
(
ExpiredJwtException
e
)
{
logger
.
info
(
"checkIdentifyToken-apple token expired "
+
e
.
getMessage
());
throw
new
PicaException
(
"apple token expired Exception"
,
"apple token expired"
);
}
catch
(
Exception
e
)
{
logger
.
info
(
"checkIdentifyToken-apple token illegal "
+
e
.
getMessage
());
throw
new
PicaException
(
"apple token illegal Exception"
,
"apple token illegal"
);
}
}
}
return
this
.
verify
(
publicKey
,
identifyToken
,
aud
,
sub
,
request
);
}
/**
/**
* @Description 验证苹果公钥
* @Description apple用户信息入表
* @Author Chongwen.jiang
* @Author Chongwen.jiang
* @Date 2020/2/24 19:49
* @Date 2020/2/24 11:00
* @ModifyDate 2020/2/24 19:49
* @ModifyDate 2020/2/24 11:00
* @Params [key, jwt, audience, subject]
* @Params [request]
* @Return boolean
* @Return void
*/
*/
private
boolean
verify
(
PublicKey
key
,
String
jwt
,
String
audience
,
String
subject
,
BaseRequest
request
)
{
private
void
processAppleInfoUser
(
BaseRequest
request
)
{
JwtParser
jwtParser
=
Jwts
.
parser
().
setSigningKey
(
key
);
AccountAppleInfo
appleInfo
=
new
AccountAppleInfo
();
jwtParser
.
requireIssuer
(
Constants
.
APPLE_ISSUE_URL
);
appleInfo
.
setCreatedId
(
0
);
jwtParser
.
requireAudience
(
audience
);
appleInfo
.
setModifiedId
(
0
);
jwtParser
.
requireSubject
(
subject
);
appleInfo
.
setAppleUserId
(
request
.
getAppleUserId
());
try
{
appleInfo
.
setAppleId
(
request
.
getAppleId
());
logger
.
info
(
"checkIdentifyToken-apple-verify-starting"
);
appleInfo
.
setInfo
(
request
.
getInfo
());
Jws
<
Claims
>
claim
=
jwtParser
.
parseClaimsJws
(
jwt
);
accountAppleInfoMapper
.
insertSelective
(
appleInfo
);
logger
.
info
(
"acheckIdentifyToken-apple-verify-claim:{}"
,
JSON
.
toJSONString
(
claim
));
}
//logger.info("apple-verify-claim.getBody:{}", JSON.toJSONString(claim.getBody()));
if
(
claim
!=
null
&&
claim
.
getBody
().
containsKey
(
"auth_time"
))
{
/**
request
.
setInfo
(
JSON
.
toJSONString
(
claim
.
getBody
()));
* @Description 苹果登录绑定手机号
JSONObject
claimBody
=
JSONObject
.
parseObject
(
JSON
.
toJSONString
(
claim
.
getBody
()),
JSONObject
.
class
);
* @Author Chongwen.jiang
request
.
setAppleId
(
claimBody
.
getString
(
"email"
));
* @Date 2020/2/24 11:40
return
true
;
* @ModifyDate 2020/2/24 11:40
}
* @Params [request]
return
false
;
* @Return com.pica.cloud.account.account.server.entity.LoginResult
}
catch
(
ExpiredJwtException
e
)
{
*/
logger
.
info
(
"checkIdentifyToken-apple token expired "
+
e
.
getMessage
());
@Override
throw
new
PicaException
(
"apple token expired Exception"
,
"apple token expired"
);
public
LoginResult
loginByAppleStep
(
BaseRequest
request
)
{
}
catch
(
Exception
e
)
{
// 判断当前手机号是否注册过: 没有注册过,进行注册操操作, 注册过,直接登录;
logger
.
info
(
"checkIdentifyToken-apple token illegal "
+
e
.
getMessage
());
AccountInfoEntity
accountInfoDb
=
accountInfoDetailMapper
.
selectByMobile
(
AESUtil
.
encryptV0
(
request
.
getMobile
()));
throw
new
PicaException
(
"apple token illegal Exception"
,
"apple token illegal"
);
logger
.
info
(
"loginByAppleStep-account is null {}, request:{}"
,
accountInfoDb
==
null
,
JSON
.
toJSONString
(
request
));
LoginResult
result
;
if
(
accountInfoDb
==
null
)
{
// 验证码校验
accountUtils
.
checkRegisterMobilePhoneAndAuthCode
(
request
.
getMobile
(),
AccountTypeEnum
.
SYSCODE_TYPE_APPLE
.
getCode
()
+
""
,
request
.
getAuthCode
());
result
=
registerService
.
register
(
request
);
logger
.
info
(
"loginByAppleStep-register"
);
}
else
{
// 验证码校验
accountUtils
.
checkMobilePhoneAndAuthCode
(
request
.
getMobile
(),
AccountTypeEnum
.
SYSCODE_TYPE_APPLE
.
getCode
()
+
""
,
request
.
getAuthCode
());
result
=
processLogin
(
request
,
accountInfoDb
.
getId
(),
AccountTypeEnum
.
LOGIN_APPLE
.
getCode
());
logger
.
info
(
"loginByAppleStep-processLogin"
);
}
result
.
setMobile
(
request
.
getMobile
());
AccountInfoEntity
accountInfo
=
accountInfoDetailMapper
.
selectByMobile
(
AESUtil
.
encryptV0
(
request
.
getMobile
()));
Integer
acctId
=
accountInfo
.
getId
();
// insert account_apple_info表数据
logger
.
info
(
"loginByAppleStep-insert-account_apple_info-start"
);
processAccountUnionApple
(
acctId
,
request
.
getAppleUserId
());
logger
.
info
(
"loginByAppleStep-insert-account_apple_info-end"
);
return
result
;
}
}
}
/**
/**
* @Description apple用户信息入表
* @Description account_apple_info insert
* @Author Chongwen.jiang
* @Author Chongwen.jiang
* @Date 2020/2/24 11:00
* @Date 2020/2/24 11:34
* @ModifyDate 2020/2/24 11:00
* @ModifyDate 2020/2/24 11:34
* @Params [request]
* @Params [acctId, appleUserId]
* @Return void
* @Return void
*/
*/
private
void
processAppleInfoUser
(
BaseRequest
request
)
{
private
void
processAccountUnionApple
(
Integer
acctId
,
String
appleUserId
)
{
AccountAppleInfo
appleInfo
=
new
AccountAppleInfo
();
AccountUnionEntity
accountUnion
=
accountUnionMapper
.
selectByUnionId
(
appleUserId
);
appleInfo
.
setCreatedId
(
0
);
if
(
accountUnion
!=
null
)
{
appleInfo
.
setModifiedId
(
0
);
throw
new
PicaException
(
appleInfo
.
setAppleUserId
(
request
.
getAppleUserId
());
AccountExceptionEnum
.
PICA_APPLE_BIND_OTHER
.
getCode
(),
appleInfo
.
setAppleId
(
request
.
getAppleId
());
AccountExceptionEnum
.
PICA_APPLE_BIND_OTHER
.
getMessage
());
appleInfo
.
setInfo
(
request
.
getInfo
());
}
accountAppleInfoMapper
.
insertSelective
(
appleInfo
);
Map
<
String
,
Object
>
map
=
new
HashedMap
(
2
);
}
map
.
put
(
"acctId"
,
acctId
);
map
.
put
(
"unionType"
,
AccountTypeEnum
.
UNION_LOGIN_APPLE
.
getCode
());
/**
AccountUnionEntity
accountUnionEntityAccount
=
accountUnionMapper
.
selectByAcctId
(
map
);
* @Description 苹果登录绑定手机号
if
(
accountUnionEntityAccount
!=
null
)
{
* @Author Chongwen.jiang
throw
new
PicaException
(
* @Date 2020/2/24 11:40
AccountExceptionEnum
.
PICA_MOBILE_BIND_OTHER
.
getCode
(),
* @ModifyDate 2020/2/24 11:40
AccountExceptionEnum
.
PICA_MOBILE_BIND_OTHER
.
getMessage
());
* @Params [request]
}
* @Return com.pica.cloud.account.account.server.entity.LoginResult
AccountUnionEntity
accountUnionEntity
=
new
AccountUnionEntity
();
*/
accountUnionEntity
.
setAcctId
(
acctId
.
longValue
());
@Override
accountUnionEntity
.
setUnionId
(
appleUserId
);
public
LoginResult
loginByAppleStep
(
BaseRequest
request
)
{
accountUnionEntity
.
setCreatedId
(
acctId
);
// 判断当前手机号是否注册过: 没有注册过,进行注册操操作, 注册过,直接登录;
accountUnionEntity
.
setModifiedId
(
acctId
);
AccountInfoEntity
accountInfoDb
=
accountInfoDetailMapper
.
selectByMobile
(
AESUtil
.
encryptV0
(
request
.
getMobile
()));
accountUnionEntity
.
setUnionType
(
AccountTypeEnum
.
UNION_LOGIN_APPLE
.
getCode
());
logger
.
info
(
"loginByAppleStep-account is null {}, request:{}"
,
accountInfoDb
==
null
,
JSON
.
toJSONString
(
request
));
accountUnionMapper
.
insertSelective
(
accountUnionEntity
);
LoginResult
result
;
if
(
accountInfoDb
==
null
)
{
// 验证码校验
accountUtils
.
checkRegisterMobilePhoneAndAuthCode
(
request
.
getMobile
(),
AccountTypeEnum
.
SYSCODE_TYPE_APPLE
.
getCode
()
+
""
,
request
.
getAuthCode
());
result
=
registerService
.
register
(
request
);
logger
.
info
(
"loginByAppleStep-register"
);
}
else
{
// 验证码校验
accountUtils
.
checkMobilePhoneAndAuthCode
(
request
.
getMobile
(),
AccountTypeEnum
.
SYSCODE_TYPE_APPLE
.
getCode
()
+
""
,
request
.
getAuthCode
());
result
=
processLogin
(
request
,
accountInfoDb
.
getId
(),
AccountTypeEnum
.
LOGIN_APPLE
.
getCode
());
logger
.
info
(
"loginByAppleStep-processLogin"
);
}
}
result
.
setMobile
(
request
.
getMobile
());
AccountInfoEntity
accountInfo
=
accountInfoDetailMapper
.
selectByMobile
(
AESUtil
.
encryptV0
(
request
.
getMobile
()));
Integer
acctId
=
accountInfo
.
getId
();
// insert account_apple_info表数据
logger
.
info
(
"loginByAppleStep-insert-account_apple_info-start"
);
processAccountUnionApple
(
acctId
,
request
.
getAppleUserId
());
logger
.
info
(
"loginByAppleStep-insert-account_apple_info-end"
);
return
result
;
}
/**
* @Description account_apple_info insert
* @Author Chongwen.jiang
* @Date 2020/2/24 11:34
* @ModifyDate 2020/2/24 11:34
* @Params [acctId, appleUserId]
* @Return void
*/
private
void
processAccountUnionApple
(
Integer
acctId
,
String
appleUserId
)
{
AccountUnionEntity
accountUnion
=
accountUnionMapper
.
selectByUnionId
(
appleUserId
);
if
(
accountUnion
!=
null
)
{
throw
new
PicaException
(
AccountExceptionEnum
.
PICA_APPLE_BIND_OTHER
.
getCode
(),
AccountExceptionEnum
.
PICA_APPLE_BIND_OTHER
.
getMessage
());
}
Map
<
String
,
Object
>
map
=
new
HashedMap
(
2
);
map
.
put
(
"acctId"
,
acctId
);
map
.
put
(
"unionType"
,
AccountTypeEnum
.
UNION_LOGIN_APPLE
.
getCode
());
AccountUnionEntity
accountUnionEntityAccount
=
accountUnionMapper
.
selectByAcctId
(
map
);
if
(
accountUnionEntityAccount
!=
null
)
{
throw
new
PicaException
(
AccountExceptionEnum
.
PICA_MOBILE_BIND_OTHER
.
getCode
(),
AccountExceptionEnum
.
PICA_MOBILE_BIND_OTHER
.
getMessage
());
}
AccountUnionEntity
accountUnionEntity
=
new
AccountUnionEntity
();
accountUnionEntity
.
setAcctId
(
acctId
.
longValue
());
accountUnionEntity
.
setUnionId
(
appleUserId
);
accountUnionEntity
.
setCreatedId
(
acctId
);
accountUnionEntity
.
setModifiedId
(
acctId
);
accountUnionEntity
.
setUnionType
(
AccountTypeEnum
.
UNION_LOGIN_APPLE
.
getCode
());
accountUnionMapper
.
insertSelective
(
accountUnionEntity
);
}
}
}
写
预览
Markdown
格式
0%
请重试
or
附加一个文件
附加文件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录