我前幾天在這里看到的一段短信wap push的 代碼,對(duì)移動(dòng)wap的 , 有個(gè)問(wèn)題不明白, url 是sp的地址還是 移動(dòng)的 地址啊 subject 的內(nèi)容應(yīng)該是什么啊,,最好可以舉個(gè)例子 starttime 和 endtime 做什么用的啊,,應(yīng)該如何取呢
順便問(wèn)一句,,現(xiàn)在移動(dòng)還可以sms 進(jìn)行 wap push 嗎
/* 02 05 '-//WAPFORUM//DTD SI 1.0//EN 6A 'UTF-8 00 45 ' <si> C6 ' <indication 08 ' <action=signal-high> 0C 'href= "http:// 03 '字符串開(kāi)始 這里就是url從 "http:// "以后的那部分的每個(gè)字符的ASCII碼 00 '字符串結(jié)束 0A 'created= C3 '時(shí)間 07 '7個(gè)字節(jié),也可以是04,下面就只需要年月日就可以了 20 03 01 01 00 00 00 '年,月,日,時(shí),分,秒,格式如何一看就明白吧。 10 'si_expires= C3 '時(shí)間 07 '跟上面一樣 20 04 01 01 00 00 00 01 '> 03 '字符串開(kāi)始 這里就是顯示給用戶的內(nèi)容,用utf-8編碼。 utf-8編碼,英文字符直接用ascii碼;中文如果unicode是(二進(jìn)制)abcdefgh ijklmnop, 那么utf-8就會(huì)變成1110abcd 10efghij 10klmnop 00 '字符串結(jié)束 01 ' </indication> " 01 ' </si>
有了Push消息體之后,需要在前面增加一個(gè)Push PDU 81 'transaction id (connectionless WSP) 06 'pdu type (06=push) 06 'Headers len 03 AE 81 EA 'content type: application/vnd.wap.sic; charset=utf-8 8D 'content-length XX '這里就是Push消息體的長(zhǎng)度。如果消息體長(zhǎng)度小于128,那么就要加上128。例如是93個(gè)字節(jié),那么需要填入DD '至于大于127怎么處理,按照協(xié)議好像應(yīng)該是這樣,例如原來(lái)的二進(jìn)制abcdefgh,那么就要弄成兩個(gè)字節(jié): '1000000a 1bcdefgh,但是嘗試還沒(méi)成功
在然后,還要在前面增加一個(gè)UDH 06 'User Data Header Length (6 bytes) 05 'UDH Item Element id (Port Numbers) 04 'UDH IE length (4 bytes) 0B 84 'destination port number 23 F0 'origin port number
如果所有這些加起來(lái)大于140個(gè)字節(jié),那么就需要修改UDH頭,分成兩條短消息串聯(lián)。但是沒(méi)有嘗試成功。
發(fā)送的時(shí)候,udhi=1,pid=0,dcs=4 Nokia 3650/7650肯定OK,motorola t720肯定ok,siemens 3118,3618肯定不行,其他的還沒(méi)嘗試。
同樣的技術(shù)可以用來(lái)發(fā)送mms通知、fundown的鈴聲圖片。
需要解決的問(wèn)題:長(zhǎng)于127字節(jié)/兩條短信的時(shí)候該怎么辦。 */
private static String getSMSPush(String url, String subject, String startTime, String endTime) { String pushString = " "; String body = " "; body += "02 "; body += "05 "; //-//WAPFORUM//DTD SI 1.0//EN body += "6A "; //UTF-8 body += "00 "; //字符串結(jié)束 body += "45 "; // <si> body += "C6 "; // <indication body += "08 "; // <action=signal-high> body += "0C "; //href= "http:// body += "03 "; //字符串開(kāi)始 body += byteArrayToHexString(url.getBytes()); //實(shí)際地址 body += "00 "; //字符串結(jié)束 body += "0A "; //created= body += "C3 "; // '時(shí)間 body += "07 "; //時(shí)間字節(jié)數(shù) body += startTime; //YYYYMMDDHHMMSS body += "10 "; //si_expires= body += "C3 "; //時(shí)間 body += "07 "; //時(shí)間字節(jié)數(shù) body += endTime; //YYYYMMDDHHMMSS body += "01 "; //> body += "03 "; //字符串開(kāi)始 try { ody += byteArrayToHexString(subject.getBytes( "UTF-8 ")); //顯示給用戶的內(nèi)容,用utf-8編碼。utf-8編碼,英文字符直接用ascii碼;中文如果unicode是(二進(jìn)制) } catch (Exception ex)
{ } body += "00 "; //字符串結(jié)束 body += "01 "; // </indication> " body += "01 "; // ' </si> int length = body.length(); String pud = " "; pud += "81 "; //transaction id (connectionless WSP) pud += "06 "; // 'pdu type (06=push) pud += "06 "; //Headers len pud += "03 "; pud += "AE "; pud += "81 "; pud += "EA "; //content type: application/vnd.wap.sic; charset=utf-8 pud += "8D "; //content-length pud += Integer.toHexString(length).toUpperCase(); 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 " };
private static String getUTFString(final String gbString) { if (gbString == null) return " "; char[] utfBytes = gbString.toCharArray(); String unicodeBytes = " "; for (int byteIndex = 0; byteIndex < utfBytes.length; byteIndex++) { String hexB = " "; if (utfBytes[byteIndex] < '! ') { hexB = Integer.toHexString(utfBytes[byteIndex]); if (hexB.length() <= 2) { hexB = "00 " + hexB; } unicodeBytes = unicodeBytes + " " + hexB + "; "; } else { unicodeBytes += utfBytes[byteIndex]; } } return unicodeBytes; } }
|