1.app历史数据判断昵称是否base64加密过
Showing
2 changed files
with
70 additions
and
16 deletions
| ... | @@ -40,6 +40,7 @@ import org.springframework.transaction.annotation.Propagation; | ... | @@ -40,6 +40,7 @@ import org.springframework.transaction.annotation.Propagation; |
| 40 | import org.springframework.transaction.annotation.Transactional; | 40 | import org.springframework.transaction.annotation.Transactional; |
| 41 | import org.springframework.dao.EmptyResultDataAccessException; | 41 | import org.springframework.dao.EmptyResultDataAccessException; |
| 42 | import org.springframework.util.Assert; | 42 | import org.springframework.util.Assert; |
| 43 | import org.springframework.util.Base64Utils; | ||
| 43 | 44 | ||
| 44 | import java.sql.Timestamp; | 45 | import java.sql.Timestamp; |
| 45 | import java.util.Objects; | 46 | import java.util.Objects; |
| ... | @@ -217,11 +218,18 @@ public class UserAppServiceImpl implements UserAppService { | ... | @@ -217,11 +218,18 @@ public class UserAppServiceImpl implements UserAppService { |
| 217 | 218 | ||
| 218 | // vis 手机号 | 219 | // vis 手机号 |
| 219 | String cellphone = visUserDTO.getCellphone(); | 220 | String cellphone = visUserDTO.getCellphone(); |
| 220 | userAppIdManual.setUsername(StringUtils.isBlank(cellphone) ? null : cellphone); | 221 | userAppIdManual.setUsername(StringUtils.isBlank(cellphone) ? username : cellphone); |
| 221 | userAppIdManual.setCellphone(StringUtils.isBlank(cellphone) ? null : cellphone); | 222 | userAppIdManual.setCellphone(StringUtils.isBlank(cellphone) ? null : cellphone); |
| 222 | 223 | ||
| 223 | String nickname = visUserDTO.getNickname(); | 224 | if (StringUtils.isBlank(visUserDTO.getNickname())) { |
| 224 | userAppIdManual.setNickname(StringUtils.isBlank(nickname) ? resources.getNickname() : nickname); | 225 | userAppIdManual.setNickname(resources.getNickname()); |
| 226 | } else { | ||
| 227 | if(!Base64Util.isBase64(visUserDTO.getNickname())) { | ||
| 228 | userAppIdManual.setNickname(Base64Utils.encodeToString(visUserDTO.getNickname().getBytes())); | ||
| 229 | } else { | ||
| 230 | userAppIdManual.setNickname(visUserDTO.getNickname()); | ||
| 231 | } | ||
| 232 | } | ||
| 225 | 233 | ||
| 226 | Integer gender = visUserDTO.getGender(); | 234 | Integer gender = visUserDTO.getGender(); |
| 227 | userAppIdManual.setGender(Objects.isNull(gender) ? -1 : gender); | 235 | userAppIdManual.setGender(Objects.isNull(gender) ? -1 : gender); |
| ... | @@ -300,11 +308,18 @@ public class UserAppServiceImpl implements UserAppService { | ... | @@ -300,11 +308,18 @@ public class UserAppServiceImpl implements UserAppService { |
| 300 | userAppIdManual.setId(id); | 308 | userAppIdManual.setId(id); |
| 301 | 309 | ||
| 302 | String cellphone = visUserDTO.getCellphone(); | 310 | String cellphone = visUserDTO.getCellphone(); |
| 303 | userAppIdManual.setUsername(StringUtils.isBlank(cellphone) ? null : cellphone); | 311 | userAppIdManual.setUsername(StringUtils.isBlank(cellphone) ? username1 : cellphone); |
| 304 | userAppIdManual.setCellphone(StringUtils.isBlank(cellphone) ? null : cellphone); | 312 | userAppIdManual.setCellphone(StringUtils.isBlank(cellphone) ? null : cellphone); |
| 305 | 313 | ||
| 306 | String nickname = visUserDTO.getNickname(); | 314 | if (StringUtils.isBlank(visUserDTO.getNickname())) { |
| 307 | userAppIdManual.setNickname(StringUtils.isBlank(nickname) ? resources.getNickname() : nickname); | 315 | userAppIdManual.setNickname(resources.getNickname()); |
| 316 | } else { | ||
| 317 | if(!Base64Util.isBase64(visUserDTO.getNickname())) { | ||
| 318 | userAppIdManual.setNickname(Base64Utils.encodeToString(visUserDTO.getNickname().getBytes())); | ||
| 319 | } else { | ||
| 320 | userAppIdManual.setNickname(visUserDTO.getNickname()); | ||
| 321 | } | ||
| 322 | } | ||
| 308 | 323 | ||
| 309 | Integer gender = visUserDTO.getGender(); | 324 | Integer gender = visUserDTO.getGender(); |
| 310 | userAppIdManual.setGender(Objects.isNull(gender) ? -1 : gender); | 325 | userAppIdManual.setGender(Objects.isNull(gender) ? -1 : gender); |
| ... | @@ -329,7 +344,6 @@ public class UserAppServiceImpl implements UserAppService { | ... | @@ -329,7 +344,6 @@ public class UserAppServiceImpl implements UserAppService { |
| 329 | 344 | ||
| 330 | this.userAppRepository.saveByIdManual(userAppIdManual); | 345 | this.userAppRepository.saveByIdManual(userAppIdManual); |
| 331 | 346 | ||
| 332 | |||
| 333 | UserAppBindDTO userAppBindDTO = this.userAppBindService.findFirstByAccountAndAccountType(resources.getUserId(), 5); | 347 | UserAppBindDTO userAppBindDTO = this.userAppBindService.findFirstByAccountAndAccountType(resources.getUserId(), 5); |
| 334 | if (Objects.isNull(userAppBindDTO.getId())) { | 348 | if (Objects.isNull(userAppBindDTO.getId())) { |
| 335 | 349 | ||
| ... | @@ -385,11 +399,18 @@ public class UserAppServiceImpl implements UserAppService { | ... | @@ -385,11 +399,18 @@ public class UserAppServiceImpl implements UserAppService { |
| 385 | userAppIdManual.setId(id); | 399 | userAppIdManual.setId(id); |
| 386 | 400 | ||
| 387 | String cellphone = visUserDTO.getCellphone(); | 401 | String cellphone = visUserDTO.getCellphone(); |
| 388 | userAppIdManual.setUsername(StringUtils.isBlank(cellphone) ? null : cellphone); | 402 | userAppIdManual.setUsername(StringUtils.isBlank(cellphone) ? username1 : cellphone); |
| 389 | userAppIdManual.setCellphone(StringUtils.isBlank(cellphone) ? null : cellphone); | 403 | userAppIdManual.setCellphone(StringUtils.isBlank(cellphone) ? null : cellphone); |
| 390 | 404 | ||
| 391 | String nickname = visUserDTO.getNickname(); | 405 | if (StringUtils.isBlank(visUserDTO.getNickname())) { |
| 392 | userAppIdManual.setNickname(StringUtils.isBlank(nickname) ? resources.getNickname() : nickname); | 406 | userAppIdManual.setNickname(resources.getNickname()); |
| 407 | } else { | ||
| 408 | if(!Base64Util.isBase64(visUserDTO.getNickname())) { | ||
| 409 | userAppIdManual.setNickname(Base64Utils.encodeToString(visUserDTO.getNickname().getBytes())); | ||
| 410 | } else { | ||
| 411 | userAppIdManual.setNickname(visUserDTO.getNickname()); | ||
| 412 | } | ||
| 413 | } | ||
| 393 | 414 | ||
| 394 | Integer gender = visUserDTO.getGender(); | 415 | Integer gender = visUserDTO.getGender(); |
| 395 | userAppIdManual.setGender(Objects.isNull(gender) ? -1 : gender); | 416 | userAppIdManual.setGender(Objects.isNull(gender) ? -1 : gender); |
| ... | @@ -470,11 +491,18 @@ public class UserAppServiceImpl implements UserAppService { | ... | @@ -470,11 +491,18 @@ public class UserAppServiceImpl implements UserAppService { |
| 470 | userAppIdManual.setId(id); | 491 | userAppIdManual.setId(id); |
| 471 | 492 | ||
| 472 | String cellphone = visUserDTO.getCellphone(); | 493 | String cellphone = visUserDTO.getCellphone(); |
| 473 | userAppIdManual.setUsername(StringUtils.isBlank(cellphone) ? null : cellphone); | 494 | userAppIdManual.setUsername(StringUtils.isBlank(cellphone) ? username1 : cellphone); |
| 474 | userAppIdManual.setCellphone(StringUtils.isBlank(cellphone) ? null : cellphone); | 495 | userAppIdManual.setCellphone(StringUtils.isBlank(cellphone) ? null : cellphone); |
| 475 | 496 | ||
| 476 | String nickname = visUserDTO.getNickname(); | 497 | if (StringUtils.isBlank(visUserDTO.getNickname())) { |
| 477 | userAppIdManual.setNickname(StringUtils.isBlank(nickname) ? resources.getNickname() : nickname); | 498 | userAppIdManual.setNickname(resources.getNickname()); |
| 499 | } else { | ||
| 500 | if(!Base64Util.isBase64(visUserDTO.getNickname())) { | ||
| 501 | userAppIdManual.setNickname(Base64Utils.encodeToString(visUserDTO.getNickname().getBytes())); | ||
| 502 | } else { | ||
| 503 | userAppIdManual.setNickname(visUserDTO.getNickname()); | ||
| 504 | } | ||
| 505 | } | ||
| 478 | 506 | ||
| 479 | Integer gender = visUserDTO.getGender(); | 507 | Integer gender = visUserDTO.getGender(); |
| 480 | userAppIdManual.setGender(Objects.isNull(gender) ? -1 : gender); | 508 | userAppIdManual.setGender(Objects.isNull(gender) ? -1 : gender); | ... | ... |
| 1 | package com.topdraw.util; | 1 | package com.topdraw.util; |
| 2 | 2 | ||
| 3 | import org.apache.commons.lang3.StringUtils; | ||
| 4 | import org.springframework.util.Base64Utils; | ||
| 5 | |||
| 3 | import java.nio.charset.StandardCharsets; | 6 | import java.nio.charset.StandardCharsets; |
| 4 | import java.util.Base64; | 7 | import java.util.Base64; |
| 8 | import java.util.regex.Pattern; | ||
| 5 | 9 | ||
| 6 | public class Base64Util { | 10 | public class Base64Util { |
| 7 | 11 | ||
| ... | @@ -10,10 +14,32 @@ public class Base64Util { | ... | @@ -10,10 +14,32 @@ public class Base64Util { |
| 10 | return name1; | 14 | return name1; |
| 11 | } | 15 | } |
| 12 | 16 | ||
| 17 | |||
| 18 | |||
| 19 | public static boolean isBase64(String str) { | ||
| 20 | if (StringUtils.isBlank(str)) { | ||
| 21 | return false; | ||
| 22 | } | ||
| 23 | String base64Pattern = "^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$"; | ||
| 24 | boolean matches = Pattern.matches(base64Pattern, str); | ||
| 25 | if (matches) { | ||
| 26 | String decodeBase64Str = new String(Base64Utils.decode(str.getBytes())); | ||
| 27 | String encodeBase64Str = Base64Utils.encodeToString(decodeBase64Str.getBytes()); | ||
| 28 | if (str.equals(encodeBase64Str)) { | ||
| 29 | return true; | ||
| 30 | } | ||
| 31 | } | ||
| 32 | return false; | ||
| 33 | } | ||
| 34 | |||
| 35 | |||
| 36 | |||
| 13 | public static void main(String[] args) { | 37 | public static void main(String[] args) { |
| 14 | // String name = "test005@itv"; | 38 | // String name = "test005@itv"; |
| 15 | String name = "18580619168a@iptv"; | 39 | // String name = "18580619168a@iptv"; |
| 16 | String encode = encode(name); | 40 | // String encode = encode(name); |
| 17 | System.out.println(encode); | 41 | // System.out.println(encode); |
| 42 | boolean a = isBase64("fdsfdsf"); | ||
| 43 | System.out.println(a); | ||
| 18 | } | 44 | } |
| 19 | } | 45 | } | ... | ... |
-
Please register or sign in to post a comment