1.fix emoji nickName issue

main
Gary 7 months ago
parent 9bb0e0a171
commit ae3f472423

@ -48,6 +48,7 @@ import controller.BaseController;
import com.luoo.user.dto.UserInfoUpdateDto;
import com.luoo.user.dto.response.UserRespDTO;
import com.luoo.user.util.EmojiConverterUtil;
import com.luoo.user.util.IpUtil;
import annotation.GlobalInterceptor;
@ -141,7 +142,7 @@ public class MyController extends BaseController {
@VerifyParam(required = true) @RequestBody UserInfoUpdateDto userInfoUpdateDto) {
UserLoginDto userLoginDto = getUserLoginDto(authorization);
UserInfo user = userInfoService.findById(userLoginDto.getUserId());
String nickName = userInfoUpdateDto.getNickName();
String nickName = EmojiConverterUtil.encode(userInfoUpdateDto.getNickName());
String result = sensitiveWordBs.findFirst(nickName);
if (StringUtils.isNotEmpty(result)) {

@ -10,6 +10,7 @@ import javax.persistence.Id;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.luoo.user.util.EmojiConverterUtil;
import org.springframework.format.annotation.DateTimeFormat;
@ -39,6 +40,10 @@ public class UserInfo implements Serializable {
*/
private String nickName;
public String getNickName() {
return EmojiConverterUtil.decode(nickName);
}
/**
* apple id
*/
@ -169,4 +174,6 @@ public class UserInfo implements Serializable {
*
*/
private Integer enablePush;
}

@ -0,0 +1,60 @@
package com.luoo.user.util;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class EmojiConverterUtil {
private static final String encodePatternString = "([\\x{10000}-\\x{10ffff}\ud800-\udfff])";
private static final Pattern encodePattern = Pattern.compile(encodePatternString);
private static final String decodePatternString = "\\[\\[(.*?)\\]\\]";
private static final Pattern decodePattern = Pattern.compile(decodePatternString);
/**
* @Description emojiutf-84utf8mb4
* @param str
* @return
* @throws UnsupportedEncodingException exception
*/
public static String encode(String str) {
if (null == str) {
return null;
}
Matcher matcher = encodePattern.matcher(str);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
try {
matcher.appendReplacement(sb, "[[" + URLEncoder.encode(matcher.group(1), "UTF-8") + "]]");
} catch (UnsupportedEncodingException e) {
}
}
matcher.appendTail(sb);
return sb.toString();
}
/**
* @Description utf8emoji
* @param str
* @return exception
*/
public static String decode(String str) {
if (null == str) {
return null;
}
Matcher matcher = decodePattern.matcher(str);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
try {
matcher.appendReplacement(sb, URLDecoder.decode(matcher.group(1), "UTF-8"));
} catch (UnsupportedEncodingException e) {
}
}
matcher.appendTail(sb);
return sb.toString();
}
}
Loading…
Cancel
Save