📄 wappushencoder.java
字号:
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 totalLen=nWapPushUDHLen+nWapPushPUDLen+nPushIndicatorLen+nBytURLLen+nPushDisplayTextHeaderLen+nBytContentLen+nEndOfWapPushLen;
int bodyLen=nPushIndicatorLen+nBytURLLen+nPushDisplayTextHeaderLen+nBytContentLen+nEndOfWapPushLen;
int totalLen=nWapPushUDHLen+nWapPushPUDLen+bodyLen;
// 否则MOTO A768不能正常接收
WapPushPUD[nWapPushPUDLen-1]=(byte) (bodyLen/2+128);
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
*/
public byte[] format9(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 ,(byte) 0xB3 ,0x03 ,0x01 ,0x01
// 0x0B ,0x05 ,0x04 ,0x0B ,(byte) 0x84 ,0x23 ,(byte) 0xF0 ,0x00 ,0x03 ,0x03 ,0x01 ,0x01
};
//第二部分
byte[] WapPushPUD = new byte[]
{
(byte) 0xB3,0x06,0x01,(byte) 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 代替SmsPushData代码
* 该代码NOKIA 和MOTO都可以收到
* 有无长度控制,NOKIA都可以接收
* 在WapPushPUD后 添加一个0x00,有无长度控制都可以接收NOKIA,可以考虑减少这个0X00
*/
public byte[] format10(String content,String url){
byte[] WapPushUDH = new byte[]
{
0x06,0x05,0x04,0x0b,(byte) 0x84,0x23,(byte) 0xf0
};
byte[] WapPushPUD = new byte[]
{
(byte) 0x81,0x06,0x08,0x03,(byte) 0xae,(byte) 0x81,(byte) 0xea,(byte) 0xb4,(byte) 0x84,(byte) 0x8d ,0x00
};
//第三部分
byte[] WapPushIndicator = new byte[]
{
0x02,0x05,0x6a,0x00,0x45,(byte) 0xc6,0x08,0x0c,0x03
};
//第四部分:消息文字的UTF8编码
//第五部分
//
byte[] WapPushDisplayTextHeader = new byte[]
{
0x00,0x01,0x03
};
//第六部分:URL去掉http://后的UTF8编码
// //第七部分:
byte[] EndOfWapPush = new byte[]
{
0x00, 0x01, 0x01
};
int nurlLen;
int ntipLen;
int ncontent;
String s = "";
byte byte0 = 1;
byte abyte0[] = new byte[4];
// int i = 0;
nurlLen = url.length() + 1;
byte[] bytContent = null;
byte[] bytURL = null;
bytURL=url.getBytes();
bytContent = this.chString2UTF8_byte(content);
ntipLen = bytContent.length + 1;
ncontent = nurlLen + ntipLen + 9 + 2 + 2;
byte[] bytMsg=null;
// getUIntVar(ncontent, abyte0, byte0);
if(ncontent < 128)
{
abyte0[0] = (byte)(ncontent + 128);
byte0 = 1;
}
if(ncontent < 16384)
{
byte0 = 2;
} else
if(ncontent < 0x200000)
{
byte0 = 3;
} else
{
byte0 = 4;
}
ncontent <<= 32 - byte0 * 7;
for(int j = 0; j < byte0 - 1; j++)
{
abyte0[j] |= 0x80;
}
for(int k = 0; k < byte0; k++)
{
abyte0[k] |= (byte)(ncontent>> 32 - (k + 1) * 7 & 0x7f);
}
// int ncontentLen = ncontent + WapPushUDH.length + WapPushPUD.length + byte0;
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+ byte0;
// 否则MOTO A768不能正常接收
WapPushPUD[nWapPushPUDLen-1]=(byte) (bodyLen/2+128); //在WapPushPUD后 添加一个0x00,有无长度控制都可以接收NOKIA
bytMsg = new byte[totalLen];
if(totalLen <= 140)
{
System.arraycopy(WapPushUDH, 0, bytMsg, i, nWapPushUDHLen);
i+=nWapPushUDHLen;
WapPushPUD[2] = (byte)((WapPushPUD.length - 3) + byte0);
System.arraycopy(WapPushPUD, 0, bytMsg, i, nWapPushPUDLen);
i+=nWapPushPUDLen;
System.arraycopy(abyte0, 0, bytMsg, i, byte0);
i += byte0;
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);
} else
{
//System.err.print((new StringBuilder()).append("\u4FE1\u606F\u957F\u5EA6\u8D85\u8FC770\u5B57\u7B26:").append(ncontentLen).toString());
}
return bytMsg;
}
/**
* @param content
* @param url
* @return
*/
public byte[] format11(String content, String url){
byte[] WapPushUDH = new byte[]
{
0x06, 0x05, 0x04, 0x0b, (byte) 0x84, 0x23,(byte) 0xf0
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -