@ -385,7 +385,10 @@ public class UserService implements IUserService {
* /
private UserVo . UserSign wxmplogin ( String code , String gameType ) throws Exception {
//0.获取openid
Long start = System . currentTimeMillis ( ) ;
WxXcxUtil . WechatUser wechatUser = WxXcxUtil . getUserInfo ( code , gameType ) ;
Long end = System . currentTimeMillis ( ) ;
log . info ( "调用微信查询openId耗时:{}" , end - start ) ;
String openId = wechatUser . openid ;
String unionId = wechatUser . unionid ;
log . info ( "小程序登录,openid:{} ,unionId:{}" , openId , unionId ) ;
@ -408,6 +411,7 @@ public class UserService implements IUserService {
* /
private UserVo . UserSign getUserSign ( String openId , String unionId ,
byte identifyType , String redirect ) {
long start = System . currentTimeMillis ( ) ;
UserVo . UserSign userSignVo ;
List < SysAuth > authList ;
SysAuth theAuth ;
@ -423,13 +427,17 @@ public class UserService implements IUserService {
SysAuthExample authExample = new SysAuthExample ( ) ;
authExample . createCriteria ( ) . andIdentifierEqualTo ( openId ) . andIdentifyTypeEqualTo ( identifyType ) ;
authList = authDao . selectByExample ( authExample ) ;
long end1 = System . currentTimeMillis ( ) ;
log . info ( "查auth表耗时:{}" , end1 - start ) ;
if ( CollectionUtil . isEmpty ( authList ) ) {
List < SysAuth > sysAuthList = null ;
long end2 = 0 ;
if ( ObjectUtil . isNotNull ( unionId ) & & identifyType = = WebConstant . IDENTIFY_TYPE . Wxmp . value ) {
SysAuthExample sysAuthExample = new SysAuthExample ( ) ;
sysAuthExample . createCriteria ( ) . andCredentialEqualTo ( unionId ) ;
sysAuthList = authDao . selectByExample ( sysAuthExample ) ;
end2 = System . currentTimeMillis ( ) ;
log . info ( "查找同平台其他登录方式耗时:{}" , end2 - end1 ) ;
}
if ( CollectionUtil . isNotEmpty ( sysAuthList ) ) {
//添加认证方式
@ -440,7 +448,8 @@ public class UserService implements IUserService {
theAuth . setIdentifier ( openId ) ;
theAuth . setCredential ( unionId ) ;
authDao . insertSelective ( theAuth ) ;
long end3 = System . currentTimeMillis ( ) ;
log . info ( "同平台有其他登录方式,添加小程序auth耗时:{}" , end3 - ( end2 = = 0 ? end1 : end2 ) ) ;
} else {
//新建用户并保存微信信息
SysUser user = new SysUser ( ) ;
@ -456,6 +465,8 @@ public class UserService implements IUserService {
theAuth . setIdentifier ( openId ) ;
theAuth . setCredential ( unionId ) ;
authDao . insertSelective ( theAuth ) ;
long end4 = System . currentTimeMillis ( ) ;
log . info ( "同平台没有其他登录方式,添加user和小程序auth耗时:{}" , end4 - ( end2 = = 0 ? end1 : end2 ) ) ;
// //自动添加账号密码
// String accountName = RandomStringUtils.random(8, WebConstant.RANDOM_STR);
// SysAuth accountAuth = new SysAuth();
@ -476,8 +487,11 @@ public class UserService implements IUserService {
userSignVo = new UserVo . UserSign ( ) ;
userSignVo . setUserId ( theAuth . getUserId ( ) ) ;
userSignVo . setAuthId ( theAuth . getId ( ) ) ;
//存入redis
redisUtil . set ( key , userSignVo , TallConstant . LOGIN_TIME ) ;
long end2 = System . currentTimeMillis ( ) ;
log . info ( "方法结束总耗时:{}" , end2 - end1 ) ;
return userSignVo ;
}