📄 wappushencoder.java
字号:
System.arraycopy(WapPushPUD, 0, bytMsg, i, nWapPushPUDLen);
i+=nWapPushPUDLen;
System.arraycopy(WapPushIndicator, 0, bytMsg, i, nPushIndicatorLen);
i+=nPushIndicatorLen;
System.arraycopy(bytURL, 0, bytMsg, i, nBytURLLen);
i+=nBytURLLen;
System.arraycopy(WapPushDisplayTextHeader, 0, bytMsg, i, nPushDisplayTextHeaderLen);
i+=nPushDisplayTextHeaderLen;
System.arraycopy(bytContent, 0, bytMsg, i, nBytContentLen);
i+=nBytContentLen;
System.arraycopy(EndOfWapPush, 0, bytMsg, i, nEndOfWapPushLen);
return bytMsg;
}
/**
* @param content
* @param url
* @return
* 包头a:
UDH: 06 05 04 0B 84 23 F0
PUD: 01 06 03 AE 8D C4
WapPushPUD,最后一位,长度控制,有没有,NOKIA SR618也可以接受,有也可以
*/
public byte[] format2(String content,String url){
byte[] WapPushUDH = new byte[]
{
0x06,0x05 ,0x04 ,0x0B ,(byte) 0x84 ,0x23 ,(byte) 0xF0
};
//第二部分
byte[] WapPushPUD = new byte[]
{
0x01 ,0x06 ,0x03 ,(byte) 0xAE ,(byte) 0x8D ,(byte) 0xC4
};
// *pszPos++ = 0x02;;
// *pszPos++ = 0x05; //-//WAPFORUM//DTD SI 1.0//EN
// *pszPos++ = 0x6A; //UTF-8
// *pszPos++ = 0x00; //字符串结束
// *pszPos++ = 0x45; //<si>
// *pszPos++ = 0xC6; //<indication
// *pszPos++ = 0x08; //<action=signal-high>
// *pszPos++ = 0x0C; //href="http://"
// *pszPos++ = 0x03; //字符串开始
//第三部分
byte[] WapPushIndicator = new byte[]
{
0x02, 0x05, 0x6A, 0x00, 0x45, (byte) 0xC6,0x08,0x0C, 0x03
};
//第四部分:URL去掉http://后的UTF8编码
//第五部分
// *pszPos++ = 0x00; //字符串结束
// *pszPos++ = 0x01; //>
// *pszPos++ = 0x03; //字符串开始
//
byte[] WapPushDisplayTextHeader = new byte[]
{
0x00, 0x01, 0x03
};
//第六部分:消息文字的UTF8编码
// //第七部分:
// *pszPos++ = 0x00; //字符串结束
// *pszPos++ = 0x01; //</indication>"
// *pszPos++ = 0x01; //</si>
byte[] EndOfWapPush = new byte[]
{
0x00, 0x01, 0x01
};
byte[] bytContent = null;
byte[] bytURL = null;
try {
// content=Utf8Util.getInstance().GBKToUtf8(content);
//
// bytContent = content.getBytes();
// bytURL = url.getBytes();
// content = new String(bytContent, "UTF-8");
// bytContent = content.getBytes("UTF-8");
String contentUTF8=Utf8Util.getInstance().GBKToUtf8(content);
String urlUTF8=Utf8Util.getInstance().GBKToUtf8(url);
// bytContent = contentUTF8.getBytes();
bytContent=this.chString2UTF8_byte(content);
// System.out.println(this.byteToHexStr(bytContent));
bytURL = urlUTF8.getBytes();
// System.out.println(this.byteToHexStr(bytURL));
}
catch(Exception ex) {
ex.printStackTrace();
}
int i=0;
int nWapPushUDHLen=WapPushUDH.length;
int nWapPushPUDLen=WapPushPUD.length;
int nPushIndicatorLen=WapPushIndicator.length;
int nBytURLLen=bytURL.length;
int nPushDisplayTextHeaderLen=WapPushDisplayTextHeader.length;
int nBytContentLen=bytContent.length;
int nEndOfWapPushLen=EndOfWapPush.length;
int bodyLen=nPushIndicatorLen+nBytURLLen+nPushDisplayTextHeaderLen+nBytContentLen+nEndOfWapPushLen;
int totalLen=nWapPushUDHLen+nWapPushPUDLen+bodyLen;
// 否则MOTO A768不能正常接收
WapPushPUD[nWapPushPUDLen-1]=(byte) (bodyLen/2+128);//没有的这行,NOKIA也可以成功的。 有这行也可以。
byte[] bytMsg = new byte[totalLen];
System.arraycopy(WapPushUDH, 0, bytMsg, i, nWapPushUDHLen);
i+=nWapPushUDHLen;
System.arraycopy(WapPushPUD, 0, bytMsg, i, nWapPushPUDLen);
i+=nWapPushPUDLen;
System.arraycopy(WapPushIndicator, 0, bytMsg, i, nPushIndicatorLen);
i+=nPushIndicatorLen;
System.arraycopy(bytURL, 0, bytMsg, i, nBytURLLen);
i+=nBytURLLen;
System.arraycopy(WapPushDisplayTextHeader, 0, bytMsg, i, nPushDisplayTextHeaderLen);
i+=nPushDisplayTextHeaderLen;
System.arraycopy(bytContent, 0, bytMsg, i, nBytContentLen);
i+=nBytContentLen;
System.arraycopy(EndOfWapPush, 0, bytMsg, i, nEndOfWapPushLen);
return bytMsg;
}
/**
* @param content
* @param url
* @return
* 包头b:
UDH: 0B 05 04 0B 84 23 F0 00 03 03 01 01
PUD: 29 06 06 03 AE 81 EA 8D CA
//WapPushPUD,最后一位,长度控制,有没有,NOKIA SR618也可以接受,有也可以。
*/
public byte[] format3(String content,String url){
// 第一条:
// 0B WAPPUSH头部的总长度,不包括本字节
// 05 IE=16bit port addressing
// 04 lenght of ports
// 0B84 dest. port
// 23F0 source port
// 00 表示是Concatenated Short Messages
// 03 udh头长度
// B3 reference number
// 02 02是指共有两条短信
// 01 01是指这是第一条
//
// 接除UDH外的部分
// ...
// 第二条:
// 0B WAPPUSH头部的总长度 ,不包括本字节
// 05040B8423F0 表示接下来是一个WAPPUSH 6字节
// 00 表示是Concatenated Short Messages
// 03 udh头长度
// B3 reference number
// 02 02是指共有两条短信
// 02 02是指这是第2条
//
// 接余下部分
byte[] WapPushUDH = new byte[]
{
// 0x0B ,0x05 ,0x04 ,0x0B ,(byte) 0x84 ,0x23 ,(byte) 0xF0 ,0x00 ,0xB3 ,0x03 ,0x01 ,0x01
0x0B ,0x05 ,0x04 ,0x0B ,(byte) 0x84 ,0x23 ,(byte) 0xF0 ,0x00 ,0x03 ,0x03 ,0x01 ,0x01
};
//第二部分
byte[] WapPushPUD = new byte[]
{
// 0xB3,0x06,0x01,0xAE
0x29 ,0x06 ,0x06 ,0x03 ,(byte) 0xAE ,(byte) 0x81 ,(byte) 0xEA ,(byte) 0x8D ,(byte) 0xCA
};
// *pszPos++ = 0x02;;
// *pszPos++ = 0x05; //-//WAPFORUM//DTD SI 1.0//EN
// *pszPos++ = 0x6A; //UTF-8
// *pszPos++ = 0x00; //字符串结束
// *pszPos++ = 0x45; //<si>
// *pszPos++ = 0xC6; //<indication
// *pszPos++ = 0x08; //<action=signal-high>
// *pszPos++ = 0x0C; //href="http://"
// *pszPos++ = 0x03; //字符串开始
//第三部分
byte[] WapPushIndicator = new byte[]
{
// 0x02, 0x05, 0x6A, 0x00, 0x45, (byte) 0xC6,0x0C, 0x03
0x02, 0x05, 0x6A, 0x00, 0x45, (byte) 0xC6,0x08,0x0C, 0x03
};
//第四部分:URL去掉http://后的UTF8编码
//第五部分
// *pszPos++ = 0x00; //字符串结束
// *pszPos++ = 0x01; //>
// *pszPos++ = 0x03; //字符串开始
//
byte[] WapPushDisplayTextHeader = new byte[]
{
0x00, 0x01, 0x03
};
//第六部分:消息文字的UTF8编码
// //第七部分:
// *pszPos++ = 0x00; //字符串结束
// *pszPos++ = 0x01; //</indication>"
// *pszPos++ = 0x01; //</si>
byte[] EndOfWapPush = new byte[]
{
0x00, 0x01, 0x01
};
byte[] bytContent = null;
byte[] bytURL = null;
try {
// content=Utf8Util.getInstance().GBKToUtf8(content);
//
// bytContent = content.getBytes();
// bytURL = url.getBytes();
// content = new String(bytContent, "UTF-8");
// bytContent = content.getBytes("UTF-8");
String contentUTF8=Utf8Util.getInstance().GBKToUtf8(content);
String urlUTF8=Utf8Util.getInstance().GBKToUtf8(url);
// bytContent = contentUTF8.getBytes();
bytContent=this.chString2UTF8_byte(content);
// System.out.println(this.byteToHexStr(bytContent));
bytURL = urlUTF8.getBytes();
// System.out.println(this.byteToHexStr(bytURL));
}
catch(Exception ex) {
ex.printStackTrace();
}
int i=0;
int nWapPushUDHLen=WapPushUDH.length;
int nWapPushPUDLen=WapPushPUD.length;
int nPushIndicatorLen=WapPushIndicator.length;
int nBytURLLen=bytURL.length;
int nPushDisplayTextHeaderLen=WapPushDisplayTextHeader.length;
int nBytContentLen=bytContent.length;
int nEndOfWapPushLen=EndOfWapPush.length;
int bodyLen=nPushIndicatorLen+nBytURLLen+nPushDisplayTextHeaderLen+nBytContentLen+nEndOfWapPushLen;
int totalLen=nWapPushUDHLen+nWapPushPUDLen+bodyLen;
// 否则MOTO A768不能正常接收
WapPushPUD[nWapPushPUDLen-1]=(byte) (bodyLen/2+128); //没有这行,NOKIA也可以接受,有也可以。
byte[] bytMsg = new byte[totalLen];
System.arraycopy(WapPushUDH, 0, bytMsg, i, nWapPushUDHLen);
i+=nWapPushUDHLen;
System.arraycopy(WapPushPUD, 0, bytMsg, i, nWapPushPUDLen);
i+=nWapPushPUDLen;
System.arraycopy(WapPushIndicator, 0, bytMsg, i, nPushIndicatorLen);
i+=nPushIndicatorLen;
System.arraycopy(bytURL, 0, bytMsg, i, nBytURLLen);
i+=nBytURLLen;
System.arraycopy(WapPushDisplayTextHeader, 0, bytMsg, i, nPushDisplayTextHeaderLen);
i+=nPushDisplayTextHeaderLen;
System.arraycopy(bytContent, 0, bytMsg, i, nBytContentLen);
i+=nBytContentLen;
System.arraycopy(EndOfWapPush, 0, bytMsg, i, nEndOfWapPushLen);
return bytMsg;
}
/**
* @param content
* @param url
* @return
* 有长度控制。WapPushPUD 最后一位
*/
public byte[] format6(String content,String url){
// $udh .= chr(0x06); //User Data Header Length (6 bytes)
// $udh .= chr(0x05); //$udh Item Element id (Port Numbers)
// $udh .= chr(0x04); //$udh IE length (4 bytes)
// $udh .= chr(0x0B);
// $udh .= chr(0x84); //destination port number
// $udh .= chr(0x23);
// $udh .= chr(0xF0); //origin port number
byte[] WapPushUDH = new byte[]
{
0x06,0x05 ,0x04 ,0x0B ,(byte) 0x84 ,0x23 ,(byte) 0xF0
};
// $pud .= chr(0x72); //transaction id (connectionless WSP)
// $pud .= chr(0x06); //'pdu type (06=push)
// $pud .= chr(0x0a); //Headers len
// $pud .= chr(0x03);
// $pud .= chr(0xAE);
// $pud .= chr(0x81);
// $pud .= chr(0xEA); //content type: application/vnd.wap.sic; charset=utf-8
// $pud .= chr(0xaf);
// $pud .= chr(0x82);
// $pud .= chr(0x8D); //content-length WBXML长度;
byte[] WapPushPUD = new byte[]
{
0x72 ,0x06 ,0x0a ,0x03 ,(byte) 0xAE ,(byte) 0x81,(byte) 0xEA,(byte) 0xaf,(byte) 0x82,(byte) 0x8D
};
// $body .= chr(0x80);
// $body .= chr(0xb4);
// $body .= chr(0x84);
// // Begin Pos
// $body .= chr(0x02);
// $body .= chr(0x05); //-//WAPFORUM//DTD SI 1.0//EN
// $body .= chr(0x6A); //UTF-8
// // $body .= chr(0x03); //字符串开始
// // $body .= iconv( "GBK", "UTF-8", $subject ); //显示给用户的内容,用utf-8编码。utf-8编码,英文字符直接用ascii码;中文如果unicode是(二进制)
// $body .= chr(0x00); //字符串结束
// $body .= chr(0x45); //<si>
// $body .= chr(0xC6); //<indication
// $body .= chr(0x0C); //href="http://
// $body .= chr(0x03); //字符串开始
byte[] WapPushIndicator = new byte[]
{
(byte) 0x80, (byte) 0xb4, (byte) 0x84, 0x02, 0x05, (byte) 0x6A,0x00,0x45, (byte) 0xC6,0x0C,0x03
};
//第四部分:URL去掉http://后的UTF8编码
// $body .= chr(0x00); //字符串结束
// $body .= chr(0x08); // action=signal-high
// $body .= chr(0x01); ; // END( of indication attribute list)
//
// $body .= chr(0x03); //字符串开始
//
byte[] WapPushDisplayTextHeader = new byte[]
{
0x00, 0x08,0x01, 0x03
};
//第六部分:消息文字的UTF8编码
// $body .= chr(0x00); //字符串结束
// $body .= chr(0x01); ; // END( of indication attribute list)
// $body .= chr(0x01); ; // END( of indication attribute list)
byte[] EndOfWapPush = new byte[]
{
0x00, 0x01, 0x01
};
byte[] bytContent = null;
byte[] bytURL = null;
try {
// content=Utf8Util.getInstance().GBKToUtf8(content);
//
// bytContent = content.getBytes();
// bytURL = url.getBytes();
// content = new String(bytContent, "UTF-8");
// bytContent = content.getBytes("UTF-8");
String contentUTF8=Utf8Util.getInstance().GBKToUtf8(content);
String urlUTF8=Utf8Util.getInstance().GBKToUtf8(url);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -