1.修复微信应用登录时,昵称重复base64加密的问题
Showing
4 changed files
with
46 additions
and
20 deletions
| ... | @@ -94,4 +94,6 @@ public interface UserAppService { | ... | @@ -94,4 +94,6 @@ public interface UserAppService { |
| 94 | ResultInfo saveAppAndBindQq4Vis(VisUserQq resources); | 94 | ResultInfo saveAppAndBindQq4Vis(VisUserQq resources); |
| 95 | 95 | ||
| 96 | UserAppDTO findByMemberId(Long memberId); | 96 | UserAppDTO findByMemberId(Long memberId); |
| 97 | |||
| 98 | UserAppDTO createByManual(UserApp userApp); | ||
| 97 | } | 99 | } | ... | ... |
| ... | @@ -556,6 +556,15 @@ public class UserAppServiceImpl implements UserAppService { | ... | @@ -556,6 +556,15 @@ public class UserAppServiceImpl implements UserAppService { |
| 556 | return this.userAppMapper.toDto(userApp); | 556 | return this.userAppMapper.toDto(userApp); |
| 557 | } | 557 | } |
| 558 | 558 | ||
| 559 | @Override | ||
| 560 | @Transactional(rollbackFor = Exception.class) | ||
| 561 | public UserAppDTO createByManual(UserApp userApp) { | ||
| 562 | UserAppIdManual userAppIdManual = new UserAppIdManual(); | ||
| 563 | BeanUtils.copyProperties(userApp, userAppIdManual); | ||
| 564 | this.userAppRepository.saveByIdManual(userAppIdManual); | ||
| 565 | return this.userAppMapper.toDto(userApp); | ||
| 566 | } | ||
| 567 | |||
| 559 | 568 | ||
| 560 | @Override | 569 | @Override |
| 561 | @Transactional(rollbackFor = Exception.class) | 570 | @Transactional(rollbackFor = Exception.class) | ... | ... |
| ... | @@ -34,6 +34,7 @@ import com.topdraw.weixin.service.WeChatConstants; | ... | @@ -34,6 +34,7 @@ import com.topdraw.weixin.service.WeChatConstants; |
| 34 | import io.swagger.annotations.Api; | 34 | import io.swagger.annotations.Api; |
| 35 | import io.swagger.annotations.ApiOperation; | 35 | import io.swagger.annotations.ApiOperation; |
| 36 | import lombok.extern.slf4j.Slf4j; | 36 | import lombok.extern.slf4j.Slf4j; |
| 37 | import org.apache.commons.lang.math.RandomUtils; | ||
| 37 | import org.apache.commons.lang3.StringUtils; | 38 | import org.apache.commons.lang3.StringUtils; |
| 38 | import org.springframework.beans.factory.annotation.Autowired; | 39 | import org.springframework.beans.factory.annotation.Autowired; |
| 39 | import org.springframework.util.Assert; | 40 | import org.springframework.util.Assert; |
| ... | @@ -45,6 +46,7 @@ import org.springframework.web.bind.annotation.*; | ... | @@ -45,6 +46,7 @@ import org.springframework.web.bind.annotation.*; |
| 45 | import javax.naming.ConfigurationException; | 46 | import javax.naming.ConfigurationException; |
| 46 | import java.net.URLDecoder; | 47 | import java.net.URLDecoder; |
| 47 | import java.sql.Timestamp; | 48 | import java.sql.Timestamp; |
| 49 | import java.time.LocalDate; | ||
| 48 | import java.util.*; | 50 | import java.util.*; |
| 49 | 51 | ||
| 50 | @Api("账号处理") | 52 | @Api("账号处理") |
| ... | @@ -70,6 +72,7 @@ public class UserOperationController { | ... | @@ -70,6 +72,7 @@ public class UserOperationController { |
| 70 | private static final String UNSUBSCRIBE = "unsubscribe"; | 72 | private static final String UNSUBSCRIBE = "unsubscribe"; |
| 71 | private static final Integer SUBSCRIBE_STATUS = 1; | 73 | private static final Integer SUBSCRIBE_STATUS = 1; |
| 72 | 74 | ||
| 75 | private String secretKey = "f8681b9ce7c8fb6b"; | ||
| 73 | 76 | ||
| 74 | 77 | ||
| 75 | /******************************************************* APP ************************************/ | 78 | /******************************************************* APP ************************************/ |
| ... | @@ -151,14 +154,14 @@ public class UserOperationController { | ... | @@ -151,14 +154,14 @@ public class UserOperationController { |
| 151 | Integer type = resources.getType(); | 154 | Integer type = resources.getType(); |
| 152 | if (Objects.isNull(type)) { | 155 | if (Objects.isNull(type)) { |
| 153 | log.error("app注册,参数错误,appRegister# message ==>> 账号类型不得为空 "); | 156 | log.error("app注册,参数错误,appRegister# message ==>> 账号类型不得为空 "); |
| 154 | return ResultInfo.failure("app注册,参数错误,账号类型不得为空"); | 157 | return ResultInfo.failure("app注册失败,账号类型不得为空"); |
| 155 | } | 158 | } |
| 156 | 159 | ||
| 157 | String account = resources.getAccount(); | 160 | String account = resources.getAccount(); |
| 158 | if (StringUtils.isNotBlank(account)) { | 161 | if (StringUtils.isNotBlank(account)) { |
| 159 | if (Objects.isNull(resources.getAccountType())) { | 162 | if (Objects.isNull(resources.getAccountType())) { |
| 160 | log.error("app注册,参数错误,appRegister# message ==>> 第三方账号类型不得为空"); | 163 | log.error("app注册,参数错误,appRegister# message ==>> 第三方账号类型不得为空"); |
| 161 | return ResultInfo.failure("app注册,参数错误,第三方账号类型不得为空"); | 164 | return ResultInfo.failure("app注册失败,第三方账号类型不得为空"); |
| 162 | } | 165 | } |
| 163 | } | 166 | } |
| 164 | 167 | ||
| ... | @@ -167,23 +170,24 @@ public class UserOperationController { | ... | @@ -167,23 +170,24 @@ public class UserOperationController { |
| 167 | resources.setNickname(Base64Utils.encodeToString(username.getBytes())); | 170 | resources.setNickname(Base64Utils.encodeToString(username.getBytes())); |
| 168 | } | 171 | } |
| 169 | 172 | ||
| 170 | if (StringUtils.isNotBlank(resources.getPassword())) { | 173 | if (Objects.isNull(resources.getId())) { |
| 171 | String clientPassword = AESUtil.decrypt(resources.getPassword(), "f8681b9ce7c8fb6b"); | 174 | if (StringUtils.isNotBlank(resources.getPassword())) { |
| 172 | if (clientPassword == null || clientPassword.length() <= 16) { | 175 | String clientPassword = AESUtil.decrypt(resources.getPassword(), secretKey); |
| 173 | log.error("修改app账号密码失败,参数错误,密码格式不正确,[updateAppPasswordByOldPassword# clientPassword ==>> {}]", clientPassword); | 176 | if (clientPassword == null || clientPassword.length() <= 16) { |
| 174 | return ResultInfo.failure("密码必须包含大小写字母和数字的组合,不能使用特殊字符,长度在 8-25 之间"); | 177 | log.error("app注册异常,appRegister# message ==>> 密码格式不正确 | clientPassword ==>> {}", clientPassword); |
| 175 | } | 178 | return ResultInfo.failure("密码必须包含大小写字母和数字的组合,不能使用特殊字符,长度在 8-25 之间"); |
| 176 | String resultClientPassword = clientPassword.substring(16); | 179 | } |
| 180 | String resultClientPassword = clientPassword.substring(16); | ||
| 177 | 181 | ||
| 178 | if (!RegexUtil.appPasswordRegex(resultClientPassword)) { | 182 | if (!RegexUtil.appPasswordRegex(resultClientPassword)) { |
| 179 | log.error("app注册异常,appRegister# {} message ==>> 密码格式不正确", resultClientPassword); | 183 | log.error("app注册异常,appRegister# message ==>> 密码格式不正确 | password ==>> {}", resultClientPassword); |
| 180 | return ResultInfo.failure("密码必须包含大小写字母和数字的组合,不能使用特殊字符,长度在 8-25 之间"); | 184 | return ResultInfo.failure("密码必须包含大小写字母和数字的组合,不能使用特殊字符,长度在 8-25 之间"); |
| 185 | } | ||
| 186 | resources.setPassword(AESUtil.decodePassword(resources.getPassword())); | ||
| 181 | } | 187 | } |
| 182 | resources.setPassword(AESUtil.decodePassword(resources.getPassword())); | ||
| 183 | } | 188 | } |
| 184 | 189 | ||
| 185 | UserAppDTO userAppDTO = this.userOperationService.appRegister(resources); | 190 | return ResultInfo.success(this.userOperationService.appRegister(resources)); |
| 186 | return ResultInfo.success(userAppDTO); | ||
| 187 | } | 191 | } |
| 188 | 192 | ||
| 189 | @PostMapping(value = "/appBindThirdAccount") | 193 | @PostMapping(value = "/appBindThirdAccount") |
| ... | @@ -428,9 +432,13 @@ public class UserOperationController { | ... | @@ -428,9 +432,13 @@ public class UserOperationController { |
| 428 | 432 | ||
| 429 | String nickname = redisInfo.get("nickname").toString(); | 433 | String nickname = redisInfo.get("nickname").toString(); |
| 430 | if (StringUtils.isNotBlank(nickname)) { | 434 | if (StringUtils.isNotBlank(nickname)) { |
| 431 | String nicknameDecode = URLDecoder.decode(nickname, "UTF-8"); | 435 | boolean isBase64 = Base64Util.isBase64(nickname); |
| 432 | String nicknameEncode = Base64Util.encode(nicknameDecode); | 436 | if (isBase64) { |
| 433 | subscribeBean.setNickname(nicknameEncode); | 437 | subscribeBean.setNickname(nickname); |
| 438 | } else { | ||
| 439 | log.warn("关注时前端昵称为进行base64加密,subscribe# message =>> 采用默认昵称 | nickname ==>> {}", nickname); | ||
| 440 | subscribeBean.setNickname(Base64Util.encode("创造团用户")); | ||
| 441 | } | ||
| 434 | } | 442 | } |
| 435 | 443 | ||
| 436 | String headimgurl = redisInfo.get("headimgurl").toString(); | 444 | String headimgurl = redisInfo.get("headimgurl").toString(); | ... | ... |
| ... | @@ -136,9 +136,16 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -136,9 +136,16 @@ public class UserOperationServiceImpl implements UserOperationService { |
| 136 | // 先创建会员,缓存至redis | 136 | // 先创建会员,缓存至redis |
| 137 | MemberDTO memberDTO = this.createMember(MemberBuilder.build(MemberTypeConstant.app, resources.getHeadimgurl(), resources.getNickname(), 0)); | 137 | MemberDTO memberDTO = this.createMember(MemberBuilder.build(MemberTypeConstant.app, resources.getHeadimgurl(), resources.getNickname(), 0)); |
| 138 | if (Objects.nonNull(memberDTO.getId())) { | 138 | if (Objects.nonNull(memberDTO.getId())) { |
| 139 | UserApp userApp = UserAppBuilder.build(memberDTO.getId(), resources); | ||
| 139 | // 保存app账号 | 140 | // 保存app账号 |
| 140 | UserAppDTO _userAppDTO = this.userAppService.create(UserAppBuilder.build(memberDTO.getId(), resources)); | 141 | UserAppDTO _userAppDTO = null; |
| 141 | if (Objects.nonNull(_userAppDTO.getId()) && StringUtils.isNotBlank(resources.getAccount())) { | 142 | if (Objects.isNull(userApp.getId())) { |
| 143 | _userAppDTO = this.userAppService.create(userApp); | ||
| 144 | } else { | ||
| 145 | _userAppDTO = this.userAppService.createByManual(userApp); | ||
| 146 | } | ||
| 147 | |||
| 148 | if (Objects.nonNull(_userAppDTO.getId()) && Objects.nonNull(_userAppDTO.getId()) && StringUtils.isNotBlank(resources.getAccount())) { | ||
| 142 | UserAppBindDTO userAppBindDTO = this.userAppBindService.findFirstByAccount(resources.getAccount()); | 149 | UserAppBindDTO userAppBindDTO = this.userAppBindService.findFirstByAccount(resources.getAccount()); |
| 143 | if (Objects.isNull(userAppBindDTO.getId())) { | 150 | if (Objects.isNull(userAppBindDTO.getId())) { |
| 144 | // 保存绑定关系 | 151 | // 保存绑定关系 | ... | ... |
-
Please register or sign in to post a comment