一 什么是Emoji
emoji就是表情符号;词义来自日语(えもじ,e-moji,moji在日语中的含义是字符)<此段摘自百度百科 http://baike.baidu.com/view/2631589.htm>
二 Emoji表情符号问题ALTER TABLE topic MODIFY COLUMN content varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '内容';2 编码转换:
CREATE TABLE `ios_emoji` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增ID', `unicode` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Unicode编码', `utf8` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'UTF8编码', `utf16` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'UTF16编码', `sbunicode` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'SBUnicode编码', `filename` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '文件名', `filebyte` longblob COMMENT '文件内容字节', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='ios表情编码表';
import java.io.UnsupportedEncodingException; import org.apache.commons.lang.StringUtils; public class IOSEmojiUtil { public static String[] ios5emoji ; public static String[] ios4emoji ; public static String[] androidnullemoji ; public static String[] adsbuniemoji; public static void initios5emoji(String[] i5emj,String[] i4emj,String[] adnullemoji,String[] adsbemoji){ ios5emoji = i5emj; ios4emoji = i4emj; androidnullemoji = adnullemoji; adsbuniemoji = adsbemoji; } //在ios上将ios5转换为ios4编码 public static String transToIOS4emoji(String src) { return StringUtils.replaceEach(src, ios5emoji, ios4emoji); } //在ios上将ios4转换为ios5编码 public static String transToIOS5emoji(String src) { return StringUtils.replaceEach(src, ios4emoji, ios5emoji); } //在android上将ios5的表情符替换为空 public static String transToAndroidemojiNull(String src) { return StringUtils.replaceEach(src, ios5emoji, androidnullemoji); } //在android上将ios5的表情符替换为SBUNICODE public static String transToAndroidemojiSB(String src) { return StringUtils.replaceEach(src, ios5emoji, adsbuniemoji); } //在android上将SBUNICODE的表情符替换为ios5 public static String transSBToIOS5emoji(String src) { return StringUtils.replaceEach(src, adsbuniemoji, ios5emoji); } //eg. param: 0xF0 0x9F 0x8F 0x80 public static String hexstr2String(String hexstr) throws UnsupportedEncodingException{ byte[] b = hexstr2bytes(hexstr); return new String(b, "UTF-8"); } //eg. param: E018 public static String sbunicode2utfString(String sbhexstr) throws UnsupportedEncodingException{ byte[] b = sbunicode2utfbytes(sbhexstr); return new String(b, "UTF-8"); } //eg. param: 0xF0 0x9F 0x8F 0x80 public static byte[] hexstr2bytes(String hexstr){ String[] hexstrs = hexstr.split(" "); byte[] b = new byte[hexstrs.length]; for(int i=0;i<hexstrs.length;i++){ b[i] = hexStringToByte(hexstrs[i].substring(2))[0]; } return b; } //eg. param: E018 public static byte[] sbunicode2utfbytes(String sbhexstr) throws UnsupportedEncodingException{ int inthex = Integer.parseInt(sbhexstr, 16); char[] schar = {(char)inthex}; byte[] b = (new String(schar)).getBytes("UTF-8"); return b; } public static byte[] hexStringToByte(String hex) { int len = (hex.length() / 2); byte[] result = new byte[len]; char[] achar = hex.toCharArray(); for (int i = 0; i < len; i++) { int pos = i * 2; result[i] = (byte) (toByte(achar[pos]) << 4 | toByte(achar[pos + 1])); } return result; } private static byte toByte(char c) { byte b = (byte) "0123456789ABCDEF".indexOf(c); return b; } public static void main(String[] args) throws UnsupportedEncodingException { // TODO Auto-generated method stub byte[] b1 = {-30,-102,-67}; //ios5 //0xE2 0x9A 0xBD byte[] b2 = {-18,-128,-104}; //ios4 //"E018" //------------------------------------- byte[] b3 = {-16,-97,-113,-128}; //0xF0 0x9F 0x8F 0x80 byte[] b4 = {-18,-112,-86}; //E42A ios5emoji = new String[]{new String(b1,"utf-8"),new String(b3,"utf-8")}; ios4emoji = new String[]{new String(b2,"utf-8"),new String(b4,"utf-8")}; //测试字符串 byte[] testbytes = {105,111,115,-30,-102,-67,32,36,-18,-128,-104,32,36,-16,-97,-113,-128,32,36,-18,-112,-86}; String tmpstr = new String(testbytes,"utf-8"); System.out.println(tmpstr); //转成ios4的表情 String ios4str = transToIOS5emoji(tmpstr); byte[] tmp = ios4str.getBytes(); //System.out.print(new String(tmp,"utf-8")); for(byte b:tmp){ System.out.print(b); System.out.print(" "); } } }
七 下载资源
emoji图片和编码表 http://download.csdn.net/detail/qdkfriend/4309051
包括emoji文件表,emoji数据编码表(Unicode编码,UTF8编码,UTF16编码,SBUnicode编码)