您好,欢迎访问一九零五行业门户网

微信开发Emoji表情的实例教程

一 什么是emoji  
emoji就是表情符号;词义来自日语(えもじ,e-moji,moji在日语中的含义是字符)
表情符号现已普遍应用于手机短信和网络聊天软件。
emoji表情符号,在外国的手机短信里面已经是很流行使用的一种表情。
在国内的微信和微信中也被采用。
emoji 全编码表:
punchdrunker.github.com/iosemoji/table_html/flower.html
code.iamcal.com/php/emoji/
<?php include('emoji.php'); # browser sniffing tells us that a docomo phone # submitted this text $clean_text = emoji_docomo_to_unified($_post[message]); ... # now we want to show it in a desktop browser $html = emoji_unified_to_html($clean_text);?>
回复代码如下所示:
<?php/* 方倍工作室 http://www.fangbei.org/ copyright 2015 all rights reserved*/define("token", "weixin");$wechatobj = new wechatcallbackapitest();if (!isset($_get['echostr'])) { $wechatobj->responsemsg(); }else{ $wechatobj->valid(); }class wechatcallbackapitest { //验证签名 public function valid() { $echostr = $_get["echostr"]; $signature = $_get["signature"]; $timestamp = $_get["timestamp"]; $nonce = $_get["nonce"]; $token = token; $tmparr = array($token, $timestamp, $nonce); sort($tmparr, sort_string); $tmpstr = implode($tmparr); $tmpstr = sha1($tmpstr); if($tmpstr == $signature){ header('content-type:text'); echo $echostr; exit; } } //响应消息 public function responsemsg() { $poststr = $globals["http_raw_post_data"]; if (!empty($poststr)){ $this->logger("r \r\n".$poststr); $postobj = simplexml_load_string($poststr, 'simplexmlelement', libxml_nocdata); $rx_type = trim($postobj->msgtype); //消息类型分离 switch ($rx_type) { case "event": $result = $this->receiveevent($postobj); break; case "text": $result = $this->receivetext($postobj); break; default: $result = "unknown msg type: ".$rx_type; break; } $this->logger("t \r\n".$result); echo $result; }else { echo ""; exit; } } //接收事件消息 private function receiveevent($object) { $content = ""; switch ($object->event) { case "subscribe": $content = "欢迎关注方倍工作室 "; break; case "unsubscribe": $content = "取消关注"; break; case "click": switch ($object->eventkey) { case "company": $content = array(); $content[] = array("title"=>"方倍工作室", "description"=>"", "picurl"=>"http://discuz.comli.com/weixin/weather/icon/cartoon.jpg", "url" =>"http://m.cnblogs.com/?u=txw1958"); break; default: $content = "点击菜单:".$object->eventkey; break; } break; default: $content = "receive a new event: ".$object->event; break; } if(is_array($content)){ if (isset($content[0]['picurl'])){ $result = $this->transmitnews($object, $content); }else if (isset($content['musicurl'])){ $result = $this->transmitmusic($object, $content); } }else{ $result = $this->transmittext($object, $content); } return $result; } //接收文本消息 private function receivetext($object) { $keyword = trim($object->content); //多客服人工回复模式 if (strstr($keyword, "请问在吗") || strstr($keyword, "在线客服")){ $result = $this->transmitservice($object); return $result; } //自动回复模式 if (strstr($keyword, "文本")){ $content = "这是个文本消息"; }else if (strstr($keyword, "表情")){ $content = "中国:".$this->bytes_to_emoji(0x1f1e8).$this->bytes_to_emoji(0x1f1f3)."\n仙人掌:".$this->bytes_to_emoji(0x1f335); }else if (strstr($keyword, "单图文")){ $content = array(); $content[] = array("title"=>"单图文标题", "description"=>"单图文内容", "picurl"=>"http://discuz.comli.com/weixin/weather/icon/cartoon.jpg", "url" =>"http://m.cnblogs.com/?u=txw1958"); }else if (strstr($keyword, "图文") || strstr($keyword, "多图文")){ $content = array(); $content[] = array("title"=>"多图文1标题", "description"=>"", "picurl"=>"http://discuz.comli.com/weixin/weather/icon/cartoon.jpg", "url" =>"http://m.cnblogs.com/?u=txw1958"); $content[] = array("title"=>"多图文2标题", "description"=>"", "picurl"=>"http://d.hiphotos.bdimg.com/wisegame/pic/item/f3529822720e0cf3ac9f1ada0846f21fbe09aaa3.jpg", "url" =>"http://m.cnblogs.com/?u=txw1958"); $content[] = array("title"=>"多图文3标题", "description"=>"", "picurl"=>"http://g.hiphotos.bdimg.com/wisegame/pic/item/18cb0a46f21fbe090d338acc6a600c338644adfd.jpg", "url" =>"http://m.cnblogs.com/?u=txw1958"); }else if (strstr($keyword, "音乐")){ $content = array(); $content = array("title"=>"最炫民族风", "description"=>"歌手:凤凰传奇", "musicurl"=>"http://121.199.4.61/music/zxmzf.mp3", "hqmusicurl"=>"http://121.199.4.61/music/zxmzf.mp3"); }else{ $content = date("y-m-d h:i:s",time())."\nopenid:".$object->fromusername."\n技术支持 方倍工作室"; // $content = ""; } if(is_array($content)){ if (isset($content[0])){ $result = $this->transmitnews($object, $content); }else if (isset($content['musicurl'])){ $result = $this->transmitmusic($object, $content); } }else{ $result = $this->transmittext($object, $content); } return $result; } //回复文本消息 private function transmittext($object, $content) { if (!isset($content) || empty($content)){ return ""; } $xmltpl = "<xml> <tousername><![cdata[%s]]></tousername> <fromusername><![cdata[%s]]></fromusername> <createtime>%s</createtime> <msgtype><![cdata[text]]></msgtype> <content><![cdata[%s]]></content> </xml>"; $result = sprintf($xmltpl, $object->fromusername, $object->tousername, time(), $content); return $result; } //回复图文消息 private function transmitnews($object, $newsarray) { if(!is_array($newsarray)){ return ""; } $itemtpl = " <item> <title><![cdata[%s]]></title> <description><![cdata[%s]]></description> <picurl><![cdata[%s]]></picurl> <url><![cdata[%s]]></url> </item>"; $item_str = ""; foreach ($newsarray as $item){ $item_str .= sprintf($itemtpl, $item['title'], $item['description'], $item['picurl'], $item['url']); } $xmltpl = "<xml> <tousername><![cdata[%s]]></tousername> <fromusername><![cdata[%s]]></fromusername> <createtime>%s</createtime> <msgtype><![cdata[news]]></msgtype> <articlecount>%s</articlecount> <articles>$item_str </articles> </xml>"; $result = sprintf($xmltpl, $object->fromusername, $object->tousername, time(), count($newsarray)); return $result; } //回复音乐消息 private function transmitmusic($object, $musicarray) { if(!is_array($musicarray)){ return ""; } $itemtpl = "<music> <title><![cdata[%s]]></title> <description><![cdata[%s]]></description> <musicurl><![cdata[%s]]></musicurl> <hqmusicurl><![cdata[%s]]></hqmusicurl> </music>"; $item_str = sprintf($itemtpl, $musicarray['title'], $musicarray['description'], $musicarray['musicurl'], $musicarray['hqmusicurl']); $xmltpl = "<xml> <tousername><![cdata[%s]]></tousername> <fromusername><![cdata[%s]]></fromusername> <createtime>%s</createtime> <msgtype><![cdata[music]]></msgtype> $item_str</xml>"; $result = sprintf($xmltpl, $object->fromusername, $object->tousername, time()); return $result; } //字节转emoji表情 function bytes_to_emoji($cp) { if ($cp > 0x10000){ # 4 bytes return chr(0xf0 | (($cp & 0x1c0000) >> 18)).chr(0x80 | (($cp & 0x3f000) >> 12)).chr(0x80 | (($cp & 0xfc0) >> 6)).chr(0x80 | ($cp & 0x3f)); }else if ($cp > 0x800){ # 3 bytes return chr(0xe0 | (($cp & 0xf000) >> 12)).chr(0x80 | (($cp & 0xfc0) >> 6)).chr(0x80 | ($cp & 0x3f)); }else if ($cp > 0x80){ # 2 bytes return chr(0xc0 | (($cp & 0x7c0) >> 6)).chr(0x80 | ($cp & 0x3f)); }else{ # 1 byte return chr($cp); } } //日志记录 private function logger($log_content) { if(isset($_server['http_appname'])){ //sae sae_set_display_errors(false); sae_debug($log_content); sae_set_display_errors(true); }else if($_server['remote_addr'] != "127.0.0.1"){ //local $max_size = 1000000; $log_filename = "log.xml"; if(file_exists($log_filename) and (abs(filesize($log_filename)) > $max_size)){unlink($log_filename);} file_put_contents($log_filename, date('y-m-d h:i:s')." ".$log_content."\r\n", file_append); } } }?>
【相关推荐】
 1. 特别推荐:“php程序员工具箱”v0.1版本下载
2. 微信公众号平台源码下载
3. 阿狸子订单系统源码下载
以上就是微信开发emoji表情的实例教程的详细内容。
其它类似信息

推荐信息