|
|
|
@ -40,6 +40,7 @@ import com.elink.esua.epdc.jwt.JwtTokenUtils; |
|
|
|
import com.elink.esua.epdc.redis.AppUserRedis; |
|
|
|
import com.elink.esua.epdc.service.AppUserService; |
|
|
|
import com.elink.esua.epdc.utils.WxMaServiceUtils; |
|
|
|
import com.sun.org.apache.regexp.internal.RE; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import me.chanjar.weixin.common.error.WxErrorException; |
|
|
|
import me.chanjar.weixin.mp.api.WxMpService; |
|
|
|
@ -765,48 +766,120 @@ public class AppUserServiceImpl implements AppUserService { |
|
|
|
return userDto; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<EpdcAppAuthorizationDTO> completeUserInfo(TokenDto tokenDto, EpdcCompleteUserInfoFormDTO infoDto) { |
|
|
|
|
|
|
|
// 验证手机号
|
|
|
|
this.checkSmsCode(infoDto.getMobile(), infoDto.getSmsCode()); |
|
|
|
/** |
|
|
|
* 验证用户手机号和身份证号码 |
|
|
|
* |
|
|
|
* @param userId 用户id |
|
|
|
* @param mobile 手机号 |
|
|
|
* @param partyFlag 是否党员 |
|
|
|
* @param identityNo 身份证号码 |
|
|
|
* @return java.lang.String 用户认证状态 |
|
|
|
* @author work@yujt.net.cn |
|
|
|
* @date 2020/3/12 19:15 |
|
|
|
*/ |
|
|
|
private String checkMobileAndIdentityNo(String userId, String mobile, String partyFlag, String identityNo) { |
|
|
|
UserDTO userDto = new UserDTO(); |
|
|
|
userDto.setId(userId); |
|
|
|
userDto.setMobile(mobile); |
|
|
|
userDto.setIdentityNo(identityNo); |
|
|
|
userDto.setPartyFlag(partyFlag); |
|
|
|
// 验证用户手机号和身份证号是否被注册
|
|
|
|
Result<String> verifyResult = userFeignClient.verifyUserCompleteData(userDto); |
|
|
|
if (!verifyResult.success()) { |
|
|
|
throw new RenException(verifyResult.getMsg()); |
|
|
|
} |
|
|
|
return verifyResult.getData(); |
|
|
|
} |
|
|
|
|
|
|
|
String userId = tokenDto.getUserId(); |
|
|
|
Long gridId = getGridId(infoDto.getGridId(), tokenDto.getGridId(), userId); |
|
|
|
/** |
|
|
|
* 校验用身份证号码 |
|
|
|
* |
|
|
|
* @param identityNo 身份证号码 |
|
|
|
* @param partyFlag 是否党员,非党员身份证号码置空 |
|
|
|
* @return java.lang.String 身份证号码 |
|
|
|
* @author work@yujt.net.cn |
|
|
|
* @date 2020/3/12 19:16 |
|
|
|
*/ |
|
|
|
private String fixAndCheckIdentityNo(String identityNo, String partyFlag) { |
|
|
|
if (YesOrNoEnum.NO.value().equals(partyFlag)) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
// 党员提交,验证身份证号
|
|
|
|
identityNo = ModuleUtils.replaceIllegalCharacter(identityNo); |
|
|
|
if (StringUtils.isBlank(identityNo)) { |
|
|
|
throw new RenException("身份证号不能为空"); |
|
|
|
} |
|
|
|
String verification = IdentityNoUtils.IdentityNoVerification(identityNo); |
|
|
|
if (StringUtils.isNotBlank(verification)) { |
|
|
|
throw new RenException(verification); |
|
|
|
} |
|
|
|
return identityNo; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 组装用户数据,解析用户微信unionid、头像 |
|
|
|
* |
|
|
|
* @param userId 用户id |
|
|
|
* @param userState 用户认证状态 |
|
|
|
* @param infoDto 用户提交的表单数据 |
|
|
|
* @return EpdcCompleteAppUserDTO |
|
|
|
* @author work@yujt.net.cn |
|
|
|
* @date 2020/3/12 19:20 |
|
|
|
*/ |
|
|
|
private EpdcCompleteAppUserDTO packageUserCompleteInfo(String userId, String userState, EpdcCompleteUserInfoFormDTO infoDto) { |
|
|
|
UserDTO userDto = ConvertUtils.sourceToTarget(infoDto, UserDTO.class); |
|
|
|
userDto.setDeptId(gridId); |
|
|
|
userDto.setDeptId(infoDto.getGridId()); |
|
|
|
userDto.setId(userId); |
|
|
|
userDto.setRealName(ModuleUtils.replaceIllegalCharacter(infoDto.getRealName())); |
|
|
|
|
|
|
|
// 党员提交,验证身份证号
|
|
|
|
String identityNo = ModuleUtils.replaceIllegalCharacter(infoDto.getIdentityNo()); |
|
|
|
if (YesOrNoEnum.YES.value().equals(userDto.getPartyFlag())) { |
|
|
|
if (StringUtils.isBlank(identityNo)) { |
|
|
|
return new Result().error("身份证号不能为空"); |
|
|
|
String wxCode = infoDto.getWxCode(); |
|
|
|
String iv = infoDto.getIv(); |
|
|
|
String encryptedData = infoDto.getEncryptedData(); |
|
|
|
if (StringUtils.isNotBlank(wxCode) && StringUtils.isNotBlank(iv) && StringUtils.isNotBlank(encryptedData)) { |
|
|
|
WxMaUserInfo wxMaUserInfo = null; |
|
|
|
String decrypt = null; |
|
|
|
try { |
|
|
|
decrypt = WxMaCryptUtils.decrypt(this.getUserSessionKey(wxCode), encryptedData, iv); |
|
|
|
if (StringUtils.isNotBlank(decrypt)) { |
|
|
|
wxMaUserInfo = JSONObject.parseObject(decrypt, WxMaUserInfo.class); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("解析或组装用户微信信息失败,用户id:::::{},解密数据:::::{}", userId, decrypt); |
|
|
|
log.error(e.getMessage()); |
|
|
|
} |
|
|
|
String verification = IdentityNoUtils.IdentityNoVerification(identityNo); |
|
|
|
if (StringUtils.isNotBlank(verification)) { |
|
|
|
return new Result().error(verification); |
|
|
|
if (null == wxMaUserInfo || StringUtils.isBlank(wxMaUserInfo.getUnionId())) { |
|
|
|
throw new RenException("解析微信数据失败,请刷新后重试"); |
|
|
|
} |
|
|
|
userDto.setIdentityNo(identityNo); |
|
|
|
} |
|
|
|
|
|
|
|
// 验证用户提交的信息
|
|
|
|
Result<String> verifyResult = userFeignClient.verifyUserCompleteData(userDto); |
|
|
|
if (!verifyResult.success()) { |
|
|
|
return new Result().error(verifyResult.getMsg()); |
|
|
|
userDto.setWxUnionId(wxMaUserInfo.getUnionId()); |
|
|
|
userDto.setFaceImg(wxMaUserInfo.getAvatarUrl()); |
|
|
|
} |
|
|
|
String userState = verifyResult.getData(); |
|
|
|
userDto.setWxUnionId(this.getWxUnionId(infoDto.getWxCode(), infoDto.getIv(), infoDto.getEncryptedData(), userId)); |
|
|
|
|
|
|
|
UserGridRelationDTO userGrid = this.packageUserGridRelationInfo(gridId); |
|
|
|
EpdcCompleteAppUserDTO completeAppUserDto = ConvertUtils.sourceToTarget(userDto, EpdcCompleteAppUserDTO.class); |
|
|
|
completeAppUserDto = this.packageUserCompleteInfo(completeAppUserDto, userState); |
|
|
|
// 组装对象,准备保存用户信息
|
|
|
|
return this.packageUserCompleteInfo(completeAppUserDto, userState); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<EpdcAppAuthorizationDTO> completeUserInfo(TokenDto tokenDto, EpdcCompleteUserInfoFormDTO infoDto) { |
|
|
|
|
|
|
|
String userId = tokenDto.getUserId(); |
|
|
|
|
|
|
|
// 验证手机号、验证码
|
|
|
|
this.checkSmsCode(infoDto.getMobile(), infoDto.getSmsCode()); |
|
|
|
// 验证身份证号格式,身份证号码字符串校正
|
|
|
|
String identityNo = fixAndCheckIdentityNo(infoDto.getIdentityNo(), infoDto.getPartyFlag()); |
|
|
|
// 验证手机号身份证号是否已被注册,若未被注册,返回当前用户的状态
|
|
|
|
String userState = checkMobileAndIdentityNo(userId, infoDto.getMobile(), infoDto.getPartyFlag(), identityNo); |
|
|
|
|
|
|
|
Long gridId = getGridId(infoDto.getGridId(), tokenDto.getGridId(), userId); |
|
|
|
infoDto.setGridId(gridId); |
|
|
|
infoDto.setIdentityNo(identityNo); |
|
|
|
|
|
|
|
// 组装对象,准备保存用户信息与网格信息
|
|
|
|
EpdcAppUserCompleteInfoFormDTO dto = new EpdcAppUserCompleteInfoFormDTO(); |
|
|
|
dto.setCompleteAppUser(completeAppUserDto); |
|
|
|
dto.setUserGridRelation(userGrid); |
|
|
|
dto.setUserGridRelation(this.packageUserGridRelationInfo(gridId)); |
|
|
|
dto.setCompleteAppUser(this.packageUserCompleteInfo(userId, userState, infoDto)); |
|
|
|
|
|
|
|
Result<UserDTO> completeResult = userFeignClient.completeUserInfo(dto); |
|
|
|
if (!completeResult.success()) { |
|
|
|
@ -824,7 +897,7 @@ public class AppUserServiceImpl implements AppUserService { |
|
|
|
tokenDto.setNickname(user.getNickname()); |
|
|
|
tokenDto.setMobile(user.getMobile()); |
|
|
|
tokenDto.setPartyFlag(user.getPartyFlag()); |
|
|
|
EpdcAppAuthorizationDTO authorizationDto = this.packageEpdcAppAuthorization(tokenDto, userGrid.getGrid(), user.getState()); |
|
|
|
EpdcAppAuthorizationDTO authorizationDto = this.packageEpdcAppAuthorization(tokenDto, String.valueOf(gridId), user.getState()); |
|
|
|
|
|
|
|
// 更新社群用户党员标识并加入关联的所有网格党员群
|
|
|
|
if (YesOrNoEnum.YES.value().equals(user.getPartyFlag())) { |
|
|
|
@ -875,11 +948,8 @@ public class AppUserServiceImpl implements AppUserService { |
|
|
|
* @author work@yujt.net.cn |
|
|
|
* @date 2020/2/28 14:51 |
|
|
|
*/ |
|
|
|
@Deprecated |
|
|
|
private String getWxUnionId(String wxCode, String iv, String encryptedData, String userId) { |
|
|
|
if (StringUtils.isBlank(wxCode) || StringUtils.isBlank(iv) || StringUtils.isBlank(encryptedData)) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
String sessionKey = this.getUserSessionKey(wxCode); |
|
|
|
/** |
|
|
|
* 代码说明: |
|
|
|
* 本来使用{@link cn.binarywang.wx.miniapp.api.WxMaUserService#getUserInfo(String, String, String)}方法解析用户unionid |
|
|
|
@ -887,21 +957,7 @@ public class AppUserServiceImpl implements AppUserService { |
|
|
|
* 上述方法本质上是通过{@link WxMaCryptUtils}工具类解密微信用户数据,遂直接换用{@link WxMaCryptUtils#decrypt(String, String, String)}方法。 |
|
|
|
* 将解密得到的JSON字符串,用{@link JSONObject}组装为目标对象,添加异常捕获与日志输出 |
|
|
|
*/ |
|
|
|
WxMaUserInfo wxMaUserInfo = null; |
|
|
|
String decrypt = null; |
|
|
|
try { |
|
|
|
decrypt = WxMaCryptUtils.decrypt(sessionKey, encryptedData, iv); |
|
|
|
if (StringUtils.isNotBlank(decrypt)) { |
|
|
|
wxMaUserInfo = JSONObject.parseObject(decrypt, WxMaUserInfo.class); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("解析或组装用户{}的微信信息失败,解密数据:::::", userId, decrypt); |
|
|
|
log.error(e.getMessage()); |
|
|
|
} |
|
|
|
if (null == wxMaUserInfo || StringUtils.isBlank(wxMaUserInfo.getUnionId())) { |
|
|
|
throw new RenException("解析微信数据失败,请刷新后重试"); |
|
|
|
} |
|
|
|
return wxMaUserInfo.getUnionId(); |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
|