package com.wap;
import java.io.IOException;
import java.util.Calendar;
import java.util.Vector;
import com.tools.Utf8Util;
import sun.misc.BASE64Decoder;
public class WapPushEncoder {
public static String getBASE64(String s) {
if(s == null)
return null;
return (new sun.misc.BASE64Encoder()).encode(s.getBytes());
}
public static String getFromBASE64(String s) {
if(s == null)
return null;
BASE64Decoder decoder = new BASE64Decoder();
try {
byte[] b = decoder.decodeBuffer(s);
System.out.print(new String(b));
return new String(b);
}
catch(Exception e) {
return null;
}
}
/**
* @param content
* @param url
* @return
* NOKIA 6600可以通过,其余不是很顺利;多普大也收到
* 李伟版本;
*/
public byte[] format(String content, String url) {
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);
// System.out.println(this.byteToHexStr(bytContent));
// System.out.println(this.byteToHexStr(this.chString2UTF8_byte(content)));
//
bytURL = urlUTF8.getBytes();
// System.out.println(this.byteToHexStr(bytURL));
}
catch(Exception ex) {
ex.printStackTrace(); }
int iContentLen = bytContent.length;
int iURLLen = bytURL.length;
byte[] bytMsg = new byte[36 + iContentLen + iURLLen];
int i = 0;
bytMsg[i++] = (byte)0x06;
bytMsg[i++] = (byte)0x05;
bytMsg[i++] = (byte)0x04;
bytMsg[i++] = (byte)0x0b;
bytMsg[i++] = (byte)0x84;
bytMsg[i++] = (byte)0x23;
bytMsg[i++] = (byte)0xf0;
bytMsg[i++] = (byte)0x72;
bytMsg[i++] = (byte)0x06;
bytMsg[i++] = (byte)0x0a;
bytMsg[i++] = (byte)0x03;
bytMsg[i++] = (byte)0xae;
bytMsg[i++] = (byte)0x81;
bytMsg[i++] = (byte)0xea;
bytMsg[i++] = (byte)0xaf;
bytMsg[i++] = (byte)0x82;
bytMsg[i++] = (byte)0x8d;
bytMsg[i++] = (byte)0xae; // 18
int ipos = i;
bytMsg[i++] = (byte)159; //159+iURLLen
bytMsg[i++] = (byte)0x87;
bytMsg[i++] = (byte)0x01;
bytMsg[i++] = (byte)0x05;
bytMsg[i++] = (byte)0x6a;
bytMsg[i++] = (byte)(iContentLen + 1);
System.arraycopy(bytContent, 0, bytMsg, i, iContentLen);
i += iContentLen;
bytMsg[i++] = (byte)0x00;
bytMsg[i++] = (byte)0x45;
bytMsg[i++] = (byte)0xc6;
bytMsg[i++] = (byte)0x0c;
bytMsg[i++] = (byte)0x03;
System.arraycopy(bytURL, 0, bytMsg, i, iURLLen);
i += iURLLen;
bytMsg[ipos] += (byte)iURLLen;
bytMsg[i++] = (byte)0x00;
bytMsg[i++] = (byte)0x08;
bytMsg[i++] = (byte)0x01;
bytMsg[i++] = (byte)0x83;
bytMsg[i++] = (byte)0x00;
bytMsg[i++] = (byte)0x01;
bytMsg[i++] = (byte)0x01;
// System.out.println("BYTE LENGTH : " + bytMsg.length);
return bytMsg;
}
public String byteToHexStr(byte buf[]) {
StringBuffer sb = new StringBuffer(2 * buf.length);
for(int i = 0; i < buf.length; i++) {
int h = (buf[ i ] & 0xf0) >> 4;
int l = (buf[ i ] & 0x0f);
sb.append(new Character((char)((h > 9) ? 'a' + h - 10 : '0' + h)));
sb.append(new Character((char)((l > 9) ? 'a' + l - 10 : '0' + l)));
}
return sb.toString().toUpperCase();
}
public String intToHexStr(int i) {
if(i>255)
return "00";
StringBuffer sb = new StringBuffer(2);
int h=0;
int l=0;
h=i/16;
// System.out.println(h);
l=i%16;
// System.out.println(l);
sb.append(new Character((char)((h > 9) ? 'a' + h - 10 : '0' + h)));
sb.append(new Character((char)((l > 9) ? 'a' + l - 10 : '0' + l)));
System.out.println(sb.toString().toUpperCase());
return sb.toString().toUpperCase();
}
private byte[] chString2UTF8_byte(String str) {
byte[] result = null;
try{
str = new String(str.getBytes(),"GB2312");
result = str.getBytes("UTF-8");
}catch (Exception e){
e.printStackTrace();
}
return result;
}
/**
* @param content
* @param url
* @return
* 没有长度控制。
*/
public byte[] format5(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[]
{
0x02, 0x05, 0x6A, 0x00, 0x45, (byte) 0xC6, 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
};
// String wapPushHeader1="0B05040B8423F00003030101";
// String wapPushHeader2="29060603AE81EA8DCA";
// String wapPushIndicator="02056A0045C60C03";
//// 第四部分:URL去掉http://后的UTF8编码
// String wapPushDisplayTextHeader="000103";
//// 第六部分:消息文字的UTF8编码
// String wapPushEnd="000101";
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+=nPu
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论







收起资源包目录


















共 15 条
- 1
- 2
- 3
资源评论

- 魔烨2018-11-26没有渔好。
- bigraywolf2017-05-06一般般吧,不是我想要的
- softstarxy2013-09-20不好用。没什么用处
- mostlykill2012-06-07没有编译过,需要可以直接使用的,效果不清楚。谢谢吧。
- finzaghi092011-10-08不错,找了很久这个,终于找到了,要有c#版的就更好了,不过我是看思路的,语言不重要
cutemouse
- 粉丝: 319
- 资源: 79

上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
已下载
下载帮助

内容简介:wappush.rar wap wap PushUtilA8.java PushUtil.java SmsPushData.java WapPushMessage.java WapPush.java WapPushSender.java WapPushEncoder.java CmppWapPush.java wbxml
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
