emoji表情应用.

数据库修改:

1.utf8mb4的最低mysql版本支持版本为5.5.3+,若不是,请升级到较新版本。

2.修改database、table和column字符集。参考以下语句:

  ALTER DATABASE database_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;

  ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

  ALTER TABLE table_name CHANGE column_name VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

3.修改mysql配置文件my.cnf(windows为my.ini)

  my.cnf一般在etc/mysql/my.cnf位置。找到后请在以下三部分里添加如下内容:

  [client]

  default-character-set = utf8mb4

  [mysql]

  default-character-set = utf8mb4

  [mysqld]

  character-set-client-handshake = FALSE

  character-set-server = utf8mb4

  collation-server = utf8mb4_unicode_ci

  init_connect='SET NAMES utf8mb4'

4.重启 MySQL Server、检查字符集

  在mysql命令行中输入:SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%';

检查是否如下:

+--------------------------+--------------------+

| Variable_name            | Value              |

+--------------------------+--------------------+

| character_set_client    | utf8mb4            |

| character_set_connection | utf8mb4            |

| character_set_database  | utf8mb4            |

| character_set_filesystem | binary            |

| character_set_results    | utf8mb4            |

| character_set_server    | utf8mb4            |

| character_set_system    | utf8              |

| collation_connection    | utf8mb4_unicode_ci |

| collation_database      | utf8mb4_unicode_ci |

| collation_server        | utf8mb4_unicode_ci |

+--------------------------+--------------------+

 

5.如果你用的是java服务器,升级或确保你的mysql connector版本高于5.1.13,推荐使用5.1.34,否则仍然无法使用utf8mb4

 

6.检查你服务端的db配置文件:

 

jdbc.url=jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=utf8&autoReconnect=true&rewriteBatchedStatements=TRUE

 

资源下载:

 

 http://download.csdn.net/detail/wzy26816812/8535057

 工具类:

  1 /*  3 * 2015年3月18日:上午11:16:15
  4 * Keen
  5 *
  6 * jacks808@163.com
  7 *
  8 * 
  9 */
 10 package com.common.util;
 11 
 12 import java.util.HashMap;
 13 import java.util.Map;
 14 
 15 /**
 16 * emoji工具 <br>
 17 * 2015年3月18日:上午11:16:15
 18 * 
 19 * @author Keen | jacks808@163.com <br>
 20 */
 21 public final class EmojiUtils {
 22 
 23 private EmojiUtils() {
 24 }
 25 
 26 private static final Map<String, String> EMOJI_MAP = new HashMap<String, String>() {
 27 private static final long serialVersionUID = 1L;
 28 {
 29 put("0xD83D 0xDE04", "<img src='/smiles_01_01.png' />");
 30 put("0xD83D 0xDE0A", "<img src='/smiles_01_02.png' />");
 31 put("0xD83D 0xDE03", "<img src='/smiles_01_03.png' />");
 32 put("0x263A", "<img src='/smiles_01_04.png' />");
 33 put("0xD83D 0xDE09", "<img src='/smiles_01_05.png' />");
 34 put("0xD83D 0xDE0D", "<img src='/smiles_01_06.png' />");
 35 put("0xD83D 0xDE18", "<img src='/smiles_01_07.png' />");
 36 put("0xD83D 0xDE1A", "<img src='/smiles_01_08.png' />");
 37 put("0xD83D 0xDE33", "<img src='/smiles_01_09.png' />");
 38 put("0xD83D 0xDE0C", "<img src='/smiles_01_10.png' />");
 39 put("0xD83D 0xDE01", "<img src='/smiles_01_11.png' />");
 40 put("0xD83D 0xDE1C", "<img src='/smiles_02_01.png' />");
 41 put("0xD83D 0xDE1D", "<img src='/smiles_02_02.png' />");
 42 put("0xD83D 0xDE12", "<img src='/smiles_02_03.png' />");
 43 put("0xD83D 0xDE0F", "<img src='/smiles_02_04.png' />");
 44 put("0xD83D 0xDE13", "<img src='/smiles_02_05.png' />");
 45 put("0xD83D 0xDE14", "<img src='/smiles_02_06.png' />");
 46 put("0xD83D 0xDE1E", "<img src='/smiles_02_07.png' />");
 47 put("0xD83D 0xDE16", "<img src='/smiles_02_08.png' />");
 48 put("0xD83D 0xDE25", "<img src='/smiles_02_09.png' />");
 49 put("0xD83D 0xDE30", "<img src='/smiles_02_10.png' />");
 50 put("0xD83D 0xDE28", "<img src='/smiles_02_11.png' />");
 51 put("0xD83D 0xDE23", "<img src='/smiles_03_01.png' />");
 52 put("0xD83D 0xDE22", "<img src='/smiles_03_02.png' />");
 53 put("0xD83D 0xDE2D", "<img src='/smiles_03_03.png' />");
 54 put("0xD83D 0xDE02", "<img src='/smiles_03_04.png' />");
 55 put("0xD83D 0xDE32", "<img src='/smiles_03_05.png' />");
 56 put("0xD83D 0xDE31", "<img src='/smiles_03_06.png' />");
 57 put("0xD83D 0xDE20", "<img src='/smiles_03_07.png' />");
 58 put("0xD83D 0xDE21", "<img src='/smiles_03_08.png' />");
 59 put("0xD83D 0xDE2A", "<img src='/smiles_03_09.png' />");
 60 put("0xD83D 0xDE37", "<img src='/smiles_03_10.png' />");
 61 put("0xD83D 0xDC7F", "<img src='/smiles_03_11.png' />");
 62 put("0xD83D 0xDC7D", "<img src='/smiles_04_01.png' />");
 63 put("0xD83D 0xDC9B", "<img src='/smiles_04_02.png' />");
 64 put("0xD83D 0xDC99", "<img src='/smiles_04_03.png' />");
 65 put("0xD83D 0xDC9C", "<img src='/smiles_04_04.png' />");
 66 put("0xD83D 0xDC97", "<img src='/smiles_04_05.png' />");
 67 put("0xD83D 0xDC9A", "<img src='/smiles_04_06.png' />");
 68 put("0x2764", "<img src='/smiles_04_07.png' />");
 69 put("0xD83D 0xDC94", "<img src='/smiles_04_08.png' />");
 70 put("0xD83D 0xDC93", "<img src='/smiles_04_09.png' />");
 71 put("0xD83D 0xDC98", "<img src='/smiles_04_10.png' />");
 72 put("0x2728", "<img src='/smiles_04_11.png' />");
 73 put("0xD83C 0xDF1F", "<img src='/smiles_05_01.png' />");
 74 put("0xD83D 0xDCA2", "<img src='/smiles_05_02.png' />");
 75 put("0x2755", "<img src='/smiles_05_03.png' />");
 76 put("0x2754", "<img src='/smiles_05_04.png' />");
 77 put("0xD83D 0xDCA4", "<img src='/smiles_05_05.png' />");
 78 put("0xD83D 0xDCA8", "<img src='/smiles_05_06.png' />");
 79 put("0xD83D 0xDCA6", "<img src='/smiles_05_07.png' />");
 80 put("0xD83C 0xDFB6", "<img src='/smiles_05_08.png' />");
 81 put("0xD83C 0xDFB5", "<img src='/smiles_05_09.png' />");
 82 put("0xD83D 0xDD25", "<img src='/smiles_05_10.png' />");
 83 put("0xD83D 0xDCA9", "<img src='/smiles_05_11.png' />");
 84 put("0xD83D 0xDC4D", "<img src='/smiles_06_01.png' />");
 85 put("0xD83D 0xDC4E", "<img src='/smiles_06_02.png' />");
 86 put("0xD83D 0xDC4C", "<img src='/smiles_06_03.png' />");
 87 put("0xD83D 0xDC4A", "<img src='/smiles_06_04.png' />");
 88 put("0x270A", "<img src='/smiles_06_05.png' />");
 89 put("0x270C", "<img src='/smiles_06_06.png' />");
 90 put("0xD83D 0xDC4B", "<img src='/smiles_06_07.png' />");
 91 put("0x270B", "<img src='/smiles_06_08.png' />");
 92 put("0xD83D 0xDC50", "<img src='/smiles_06_09.png' />");
 93 put("0xD83D 0xDC46", "<img src='/smiles_06_10.png' />");
 94 put("0xD83D 0xDC47", "<img src='/smiles_06_11.png' />");
 95 put("0xD83D 0xDC49", "<img src='/smiles_07_01.png' />");
 96 put("0xD83D 0xDC48", "<img src='/smiles_07_02.png' />");
 97 put("0xD83D 0xDE4C", "<img src='/smiles_07_03.png' />");
 98 put("0xD83D 0xDE4F", "<img src='/smiles_07_04.png' />");
 99 put("0x261D", "<img src='/smiles_07_05.png' />");
100 put("0xD83D 0xDC4F", "<img src='/smiles_07_06.png' />");
101 put("0xD83D 0xDCAA", "<img src='/smiles_07_07.png' />");
102 put("0xD83D 0xDEB6", "<img src='/smiles_07_08.png' />");
103 put("0xD83C 0xDFC3", "<img src='/smiles_07_09.png' />");
104 put("0xD83D 0xDC6B", "<img src='/smiles_07_10.png' />");
105 put("0xD83D 0xDC83", "<img src='/smiles_07_11.png' />");
106 put("0xD83D 0xDC6F", "<img src='/smiles_08_01.png' />");
107 put("0xD83D 0xDE46", "<img src='/smiles_08_02.png' />");
108 put("0xD83D 0xDE45", "<img src='/smiles_08_03.png' />");
109 put("0xD83D 0xDC81", "<img src='/smiles_08_04.png' />");
110 put("0xD83D 0xDE47", "<img src='/smiles_08_05.png' />");
111 put("0xD83D 0xDC8F", "<img src='/smiles_08_06.png' />");
112 put("0xD83D 0xDC91", "<img src='/smiles_08_07.png' />");
113 put("0xD83D 0xDC86", "<img src='/smiles_08_08.png' />");
114 put("0xD83D 0xDC87", "<img src='/smiles_08_09.png' />");
115 put("0xD83D 0xDC85", "<img src='/smiles_08_10.png' />");
116 put("0xD83D 0xDC66", "<img src='/smiles_08_11.png' />");
117 put("0xD83D 0xDC67", "<img src='/smiles_09_01.png' />");
118 put("0xD83D 0xDC69", "<img src='/smiles_09_02.png' />");
119 put("0xD83D 0xDC68", "<img src='/smiles_09_03.png' />");
120 put("0xD83D 0xDC76", "<img src='/smiles_09_04.png' />");
121 put("0xD83D 0xDC75", "<img src='/smiles_09_05.png' />");
122 put("0xD83D 0xDC74", "<img src='/smiles_09_06.png' />");
123 put("0xD83D 0xDC71", "<img src='/smiles_09_07.png' />");
124 put("0xD83D 0xDC72", "<img src='/smiles_09_08.png' />");
125 put("0xD83D 0xDC73", "<img src='/smiles_09_09.png' />");
126 put("0xD83D 0xDC77", "<img src='/smiles_09_10.png' />");
127 put("0xD83D 0xDC6E", "<img src='/smiles_09_11.png' />");
128 put("0xD83D 0xDC7C", "<img src='/smiles_10_01.png' />");
129 put("0xD83D 0xDC78", "<img src='/smiles_10_02.png' />");
130 put("0xD83D 0xDC82", "<img src='/smiles_10_03.png' />");
131 put("0xD83D 0xDC80", "<img src='/smiles_10_04.png' />");
132 put("0xD83D 0xDC63", "<img src='/smiles_10_05.png' />");
133 put("0xD83D 0xDC8B", "<img src='/smiles_10_06.png' />");
134 put("0xD83D 0xDC44", "<img src='/smiles_10_07.png' />");
135 put("0xD83D 0xDC42", "<img src='/smiles_10_08.png' />");
136 put("0xD83D 0xDC40", "<img src='/smiles_10_09.png' />");
137 put("0xD83D 0xDC43", "<img src='/smiles_10_10.png' />");
138 put("0xD83C 0xDF8D", "<img src='/bells_01_01.png' />");
139 put("0xD83D 0xDC9D", "<img src='/bells_01_02.png' />");
140 put("0xD83C 0xDF8E", "<img src='/bells_01_03.png' />");
141 put("0xD83C 0xDF92", "<img src='/bells_01_04.png' />");
142 put("0xD83C 0xDF93", "<img src='/bells_01_05.png' />");
143 put("0xD83C 0xDF8F", "<img src='/bells_01_06.png' />");
144 put("0xD83C 0xDF86", "<img src='/bells_01_07.png' />");
145 put("0xD83C 0xDF87", "<img src='/bells_01_08.png' />");
146 put("0xD83C 0xDF90", "<img src='/bells_01_09.png' />");
147 put("0xD83C 0xDF91", "<img src='/bells_01_10.png' />");
148 put("0xD83C 0xDF83", "<img src='/bells_01_11.png' />");
149 put("0xD83D 0xDC7B", "<img src='/bells_02_01.png' />");
150 put("0xD83C 0xDF85", "<img src='/bells_02_02.png' />");
151 put("0xD83C 0xDF84", "<img src='/bells_02_03.png' />");
152 put("0xD83C 0xDF81", "<img src='/bells_02_04.png' />");
153 put("0xD83D 0xDD14", "<img src='/bells_02_05.png' />");
154 put("0xD83C 0xDF89", "<img src='/bells_02_06.png' />");
155 put("0xD83C 0xDF88", "<img src='/bells_02_07.png' />");
156 put("0xD83D 0xDCBF", "<img src='/bells_02_08.png' />");
157 put("0xD83D 0xDCC0", "<img src='/bells_02_09.png' />");
158 put("0xD83D 0xDCF7", "<img src='/bells_02_10.png' />");
159 put("0xD83C 0xDFA5", "<img src='/bells_02_11.png' />");
160 put("0xD83D 0xDCBB", "<img src='/bells_03_01.png' />");
161 put("0xD83D 0xDCFA", "<img src='/bells_03_02.png' />");
162 put("0xD83D 0xDCF1", "<img src='/bells_03_03.png' />");
163 put("0xD83D 0xDCE0", "<img src='/bells_03_04.png' />");
164 put("0x260E", "<img src='/bells_03_05.png' />");
165 put("0xD83D 0xDCBD", "<img src='/bells_03_06.png' />");
166 put("0xD83D 0xDCFC", "<img src='/bells_03_07.png' />");
167 put("0xD83D 0xDD0A", "<img src='/bells_03_08.png' />");
168 put("0xD83D 0xDCE2", "<img src='/bells_03_09.png' />");
169 put("0xD83D 0xDCE3", "<img src='/bells_03_10.png' />");
170 put("0xD83D 0xDCFB", "<img src='/bells_03_11.png' />");
171 put("0xD83D 0xDCE1", "<img src='/bells_04_01.png' />");
172 put("0x27BF", "<img src='/bells_04_02.png' />");
173 put("0xD83D 0xDD0D", "<img src='/bells_04_03.png' />");
174 put("0xD83D 0xDD13", "<img src='/bells_04_04.png' />");
175 put("0xD83D 0xDD12", "<img src='/bells_04_05.png' />");
176 put("0xD83D 0xDD11", "<img src='/bells_04_06.png' />");
177 put("0x2702", "<img src='/bells_04_07.png' />");
178 put("0xD83D 0xDD28", "<img src='/bells_04_08.png' />");
179 put("0xD83D 0xDCA1", "<img src='/bells_04_09.png' />");
180 put("0xD83D 0xDCF2", "<img src='/bells_04_10.png' />");
181 put("0xD83D 0xDCE9", "<img src='/bells_04_11.png' />");
182 put("0xD83D 0xDCEB", "<img src='/bells_05_01.png' />");
183 put("0xD83D 0xDCEE", "<img src='/bells_05_02.png' />");
184 put("0xD83D 0xDEC0", "<img src='/bells_05_03.png' />");
185 put("0xD83D 0xDEBD", "<img src='/bells_05_04.png' />");
186 put("0xD83D 0xDCBA", "<img src='/bells_05_05.png' />");
187 put("0xD83D 0xDCB0", "<img src='/bells_05_06.png' />");
188 put("0xD83D 0xDD31", "<img src='/bells_05_07.png' />");
189 put("0xD83D 0xDEAC", "<img src='/bells_05_08.png' />");
190 put("0xD83D 0xDCA3", "<img src='/bells_05_09.png' />");
191 put("0xD83D 0xDD2B", "<img src='/bells_05_10.png' />");
192 put("0xD83D 0xDC8A", "<img src='/bells_05_11.png' />");
193 put("0xD83D 0xDC89", "<img src='/bells_06_01.png' />");
194 put("0xD83C 0xDFC8", "<img src='/bells_06_02.png' />");
195 put("0xD83C 0xDFC0", "<img src='/bells_06_03.png' />");
196 put("0x26BD", "<img src='/bells_06_04.png' />");
197 put("0x26BE", "<img src='/bells_06_05.png' />");
198 put("0xD83C 0xDFBE", "<img src='/bells_06_06.png' />");
199 put("0x26F3", "<img src='/bells_06_07.png' />");
200 put("0xD83C 0xDFB1", "<img src='/bells_06_08.png' />");
201 put("0xD83C 0xDFCA", "<img src='/bells_06_09.png' />");
202 put("0xD83C 0xDFC4", "<img src='/bells_06_10.png' />");
203 put("0xD83C 0xDFBF", "<img src='/bells_06_11.png' />");
204 put("0x2660", "<img src='/bells_07_01.png' />");
205 put("0x2665", "<img src='/bells_07_02.png' />");
206 put("0x2663", "<img src='/bells_07_03.png' />");
207 put("0x2666", "<img src='/bells_07_04.png' />");
208 put("0xD83C 0xDFC6", "<img src='/bells_07_05.png' />");
209 put("0xD83D 0xDC7E", "<img src='/bells_07_06.png' />");
210 put("0xD83C 0xDFAF", "<img src='/bells_07_07.png' />");
211 put("0xD83C 0xDC04", "<img src='/bells_07_08.png' />");
212 put("0xD83C 0xDFAC", "<img src='/bells_07_09.png' />");
213 put("0xD83D 0xDCDD", "<img src='/bells_07_10.png' />");
214 put("0xD83D 0xDCD6", "<img src='/bells_07_11.png' />");
215 put("0xD83C 0xDFA8", "<img src='/bells_08_01.png' />");
216 put("0xD83C 0xDFA4", "<img src='/bells_08_02.png' />");
217 put("0xD83C 0xDFA7", "<img src='/bells_08_03.png' />");
218 put("0xD83C 0xDFBA", "<img src='/bells_08_04.png' />");
219 put("0xD83C 0xDFB7", "<img src='/bells_08_05.png' />");
220 put("0xD83C 0xDFB8", "<img src='/bells_08_06.png' />");
221 put("0x303D", "<img src='/bells_08_07.png' />");
222 put("0xD83D 0xDC5F", "<img src='/bells_08_08.png' />");
223 put("0xD83D 0xDC61", "<img src='/bells_08_09.png' />");
224 put("0xD83D 0xDC60", "<img src='/bells_08_10.png' />");
225 put("0xD83D 0xDC62", "<img src='/bells_08_11.png' />");
226 put("0xD83D 0xDC55", "<img src='/bells_09_01.png' />");
227 put("0xD83D 0xDC54", "<img src='/bells_09_02.png' />");
228 put("0xD83D 0xDC57", "<img src='/bells_09_03.png' />");
229 put("0xD83D 0xDC58", "<img src='/bells_09_04.png' />");
230 put("0xD83D 0xDC59", "<img src='/bells_09_05.png' />");
231 put("0xD83C 0xDF80", "<img src='/bells_09_06.png' />");
232 put("0xD83C 0xDFA9", "<img src='/bells_09_07.png' />");
233 put("0xD83D 0xDC51", "<img src='/bells_09_08.png' />");
234 put("0xD83D 0xDC52", "<img src='/bells_09_09.png' />");
235 put("0xD83C 0xDF02", "<img src='/bells_09_10.png' />");
236 put("0xD83D 0xDCBC", "<img src='/bells_09_11.png' />");
237 put("0xD83D 0xDC5C", "<img src='/bells_10_01.png' />");
238 put("0xD83D 0xDC84", "<img src='/bells_10_02.png' />");
239 put("0xD83D 0xDC8D", "<img src='/bells_10_03.png' />");
240 put("0xD83D 0xDC8E", "<img src='/bells_10_04.png' />");
241 put("0x2615", "<img src='/bells_10_05.png' />");
242 put("0xD83C 0xDF75", "<img src='/bells_10_06.png' />");
243 put("0xD83C 0xDF7A", "<img src='/bells_10_07.png' />");
244 put("0xD83C 0xDF7B", "<img src='/bells_10_08.png' />");
245 put("0xD83C 0xDF78", "<img src='/bells_10_09.png' />");
246 put("0xD83C 0xDF76", "<img src='/bells_10_10.png' />");
247 put("0xD83C 0xDF74", "<img src='/bells_10_11.png' />");
248 put("0xD83C 0xDF54", "<img src='/bells_11_01.png' />");
249 put("0xD83C 0xDF5F", "<img src='/bells_11_02.png' />");
250 put("0xD83C 0xDF5D", "<img src='/bells_11_03.png' />");
251 put("0xD83C 0xDF5B", "<img src='/bells_11_04.png' />");
252 put("0xD83C 0xDF71", "<img src='/bells_11_05.png' />");
253 put("0xD83C 0xDF63", "<img src='/bells_11_06.png' />");
254 put("0xD83C 0xDF59", "<img src='/bells_11_07.png' />");
255 put("0xD83C 0xDF58", "<img src='/bells_11_08.png' />");
256 put("0xD83C 0xDF5A", "<img src='/bells_11_09.png' />");
257 put("0xD83C 0xDF5C", "<img src='/bells_11_10.png' />");
258 put("0xD83C 0xDF72", "<img src='/bells_11_11.png' />");
259 put("0xD83C 0xDF5E", "<img src='/bells_12_01.png' />");
260 put("0xD83C 0xDF73", "<img src='/bells_12_02.png' />");
261 put("0xD83C 0xDF62", "<img src='/bells_12_03.png' />");
262 put("0xD83C 0xDF61", "<img src='/bells_12_04.png' />");
263 put("0xD83C 0xDF66", "<img src='/bells_12_05.png' />");
264 put("0xD83C 0xDF67", "<img src='/bells_12_06.png' />");
265 put("0xD83C 0xDF82", "<img src='/bells_12_07.png' />");
266 put("0xD83C 0xDF70", "<img src='/bells_12_08.png' />");
267 put("0xD83C 0xDF4E", "<img src='/bells_12_09.png' />");
268 put("0xD83C 0xDF4A", "<img src='/bells_12_10.png' />");
269 put("0xD83C 0xDF49", "<img src='/bells_12_11.png' />");
270 put("0xD83C 0xDF53", "<img src='/bells_13_01.png' />");
271 put("0xD83C 0xDF46", "<img src='/bells_13_02.png' />");
272 put("0xD83C 0xDF45", "<img src='/bells_13_03.png' />");
273 put("0x2600", "<img src='/flowers_01_01.png' />");
274 put("0x2614", "<img src='/flowers_01_02.png' />");
275 put("0x2601", "<img src='/flowers_01_03.png' />");
276 put("0x26C4", "<img src='/flowers_01_04.png' />");
277 put("0xD83C 0xDF19", "<img src='/flowers_01_05.png' />");
278 put("0x26A1", "<img src='/flowers_01_06.png' />");
279 put("0xD83C 0xDF00", "<img src='/flowers_01_07.png' />");
280 put("0xD83C 0xDF0A", "<img src='/flowers_01_08.png' />");
281 put("0xD83D 0xDC31", "<img src='/flowers_01_09.png' />");
282 put("0xD83D 0xDC36", "<img src='/flowers_01_10.png' />");
283 put("0xD83D 0xDC2D", "<img src='/flowers_01_11.png' />");
284 put("0xD83D 0xDC39", "<img src='/flowers_02_01.png' />");
285 put("0xD83D 0xDC30", "<img src='/flowers_02_02.png' />");
286 put("0xD83D 0xDC3A", "<img src='/flowers_02_03.png' />");
287 put("0xD83D 0xDC38", "<img src='/flowers_02_04.png' />");
288 put("0xD83D 0xDC2F", "<img src='/flowers_02_05.png' />");
289 put("0xD83D 0xDC28", "<img src='/flowers_02_06.png' />");
290 put("0xD83D 0xDC3B", "<img src='/flowers_02_07.png' />");
291 put("0xD83D 0xDC37", "<img src='/flowers_02_08.png' />");
292 put("0xD83D 0xDC2E", "<img src='/flowers_02_09.png' />");
293 put("0xD83D 0xDC17", "<img src='/flowers_02_10.png' />");
294 put("0xD83D 0xDC35", "<img src='/flowers_02_11.png' />");
295 put("0xD83D 0xDC12", "<img src='/flowers_03_01.png' />");
296 put("0xD83D 0xDC34", "<img src='/flowers_03_02.png' />");
297 put("0xD83D 0xDC0E", "<img src='/flowers_03_03.png' />");
298 put("0xD83D 0xDC2B", "<img src='/flowers_03_04.png' />");
299 put("0xD83D 0xDC11", "<img src='/flowers_03_05.png' />");
300 put("0xD83D 0xDC18", "<img src='/flowers_03_06.png' />");
301 put("0xD83D 0xDC0D", "<img src='/flowers_03_07.png' />");
302 put("0xD83D 0xDC26", "<img src='/flowers_03_08.png' />");
303 put("0xD83D 0xDC24", "<img src='/flowers_03_09.png' />");
304 put("0xD83D 0xDC14", "<img src='/flowers_03_10.png' />");
305 put("0xD83D 0xDC27", "<img src='/flowers_03_11.png' />");
306 put("0xD83D 0xDC1B", "<img src='/flowers_04_01.png' />");
307 put("0xD83D 0xDC19", "<img src='/flowers_04_02.png' />");
308 put("0xD83D 0xDC20", "<img src='/flowers_04_03.png' />");
309 put("0xD83D 0xDC1F", "<img src='/flowers_04_04.png' />");
310 put("0xD83D 0xDC33", "<img src='/flowers_04_05.png' />");
311 put("0xD83D 0xDC2C", "<img src='/flowers_04_06.png' />");
312 put("0xD83D 0xDC90", "<img src='/flowers_04_07.png' />");
313 put("0xD83C 0xDF38", "<img src='/flowers_04_08.png' />");
314 put("0xD83C 0xDF37", "<img src='/flowers_04_09.png' />");
315 put("0xD83C 0xDF40", "<img src='/flowers_04_10.png' />");
316 put("0xD83C 0xDF39", "<img src='/flowers_04_11.png' />");
317 put("0xD83C 0xDF3B", "<img src='/flowers_05_01.png' />");
318 put("0xD83C 0xDF3A", "<img src='/flowers_05_02.png' />");
319 put("0xD83C 0xDF41", "<img src='/flowers_05_03.png' />");
320 put("0xD83C 0xDF43", "<img src='/flowers_05_04.png' />");
321 put("0xD83C 0xDF42", "<img src='/flowers_05_05.png' />");
322 put("0xD83C 0xDF34", "<img src='/flowers_05_06.png' />");
323 put("0xD83C 0xDF35", "<img src='/flowers_05_07.png' />");
324 put("0xD83C 0xDF3E", "<img src='/flowers_05_08.png' />");
325 put("0xD83D 0xDC1A", "<img src='/flowers_05_09.png' />");
326 put("0x31 0x20E3 ", "<img src='/numbers_01_01.png' />");
327 put("0x32 0x20E3 ", "<img src='/numbers_01_02.png' />");
328 put("0x33 0x20E3 ", "<img src='/numbers_01_03.png' />");
329 put("0x34 0x20E3 ", "<img src='/numbers_01_04.png' />");
330 put("0x35 0x20E3 ", "<img src='/numbers_01_05.png' />");
331 put("0x36 0x20E3 ", "<img src='/numbers_01_06.png' />");
332 put("0x37 0x20E3 ", "<img src='/numbers_01_07.png' />");
333 put("0x38 0x20E3 ", "<img src='/numbers_01_08.png' />");
334 put("0x39 0x20E3 ", "<img src='/numbers_01_09.png' />");
335 put("0x30 0x20E3 ", "<img src='/numbers_01_10.png' />");
336 put("0x23 0x20E3 ", "<img src='/numbers_01_11.png' />");
337 put("0x2B06", "<img src='/numbers_02_01.png' />");
338 put("0x2B07", "<img src='/numbers_02_02.png' />");
339 put("0x2B05", "<img src='/numbers_02_03.png' />");
340 put("0x27A1", "<img src='/numbers_02_04.png' />");
341 put("0x2197", "<img src='/numbers_02_05.png' />");
342 put("0x2196", "<img src='/numbers_02_06.png' />");
343 put("0x2198", "<img src='/numbers_02_07.png' />");
344 put("0x2199", "<img src='/numbers_02_08.png' />");
345 put("0x25C0", "<img src='/numbers_02_09.png' />");
346 put("0x25B6", "<img src='/numbers_02_10.png' />");
347 put("0x23EA", "<img src='/numbers_02_11.png' />");
348 put("0x23E9", "<img src='/numbers_03_01.png' />");
349 put("0xD83C 0xDD97", "<img src='/numbers_03_02.png' />");
350 put("0xD83C 0xDD95", "<img src='/numbers_03_03.png' />");
351 put("0xD83D 0xDD1D", "<img src='/numbers_03_04.png' />");
352 put("0xD83C 0xDD99", "<img src='/numbers_03_05.png' />");
353 put("0xD83C 0xDD92", "<img src='/numbers_03_06.png' />");
354 put("0xD83C 0xDFA6", "<img src='/numbers_03_07.png' />");
355 put("0xD83C 0xDE01", "<img src='/numbers_03_08.png' />");
356 put("0xD83D 0xDCF6", "<img src='/numbers_03_09.png' />");
357 put("0xD83C 0xDE35", "<img src='/numbers_03_10.png' />");
358 put("0xD83C 0xDE33", "<img src='/numbers_03_11.png' />");
359 put("0xD83C 0xDE50", "<img src='/numbers_04_01.png' />");
360 put("0xD83C 0xDE39", "<img src='/numbers_04_02.png' />");
361 put("0xD83C 0xDE2F", "<img src='/numbers_04_03.png' />");
362 put("0xD83C 0xDE3A", "<img src='/numbers_04_04.png' />");
363 put("0xD83C 0xDE36", "<img src='/numbers_04_05.png' />");
364 put("0xD83C 0xDE1A", "<img src='/numbers_04_06.png' />");
365 put("0xD83C 0xDE37", "<img src='/numbers_04_07.png' />");
366 put("0xD83C 0xDE38", "<img src='/numbers_04_08.png' />");
367 put("0xD83C 0xDE02", "<img src='/numbers_04_09.png' />");
368 put("0xD83D 0xDEBB", "<img src='/numbers_04_10.png' />");
369 put("0xD83D 0xDEB9", "<img src='/numbers_04_11.png' />");
370 put("0xD83D 0xDEBA", "<img src='/numbers_05_01.png' />");
371 put("0xD83D 0xDEBC", "<img src='/numbers_05_02.png' />");
372 put("0xD83D 0xDEAD", "<img src='/numbers_05_03.png' />");
373 put("0xD83C 0xDD7F", "<img src='/numbers_05_04.png' />");
374 put("0x267F", "<img src='/numbers_05_05.png' />");
375 put("0xD83D 0xDE87", "<img src='/numbers_05_06.png' />");
376 put("0xD83D 0xDEBE", "<img src='/numbers_05_07.png' />");
377 put("0x3299", "<img src='/numbers_05_08.png' />");
378 put("0x3297", "<img src='/numbers_05_09.png' />");
379 put("0xD83D 0xDD1E", "<img src='/numbers_05_10.png' />");
380 put("0xD83C 0xDD94", "<img src='/numbers_05_11.png' />");
381 put("0x2733", "<img src='/numbers_06_01.png' />");
382 put("0x2734", "<img src='/numbers_06_02.png' />");
383 put("0xD83D 0xDC9F", "<img src='/numbers_06_03.png' />");
384 put("0xD83C 0xDD9A", "<img src='/numbers_06_04.png' />");
385 put("0xD83D 0xDCF3", "<img src='/numbers_06_05.png' />");
386 put("0xD83D 0xDCF4", "<img src='/numbers_06_06.png' />");
387 put("0xD83D 0xDCB9", "<img src='/numbers_06_07.png' />");
388 put("0xD83D 0xDCB1", "<img src='/numbers_06_08.png' />");
389 put("0x2648", "<img src='/numbers_06_09.png' />");
390 put("0x2649", "<img src='/numbers_06_10.png' />");
391 put("0x264A", "<img src='/numbers_06_11.png' />");
392 put("0x264B", "<img src='/numbers_07_01.png' />");
393 put("0x264C", "<img src='/numbers_07_02.png' />");
394 put("0x264D", "<img src='/numbers_07_03.png' />");
395 put("0x264E", "<img src='/numbers_07_04.png' />");
396 put("0x264F", "<img src='/numbers_07_05.png' />");
397 put("0x2650", "<img src='/numbers_07_06.png' />");
398 put("0x2651", "<img src='/numbers_07_07.png' />");
399 put("0x2652", "<img src='/numbers_07_08.png' />");
400 put("0x2653", "<img src='/numbers_07_09.png' />");
401 put("0x26CE", "<img src='/numbers_07_10.png' />");
402 put("0xD83D 0xDD2F", "<img src='/numbers_07_11.png' />");
403 put("0xD83C 0xDD70", "<img src='/numbers_08_01.png' />");
404 put("0xD83C 0xDD71", "<img src='/numbers_08_02.png' />");
405 put("0xD83C 0xDD8E", "<img src='/numbers_08_03.png' />");
406 put("0xD83C 0xDD7E", "<img src='/numbers_08_04.png' />");
407 put("0xD83D 0xDD32", "<img src='/numbers_08_05.png' />");
408 put("0xD83D 0xDD34", "<img src='/numbers_08_06.png' />");
409 put("0xD83D 0xDD33", "<img src='/numbers_08_07.png' />");
410 put("0xD83D 0xDD5B", "<img src='/numbers_08_08.png' />");
411 put("0xD83D 0xDD50", "<img src='/numbers_08_09.png' />");
412 put("0xD83D 0xDD51", "<img src='/numbers_08_10.png' />");
413 put("0xD83D 0xDD52", "<img src='/numbers_08_11.png' />");
414 put("0xD83D 0xDD53", "<img src='/numbers_09_01.png' />");
415 put("0xD83D 0xDD54", "<img src='/numbers_09_02.png' />");
416 put("0xD83D 0xDD55", "<img src='/numbers_09_03.png' />");
417 put("0xD83D 0xDD56", "<img src='/numbers_09_04.png' />");
418 put("0xD83D 0xDD57", "<img src='/numbers_09_05.png' />");
419 put("0xD83D 0xDD58", "<img src='/numbers_09_06.png' />");
420 put("0xD83D 0xDD59", "<img src='/numbers_09_07.png' />");
421 put("0xD83D 0xDD5A", "<img src='/numbers_09_08.png' />");
422 put("0x2B55", "<img src='/numbers_09_09.png' />");
423 put("0x274C", "<img src='/numbers_09_10.png' />");
424 put("0xA9 ", "<img src='/numbers_09_11.png' />");
425 put("0xAE ", "<img src='/numbers_10_01.png' />");
426 put("0x2122", "<img src='/numbers_10_02.png' />");
427 put("0xD83C 0xDFE0", "<img src='/cars_01_01.png' />");
428 put("0xD83C 0xDFEB", "<img src='/cars_01_02.png' />");
429 put("0xD83C 0xDFE2", "<img src='/cars_01_03.png' />");
430 put("0xD83C 0xDFE3", "<img src='/cars_01_04.png' />");
431 put("0xD83C 0xDFE5", "<img src='/cars_01_05.png' />");
432 put("0xD83C 0xDFE6", "<img src='/cars_01_06.png' />");
433 put("0xD83C 0xDFEA", "<img src='/cars_01_07.png' />");
434 put("0xD83C 0xDFE9", "<img src='/cars_01_08.png' />");
435 put("0xD83C 0xDFE8", "<img src='/cars_01_09.png' />");
436 put("0xD83D 0xDC92", "<img src='/cars_01_10.png' />");
437 put("0x26EA", "<img src='/cars_01_11.png' />");
438 put("0xD83C 0xDFEC", "<img src='/cars_02_01.png' />");
439 put("0xD83C 0xDF07", "<img src='/cars_02_02.png' />");
440 put("0xD83C 0xDF06", "<img src='/cars_02_03.png' />");
441 put("0xD83C 0xDFE7", "<img src='/cars_02_04.png' />");
442 put("0xD83C 0xDFEF", "<img src='/cars_02_05.png' />");
443 put("0xD83C 0xDFF0", "<img src='/cars_02_06.png' />");
444 put("0x26FA", "<img src='/cars_02_07.png' />");
445 put("0xD83C 0xDFED", "<img src='/cars_02_08.png' />");
446 put("0xD83D 0xDDFC", "<img src='/cars_02_09.png' />");
447 put("0xD83D 0xDDFB", "<img src='/cars_02_10.png' />");
448 put("0xD83C 0xDF04", "<img src='/cars_02_11.png' />");
449 put("0xD83C 0xDF05", "<img src='/cars_03_01.png' />");
450 put("0xD83C 0xDF03", "<img src='/cars_03_02.png' />");
451 put("0xD83D 0xDDFD", "<img src='/cars_03_03.png' />");
452 put("0xD83C 0xDF08", "<img src='/cars_03_04.png' />");
453 put("0xD83C 0xDFA1", "<img src='/cars_03_05.png' />");
454 put("0x26F2", "<img src='/cars_03_06.png' />");
455 put("0xD83C 0xDFA2", "<img src='/cars_03_07.png' />");
456 put("0xD83D 0xDEA2", "<img src='/cars_03_08.png' />");
457 put("0xD83D 0xDEA4", "<img src='/cars_03_09.png' />");
458 put("0x26F5", "<img src='/cars_03_10.png' />");
459 put("0x2708", "<img src='/cars_03_11.png' />");
460 put("0xD83D 0xDE80", "<img src='/cars_04_01.png' />");
461 put("0xD83D 0xDEB2", "<img src='/cars_04_02.png' />");
462 put("0xD83D 0xDE99", "<img src='/cars_04_03.png' />");
463 put("0xD83D 0xDE97", "<img src='/cars_04_04.png' />");
464 put("0xD83D 0xDE95", "<img src='/cars_04_05.png' />");
465 put("0xD83D 0xDE8C", "<img src='/cars_04_06.png' />");
466 put("0xD83D 0xDE93", "<img src='/cars_04_07.png' />");
467 put("0xD83D 0xDE92", "<img src='/cars_04_08.png' />");
468 put("0xD83D 0xDE91", "<img src='/cars_04_09.png' />");
469 put("0xD83D 0xDE9A", "<img src='/cars_04_10.png' />");
470 put("0xD83D 0xDE83", "<img src='/cars_04_11.png' />");
471 put("0xD83D 0xDE89", "<img src='/cars_05_01.png' />");
472 put("0xD83D 0xDE84", "<img src='/cars_05_02.png' />");
473 put("0xD83D 0xDE85", "<img src='/cars_05_03.png' />");
474 put("0xD83C 0xDFAB", "<img src='/cars_05_04.png' />");
475 put("0x26FD", "<img src='/cars_05_05.png' />");
476 put("0xD83D 0xDEA5", "<img src='/cars_05_06.png' />");
477 put("0x26A0", "<img src='/cars_05_07.png' />");
478 put("0xD83D 0xDEA7", "<img src='/cars_05_08.png' />");
479 put("0xD83D 0xDD30", "<img src='/cars_05_09.png' />");
480 put("0xD83C 0xDFB0", "<img src='/cars_05_10.png' />");
481 put("0xD83D 0xDE8F", "<img src='/cars_05_11.png' />");
482 put("0xD83D 0xDC88", "<img src='/cars_06_01.png' />");
483 put("0x2668", "<img src='/cars_06_02.png' />");
484 put("0xD83C 0xDFC1", "<img src='/cars_06_03.png' />");
485 put("0xD83C 0xDF8C", "<img src='/cars_06_04.png' />");
486 put("0xD83C 0xDDEF 0xD83C 0xDDF5", "<img src='/cars_06_05.png' />");
487 put("0xD83C 0xDDF0 0xD83C 0xDDF7", "<img src='/cars_06_06.png' />");
488 put("0xD83C 0xDDE8 0xD83C 0xDDF3", "<img src='/cars_06_07.png' />");
489 put("0xD83C 0xDDFA 0xD83C 0xDDF8", "<img src='/cars_06_08.png' />");
490 put("0xD83C 0xDDEB 0xD83C 0xDDF7", "<img src='/cars_06_09.png' />");
491 put("0xD83C 0xDDEA 0xD83C 0xDDF8", "<img src='/cars_06_10.png' />");
492 put("0xD83C 0xDDEE 0xD83C 0xDDF9", "<img src='/cars_06_11.png' />");
493 put("0xD83C 0xDDF7 0xD83C 0xDDFA", "<img src='/cars_07_01.png' />");
494 put("0xD83C 0xDDEC 0xD83C 0xDDE7", "<img src='/cars_07_02.png' />");
495 put("0xD83C 0xDDE9 0xD83C 0xDDEA", "<img src='/cars_07_03.png' />");
496 }
497 };
498 
499 /**
500 * 把UTF-16的emoji表情替换为前端显示的标签 <br>
501 * 2015年3月18日:上午11:17:13<br>
502 * 
503 * @param source
504 * @return
505 */
506 public static String repleaceEmoji(
507 String source) {
508 if (!containsEmoji(source)) {
509 return source;
510 }
511 StringBuilder result = new StringBuilder(source.length());
512 int length = source.length();
513 StringBuilder emojiCode = new StringBuilder();
514 for (int i = 0; i < length; i++) {
515 while (i < length && isEmojiCharacter(source.charAt(i))) {
516 emojiCode.append("0x");
517 emojiCode.append(Integer.toHexString(source.charAt(i)).toUpperCase());
518 emojiCode.append(" ");
519 String emojiUtf16 = emojiCode.toString().trim();
520 String imgTag = EMOJI_MAP.get(emojiUtf16);
521 if (imgTag != null) {
522 result.append(imgTag);
523 emojiCode = null;// helpful for gc
524 emojiCode = new StringBuilder();
525 }
526 i++;
527 }
528 if (i < length) {
529 result.append(source.charAt(i));
530 }
531 }
532 return result.toString();
533 }
534 
535 /**
536 * 过滤emoji或者其他非文字类型的字符
537 * 
538 * @param source
539 * @return
540 */
541 public static String filterEmoji(
542 String source) {
543 
544 if (!containsEmoji(source)) {
545 return source;
546 }
547 StringBuilder buf = new StringBuilder(source.length());
548 int len = source.length();
549 for (int i = 0; i < len; i++) {
550 if(isEmojiCharacter(source.charAt(i))) {
551 continue;
552 }
553 buf.append(source.charAt(i));
554 }
555 return buf.toString();
556 }
557 
558 /**
559 * 检测是否有emoji字符
560 * 
561 * @param source
562 * @return
563 */
564 public static boolean containsEmoji(
565 String source) {
566 if (source == null) {
567 return false;
568 }
569 int len = source.length();
570 for (int i = 0; i < len; i++) {
571 char codePoint = source.charAt(i);
572 if (isEmojiCharacter(codePoint)) {
573 return true;
574 }
575 }
576 return false;
577 }
578 
579 /**
580 * 判断该字符是否为emoji字符 <br>
581 * 2015年3月19日:上午10:04:39<br>
582 * <br>
583 * 
584 * @param codePoint
585 * @return
586 * <pre>
587 * </pre>
588 */
589 private static boolean isEmojiCharacter(
590 char codePoint) {
591 boolean isEmoji = 
592 !(
593 (codePoint == 0x0) || 
594 (codePoint == 0x9) || 
595 (codePoint == 0xA) || 
596 (codePoint == 0xD) || 
597 ((codePoint >= 0x20) && (codePoint <= 0xD7FF)) || 
598 ((codePoint >= 0xE000) && (codePoint <= 0xFFFD)) || 
599 ((codePoint >= 0x10000) && (codePoint <= 0x10FFFF))
600 );
601 return isEmoji;
602 }
603 
604 public static void main(
605 String[] args) {
606 System.out.println(EmojiUtils.repleaceEmoji("👽中国👽中国👽"));
607 System.out.println(EmojiUtils.repleaceEmoji("abc👽123👽中国👽"));
608 System.out.println(EmojiUtils.repleaceEmoji("中国👽"));
609 System.out.println(EmojiUtils.repleaceEmoji("☀☀☀"));
610 System.out.println(EmojiUtils.repleaceEmoji("123123"));
611 
612 System.out.println(EmojiUtils.filterEmoji("👽中国👽中国👽"));
613 System.out.println(EmojiUtils.filterEmoji("abc👽123👽中国👽"));
614 System.out.println(EmojiUtils.filterEmoji("中国👽"));
615 System.out.println(EmojiUtils.filterEmoji("☀☀☀"));
616 System.out.println(EmojiUtils.filterEmoji("123123"));
617 }
618 }

 

posted on 2015-03-26 12:43  beenoisy  阅读(1817)  评论(0编辑  收藏  举报

导航