No public micro-channel micro-channel development nickname contains special characters

We are doing micro-channel development, there was a very important thing is to get through openid user details, including nickname, avatar, provinces, cities, districts, but now the mobile era, many people pursue individuality, widely used in the name of which Mars text or emoticons. This is to develop micro-letter caused some problems, we save will go to them mysql database error occurs after acquiring the nickname.

Solution:
Check out the nickname, nickname then encode, save them to the database after the coding is completed. The advantage of this is that no loss of detail, easy to operate, only need to encode the data line of code, the downside is navicat opened directly on the table when the nickname can not read, and use the nickname when we must remember to decoded.
String  nickname=userInfo.getAsJsonObject().get("nickname").getAsString();
try {
    //进行编码
    nickname =  Base64.encodeBase64String(nickname.getBytes("UTF-8"));
} catch (UnsupportedEncodingException  e) {
    e.printStackTrace ();
}
user.setNickname(nickname);
String nickname = (String) map.get("nickname");
try {
    //进行解码
    nickname = new  String(Base64.decodeBase64(nickname), "UTF-8");
} catch (UnsupportedEncodingException e) {
    e.printStackTrace ();
}
map.put("nickname", nickname);

 

Guess you like

Origin www.cnblogs.com/jiefu/p/11008970.html