Menu

发送离线消息时中文乱码的解决办法

climber
2009-01-23
2013-04-29
  • climber

    climber - 2009-01-23

    修改 net.sf.jml.impl.BasicMessenger.sendText(Email, String)

    将:new OIM(session).sendOfflineMsg(email, text);
    改为:new OIM(session).sendOfflineMsg(email, new String(text.getBytes("UTF-8"), "GBK"));

     
    • luo dongri

      luo dongri - 2009-02-25

      考,你来个中文的。

       
    • lan zw

      lan zw - 2009-06-30

      我囧  ..回复也中文 ..

       
    • David Hung

      David Hung - 2009-07-09

      我是用繁體中文的,不管用下面何種方式。都還是遇到部份的字變成亂碼...
      new OIM(session).sendOfflineMsg(email, new String(text.getBytes("UTF-8")));
      new OIM(session).sendOfflineMsg(email, new String(text.getBytes("UTF-8"), "big5"));
      new OIM(session).sendOfflineMsg(email, new String(text.getBytes("UTF-8"), "GBK"));

      有人有解嗎? 不然就只好等Support離線訊息的正式版發行了 = =

       
      • ronaldo

        ronaldo - 2009-07-09

        In order to send unicode offline message, we can modify the method getOfflineMsg of the class 
        net.sf.jml.protocol.soap.OIM as follow.

        private String getOfflineMsg(Email email, String txt)
        {
            StringBuilder mess = new StringBuilder();
            String displayName=new String();
            try
            {
            displayName=new String(Base64.encode(session.getMessenger().getOwner().getDisplayName().getBytes("UTF-8")));
            txt=new String(Base64.encode(txt.getBytes("UTF-8")));
            }
            catch (UnsupportedEncodingException uee)
            {
                uee.printStackTrace();
            }
            mess.append("<?xml version=\&quot;1.0\&quot; encoding=\&quot;utf-8\&quot;?>\r\n");
            mess.append("<soap:Envelope xmlns:xsi=\&quot;http://www.w3.org/2001/XMLSchema-instance\&quot;\r\n xmlns:xsd=\&quot;http://www.w3.org/2001/XMLSchema\&quot;\r\n xmlns:soap=\&quot;http://schemas.xmlsoap.org/soap/envelope/\&quot; >");
            mess.append(" <soap:Header>");
            
            mess.append(" <From memberName=\&quot;" + session.getMessenger().getOwner().getEmail().getEmailAddress()
            + "\&quot; friendlyName=\&quot;=?utf-8?B?" + displayName + "?=\&quot;\r\n xml:lang=\&quot;nl-nl\&quot;\r\n proxy=\&quot;MSNMSGR\&quot;\r\n xmlns=\&quot;http://messenger.msn.com/ws/2004/09/oim/\&quot;\r\n msnpVer=\&quot;MSNP15\&quot;\r\n buildVer=\&quot;8.5.1288.816\&quot;/>");
            mess.append(" <To memberName=\&quot;"+ email.getEmailAddress() + "\&quot; xmlns=\&quot;http://messenger.msn.com/ws/2004/09/oim/\&quot;/>");
            mess.append(" <Ticket passport=\&quot;" + sso.getOimTicket().replaceAll("&", "&amp;") + "\&quot;\r\n appid=\&quot;PROD0119GSJUC$18\&quot;\r\n lockkey=\&quot;" + lockkey + "\&quot;\r\n xmlns=\&quot;http://messenger.msn.com/ws/2004/09/oim/\&quot;/>");
            mess.append(" <Sequence xmlns=\&quot;http://schemas.xmlsoap.org/ws/2003/03/rm\&quot;>\r\n");
            mess.append(" <Identifier xmlns=\&quot;http://schemas.xmlsoap.org/ws/2002/07/utility\&quot;>http://messenger.msn.com</Identifier>\r\n");
            mess.append(" <MessageNumber>" + sentMsgNumber + "</MessageNumber>\r\n");
            mess.append(" </Sequence>\r\n");
            mess.append(" </soap:Header>\r\n");
            mess.append(" <soap:Body>\r\n");
            mess.append(" <MessageType xmlns=\&quot;http://messenger.msn.com/ws/2004/09/oim/\&quot;>text</MessageType>\r\n");
            mess.append(" <Content xmlns=\&quot;http://messenger.msn.com/ws/2004/09/oim/\&quot;>MIME-Version: 1.0\r\n");
            mess.append("Content-Type: text/plain; charset=UTF-8\r\n");
            mess.append("Content-Transfer-Encoding: base64\r\n");
            mess.append("X-OIM-Message-Type: OfflineMessage\r\n");
            mess.append("X-OIM-Run-Id: {3A3BE82C-684D-4F4F-8005-CBE8D4F82BAD}\r\n");
            mess.append("X-OIM-Sequence-Num: " + sentMsgNumber + "\r\n\r\n");
            mess.append(" " + txt + "");
            mess.append(" </Content>");
            
            mess.append(" </soap:Body>");
            mess.append("</soap:Envelope>");
            
            return mess.toString();
        }

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.