CMPP下发WAPPUSH编码转换

来源:互联网 发布:红帽 linux 清理tmp 编辑:程序博客网 时间:2024/05/16 05:43

//短信WAPPUSH编码UNICODE转UTF-8
String WapPushUrl = "wap.test.com";
String WapPushDisplayText = "测试";
try {      
      //转UTF-8编码
      byte[] bWapPushUrl = WapPushUrl.getBytes("UTF-8");
      byte[] bWapPushDisplayText = WapPushDisplayText.getBytes("UTF-8");
      
      //固定格式WapPushHeader1,WapPushHeader2,WapPushIndicator,WapPushDisplayTextHeader,EndOfWapPush
      byte[] WapPushHeader1 = { 0x0B, 0x05, 0x04, 0x0B, (byte) 0x84,
        0x23, (byte) 0xF0, 0x00, 0x03, 0x03, 0x01, 0x01 };      
      byte[] WapPushHeader2 = { 0x29, 0x06, 0x06, 0x03, (byte) 0xAE,
        (byte) 0x81, (byte) 0xEA, (byte) 0x8D, (byte) 0xCA };      
      byte[] WapPushIndicator = { 0x02, 0x05, 0x6A, 0x00, 0x45,
        (byte) 0xC6, 0x0C, 0x03 };      
      byte[] WapPushDisplayTextHeader = {0x00, 0x01, 0x03};
      byte[] EndOfWapPush = { 0x00, 0x01, 0x01 };
      
      //WapPush消息內容填充顺序:
      //WapPushHeader1,WapPushHeader2,WapPushIndicator,
      //WapPushUrl,WapPushDisplayTextHeader,WapPushDisplayText,EndOfWapPush

      byte[] Content = new byte[12 + 9 + 8 + bWapPushUrl.length
        + 3 + bWapPushDisplayText.length + 3];

      int pos = 0;
      //填充WapPushHeader1
      System.arraycopy(WapPushHeader1, 0, Content, pos,
        WapPushHeader1.length);
      pos = WapPushHeader1.length;
      //填充WapPushHeader2
      System.arraycopy(WapPushHeader2, 0, Content, pos,
        WapPushHeader2.length);
      pos += WapPushHeader2.length;
      //填充WapPushIndicator
      System.arraycopy(WapPushIndicator, 0, Content, pos,
        WapPushIndicator.length);
      pos += WapPushIndicator.length;
      //填充WapPushUrl
      System.arraycopy(bWapPushUrl, 0, Content, pos,
        bWapPushUrl.length);
      pos += bWapPushUrl.length;
      //填充WapPushDisplayTextHeader
      System.arraycopy(WapPushDisplayTextHeader, 0, Content, pos,
        WapPushDisplayTextHeader.length);
      pos += WapPushDisplayTextHeader.length;
      //填充WapPushDisplayText
      System.arraycopy(bWapPushDisplayText, 0, Content, pos,
        bWapPushDisplayText.length);
      pos += bWapPushDisplayText.length;
      //填充EndOfWapPush
      System.arraycopy(EndOfWapPush, 0, Content, pos,
        EndOfWapPush.length);
} catch (Exception e) {
      e.printStackTrace();
}