帮帮忙?把这段java 代码转换成 javascript代码?对java不熟悉!

ftbk 2006-02-21 01:47:22
public class SmsPush {
public static String getPushMsg(String subject,String url) {
String pushString = "";
String body = "";
body += "01";
body += "05"; //-//WAPFORUM//DTD SI 1.0//EN
body += "6A"; //UTF-8
body += "00"; //字符串结束
body += "45"; //<si>
body += "C6"; //<indication
body += "08"; //<action=signal-high>/////
body += "0C"; //href="http://
body += "03"; //字符串开始
body += byteArrayToHexString(url.getBytes()); //实际地址
body += "00"; //字符串结束
//body += "08"; //<action=signal-high>
body += "01"; ///>
body += "03";
try {
body += byteArrayToHexString(subject.getBytes("UTF-8")); //显示给用户的内容,用utf-8编码。utf-8编码,英文字符直接用ascii码;中文如果unicode是(二进制)
}
catch (Exception ex) {
}
body += "00"; //
body += "01"; ///>
body += "01"; ///>
int length = body.length();
String pud = "";
pud += "72"; //transaction id (connectionless WSP)
pud += "06"; //'pdu type (06=push)
pud += "0A"; //Headers len
pud += "03";
pud += "AE";
pud += "81";
pud += "EAAF82"; //content type: application/vnd.wap.sic; charset=utf-8
pud += "8D"; //content-length
pud += Integer.toHexString(length).toUpperCase();
pud += "D687";
String udh = "";
udh += "06"; //User Data Header Length (6 bytes)
udh += "05"; //UDH Item Element id (Port Numbers)
udh += "04"; //UDH IE length (4 bytes)
udh += "0B";
udh += "84"; //destination port number
udh += "23";
udh += "F0"; //origin port number
pushString = udh + pud + body;
return pushString;
}

public static String byteArrayToHexString(byte b[]) {
String result = "";
for (int i = 0; i < b.length; i++)
result = result + byteToHexString(b[i]);
return result;
}

public static String byteToString(byte b[]) {
String result = "";
for (int i = 0; i < b.length; i++) {
result = result + b[i];
}
return result;
}

public static String byteToHexString(byte b) {
int n = b;
if (n < 0)
n = 256 + n;
int d1 = n / 16;
int d2 = n % 16;
return HexCode[d1] + HexCode[d2];
}

private static String HexCode[] = {
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"A", "B", "C", "D", "E", "F"
};
}
...全文
43 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧