我前几天在这里看到的一段短信wap push的 代码,对移动wap的 , 有个问题不明白, url 是sp的地址还是 移动的 地址啊 subject 的内容应该是什么啊,,最好可以举个例子 starttime 和 endtime 做什么用的啊,,应该如何取呢
顺便问一句,,现在移动还可以sms 进行 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 '字符串开始 这里就是url从 "http:// "以后的那部分的每个字符的ASCII码 00 '字符串结束 0A 'created= C3 '时间 07 '7个字节,也可以是04,下面就只需要年月日就可以了 20 03 01 01 00 00 00 '年,月,日,时,分,秒,格式如何一看就明白吧。 10 'si_expires= C3 '时间 07 '跟上面一样 20 04 01 01 00 00 00 01 '> 03 '字符串开始 这里就是显示给用户的内容,用utf-8编码。 utf-8编码,英文字符直接用ascii码;中文如果unicode是(二进制)abcdefgh ijklmnop, 那么utf-8就会变成1110abcd 10efghij 10klmnop 00 '字符串结束 01 ' </indication> " 01 ' </si>
有了Push消息体之后,需要在前面增加一个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消息体的长度。如果消息体长度小于128,那么就要加上128。例如是93个字节,那么需要填入DD '至于大于127怎么处理,按照协议好像应该是这样,例如原来的二进制abcdefgh,那么就要弄成两个字节: '1000000a 1bcdefgh,但是尝试还没成功
在然后,还要在前面增加一个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
如果所有这些加起来大于140个字节,那么就需要修改UDH头,分成两条短消息串联。但是没有尝试成功。
发送的时候,udhi=1,pid=0,dcs=4 Nokia 3650/7650肯定OK,motorola t720肯定ok,siemens 3118,3618肯定不行,其他的还没尝试。
同样的技术可以用来发送mms通知、fundown的铃声图片。
需要解决的问题:长于127字节/两条短信的时候该怎么办。 */
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 "; //字符串结束 body += "45 "; // <si> body += "C6 "; // <indication body += "08 "; // <action=signal-high> body += "0C "; //href= "http:// body += "03 "; //字符串开始 body += byteArrayToHexString(url.getBytes()); //实际地址 body += "00 "; //字符串结束 body += "0A "; //created= body += "C3 "; // '时间 body += "07 "; //时间字节数 body += startTime; //YYYYMMDDHHMMSS body += "10 "; //si_expires= body += "C3 "; //时间 body += "07 "; //时间字节数 body += endTime; //YYYYMMDDHHMMSS body += "01 "; //> body += "03 "; //字符串开始 try { ody += byteArrayToHexString(subject.getBytes( "UTF-8 ")); //显示给用户的内容,用utf-8编码。utf-8编码,英文字符直接用ascii码;中文如果unicode是(二进制) } catch (Exception ex)
{ } body += "00 "; //字符串结束 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; } }
|