📄 wappushencoder.java
字号:
//
// 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);
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 老赵版本,URL和CONTENT互换会有不同的效果;
* 没有长度控制。
*/
public byte[] format4(String content, String url){
byte[] WapPushUDH = new byte[]
{
0x06, 0x05, 0x04, 0x0b, (byte) 0x84, 0x23,(byte) 0xf0
};
byte[] WapPushPUD = new byte[]
{
0x25, 0x06, 0x01, (byte) 0xae
};
byte[] WapPushIndicator = new byte[]
{
//// 比老赵版本是01,部分代码是02
// 0x02, 0x05, 0x6a, 0x00, 0x45, (byte) 0xC6,0x08,0x0C, 0x03 //比老赵帮本多了一个,在这里;//不成功;
0x01, 0x05, 0x6a, 0x00, 0x45, (byte) 0xC6, 0x0C, 0x03 //老赵版本;不成功
// 0x02, 0x05, 0x6a, 0x00, 0x45, (byte) 0xC6,0x0C, 0x03 //把01改成02,和FORMAT5一样了,FORMAT5可以成功收到。
};
//
byte[] WapPushDisplayTextHeader = new byte[]
{
0x00, 0x01, 0x03
};
byte[] EndOfWapPush = new byte[]
{
0x00, 0x01, 0x01
};
byte[] bytContent = null;
byte[] bytURL = null;
try {
// 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);
bytURL = urlUTF8.getBytes();
}
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);
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
* 网上的代码,WBXML太长。
*/
public byte[] format7(String content,String url){
Calendar calendar = Calendar.getInstance();
String currentTime = getTimeString(calendar);
// System.out.println(currentTime);
calendar.add(calendar.MONTH, 1); //一个月以后的时间
String nextTime = getTimeString(calendar);
byte[] startTime= getTimeBytes(currentTime);
byte[] endTime = getTimeBytes(nextTime);
// System.out.println(this.byteToHexStr(endTime));
// System.out.println(this.byteToHexStr(startTime));
// udh = udh + "06";
// udh = udh + "05";
// udh = udh + "04";
// udh = udh + "0B";
// udh = udh + "84";
// udh = udh + "23";
// udh = udh + "F0";
byte[] WapPushUDH = new byte[]
{
0x06,0x05,0x04,0x0B,(byte) 0x84,0x23,(byte) 0xF0
};
// pud = pud + "81";
// pud = pud + "06";
// pud = pud + "08";
// pud = pud + "03";
// pud = pud + "AE";
// pud = pud + "81";
// pud = pud + "EA";
// pud = pud + "b4";
// pud = pud + "84";
// pud = pud + "8D";
byte[] WapPushPUD = new byte[]
{
(byte) 0x81,0x06,0x08,0x03,(byte) 0xAE,(byte) 0x81,(byte) 0xEA,(byte) 0xb4,(byte) 0x84,(byte) 0x8D,0x00
};
// body = body + "02";
// body = body + "05";
// body = body + "6A";
// body = body + "00";
// body = body + "45";
// body = body + "C6";
// body = body + "08";
// body = body + "0C";
// body = body + "03";
byte[] WapPushIndicator = new byte[]
{
0x02, 0x05, 0x6A, 0x00, 0x45, (byte) 0xC6,0x08,0x0C, 0x03
};
//第四部分:URL去掉http://后的UTF8编码
//第五部分
// body = body + "00";
// body = body + "0A";
// body = body + "C3";////时间字
// body = body + "07";////时间字节数
byte[] WapPushDisplayTextHeader1 = new byte[]
{
0x00, 0x0a, (byte) 0xc3,//0x07
};
// body = body + startTime;
// body = body + "10";
// body = body + "C3";//时间字
// body = body + "07";////时间字节数
byte[] WapPushDisplayTextHeader2 = new byte[]
{
0x10, (byte) 0xc3,// 0x07
};
// body = body + endTime;
// body = body + "01";
// body = body + "03";
//
byte[] WapPushDisplayTextHeader3 = new byte[]
{
0x01, 0x03
};
//第六部分:消息文字的UTF8编码
// //第七部分:
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 nPushDisplayTextHeader1Len=WapPushDisplayTextHeader1.length;
int nStartTimeLen=startTime.length;
int nPushDisplayTextHeader2Len=WapPushDisplayTextHeader2.length;
int nEndTimeLen=endTime.length;
int nPushDisplayTextHeader3Len=WapPushDisplayTextHeader3.length;
int nBytContentLen=bytContent.length;
int nEndOfWapPushLen=EndOfWapPush.length;
int bodyLen=nPushIndicatorLen+nBytURLLen+nPushDisplayTextHeader1Len+nStartTimeLen+nPushDisplayTextHeader2Len+nEndTimeLen+nPushDisplayTextHeader3Len+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(WapPushDisplayTextHeader1, 0, bytMsg, i, nPushDisplayTextHeader1Len);
i+=nPushDisplayTextHeader1Len;
System.arraycopy(startTime, 0, bytMsg, i, nStartTimeLen);
i+=nStartTimeLen;
System.arraycopy(WapPushDisplayTextHeader2, 0, bytMsg, i, nPushDisplayTextHeader2Len);
i+=nPushDisplayTextHeader2Len;
System.arraycopy(endTime, 0, bytMsg, i, nEndTimeLen);
i+=nEndTimeLen;
System.arraycopy(WapPushDisplayTextHeader3, 0, bytMsg, i, nPushDisplayTextHeader3Len);
i+=nPushDisplayTextHeader3Len;
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[] format8(String content,String url){
//第一部分
byte[] WapPushUDH = new byte[]
{
0x0B, 0x05, 0x04, 0x0B, (byte) 0x84, 0x23, (byte) 0xF0, 0x00, 0x03, 0x03, 0x01, 0x01
};
//第二部分
byte[] WapPushPUD = new byte[]
{
0x29, 0x06, 0x06, 0x03, (byte) 0xAE, (byte) 0x81, (byte) 0xEA, (byte) 0x8D, (byte) 0xCA
};
//第三部分
byte[] WapPushIndicator = new byte[]
{
0x02, 0x05, 0x6A, 0x00, 0x45, (byte) 0xC6, 0x0C, 0x03
};
//第四部分:URL去掉http://后的UTF8编码
//第五部分
// 0x00; //字符串结束
// 0x01; //>
// 0x03; //字符串开始
//
byte[] WapPushDisplayTextHeader = new byte[]
{
0x00, 0x01, 0x03
};
//第六部分:消息文字的UTF8编码
//第七部分:
// 0x00; //字符串结束
// 0x01; //</indication>"
// 0x01; //</si>
byte[] EndOfWapPush = new byte[]
{
0x00, 0x01, 0x01
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -