Skip to content

Instantly share code, notes, and snippets.

@meigesir
Last active June 12, 2017 03:32
Show Gist options
  • Save meigesir/8558375 to your computer and use it in GitHub Desktop.
Save meigesir/8558375 to your computer and use it in GitHub Desktop.
微信中QQ表情web、wap页面展现,符号代码(如:/::) → 笑脸)转换为表情图片,目前支持微信5.1.0.6中QQ表情前五屏,只要在微信中输入文字代码[微笑]、/微笑,或符号代码/::) 都可以显示出表情,但是数据库是符号表情/::)
import java.util.Arrays;
import java.util.List;
public class WeixinQQFaceUtil {
private static final String WEIXIN_QQ_IMG_URL_PATH = "https://wx.qq.com/zh_CN/htmledition/images/qqface/{index}.png";//微信QQ表情符号代码转换为真正的表情图片路径(0~99)
private static final String IMG_FILL_PATH = "<img style=\"width:24px;height:24px;\" src=\"{IMG_PATH}\"/>";
public static final List<String> WEIXIN_QQ_FACE_LIST;//微信中的QQ表情符号代码
static{
// weixin_QQ_face(# - split char)
// 1 /::)#/::~#/::B#/::|#/:8-)#/::<#/::$#/::X#/::Z#/::'(#/::-|#/::@#/::P#/::D#/::O#/::(#/::+#/:--b#/::Q#/::T#
// 2 /:,@P#/:,@-D#/::d#/:,@o#/::g#/:|-)#/::!#/::L#/::>#/::,@#/:,@f#/::-S#/:?#/:,@x#/:,@@#/::8#/:,@!#/:!!!#/:xx#/:bye
// 3 /:wipe#/:dig#/:handclap#/:&-(#/:B-)#/:<@#/:@>#/::-O#/:>-|#/:P-(#/::'|#/:X-)#/::*#/:@x#/:8*#/:pd#/:<W>#/:beer#/:basketb#/:oo
// 4 /:coffee#/:eat#/:pig#/:rose#/:fade#/:showlove#/:heart#/:break#/:cake#/:li#/:bome#/:kn#/:footb#/:ladybug#/:shit#/:moon#/:sun#/:gift#/:hug#/:strong
// 5 /:weak#/:share#/:v#/:@)#/:jj#/:@@#/:bad#/:lvu#/:no#/:ok#/:love#/:<L>#/:jump#/:shake#/:<O>#/:circle#/:kotow#/:turn#/:skip#/:oY
String weixinQQFace = "/::)#/::~#/::B#/::|#/:8-)#/::<#/::$#/::X#/::Z#/::'(#/::-|#/::@#/::P#/::D#/::O#/::(#/::+#/:--b#/::Q#/::T#/:,@P#/:,@-D#/::d#/:,@o#/::g#/:|-)#/::!#/::L#/::>#/::,@#/:,@f#/::-S#/:?#/:,@x#/:,@@#/::8#/:,@!#/:!!!#/:xx#/:bye#/:wipe#/:dig#/:handclap#/:&-(#/:B-)#/:<@#/:@>#/::-O#/:>-|#/:P-(#/::'|#/:X-)#/::*#/:@x#/:8*#/:pd#/:<W>#/:beer#/:basketb#/:oo#/:coffee#/:eat#/:pig#/:rose#/:fade#/:showlove#/:heart#/:break#/:cake#/:li#/:bome#/:kn#/:footb#/:ladybug#/:shit#/:moon#/:sun#/:gift#/:hug#/:strong#/:weak#/:share#/:v#/:@)#/:jj#/:@@#/:bad#/:lvu#/:no#/:ok#/:love#/:<L>#/:jump#/:shake#/:<O>#/:circle#/:kotow#/:turn#/:skip#/:oY";
WEIXIN_QQ_FACE_LIST = Arrays.asList(weixinQQFace.split("#"));
}
/**
* 将 content 中 的 QQ表情符号代码转换为表情图片
* @param content
* @return
*/
public static String transQQFace(String content){
int length = WEIXIN_QQ_FACE_LIST.size();
for(int i = 0; i < length; i++){
String value = WEIXIN_QQ_FACE_LIST.get(i);
String img = IMG_FILL_PATH.replace("{IMG_PATH}", WEIXIN_QQ_IMG_URL_PATH);
content = content.replace(value, img.replace("{index}", String.valueOf(i)));
}
return content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment