?? waputils.java
字號:
package com.newpalm.sms.utils;
import java.io.*;
import com.newpalm.sms.business.common.ServiceFee;
import java.util.ArrayList;
import com.newpalm.sms.spmaster.CorbaConnectionContainer;
import spmaster.ISpMaster;
import com.newpalm.sms.Sms;
import java.util.Date;
/**
* 完整的一套Wap發送支撐公用類!
* 彩信 wapPush,的特點是:
* 包括兩部分 ;1: 主題 2:一個超文本鏈接地址
* 注意點:
* 用這個工具包,在傳遞主題時請采用ISo8859-1編碼;
* 還有寫日志的方法!
*
* <p>Copyright: Copyright (c) 2000 - 2001 Newpalm (China) Information Technology * Co., Ltd. All Rights Reserved. * * This SOURCE CODE FILE, which has been provided by Newpalm as part * of an Newpalm product for use ONLY by licensed users of the product, * includes CONFIDENTIAL and PROPRIETARY information of Newpalm. * * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH * THE PRODUCT. * * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD Newpalm, ITS RELATED * COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS * OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION * OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF * OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS * OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE * CODE FILE. </p>
* <p>Company: newpalm</p>
* @author zhupengfei
* @version 1.0
*/
public class WapUtils {
private static byte[] multihead = { //length=12
(byte) 0x0B, (byte) 0x05, (byte) 0x04, (byte) 0x0B,
(byte) 0x84, (byte) 0x23, (byte) 0xF0, (byte) 0x00,
(byte) 0x03, (byte) 0x14, (byte) 0x00, (byte) 0x00 //wdp headers
};
private static byte[] singlehead = { //length=7
(byte) 0x06, (byte) 0x05, (byte) 0x04, (byte) 0x0b,
(byte) 0x84, (byte) 0x23, (byte) 0xf0, //wdp headers
};
private static byte[] head = {//length=17
(byte) 0x72, (byte) 0x06, (byte) 0x0a, (byte) 0x03,
(byte) 0xae, (byte) 0x81, (byte) 0xea, (byte) 0xaf,
(byte) 0x82, (byte) 0x8d, (byte) 0xae,
(byte) 159, //這里是url長度
//(byte) 0x0, //這里是url長度
(byte) 0x87, (byte) 0x01, (byte) 0x05, (byte) 0x6a,
(byte) 0x00 //這里是title長度
};
private static byte[] urlhead = {//length=5
(byte) 0x00, (byte) 0x45, (byte) 0xc6, (byte) 0x0c,
(byte) 0x03
};
/**
* //length=7
*/
private static byte[] tail = {
(byte) 0x00, (byte) 0x08, (byte) 0x01, (byte) 0x83,
(byte) 0x00, (byte) 0x01, (byte) 0x01
};
/**
* 合并數據流;加上頭尾信息!
* @param hint String
* @param urlstr String
* @return byte[]
*/
private static byte[] generationDate ( String hint, String urlstr)
{
byte[] rst =combineToStream( hint , urlstr ) ;
if ( rst.length + 7 <= 140 ) { //單條是否足夠
//單條OK
byte[] tempbytes = rst ;
rst = new byte[ rst.length + 7 ] ;
for ( int i = 0 ; i < singlehead.length ; i++ ) {
rst[ i ] = singlehead[ i ] ;
}
for ( int i = 0 ; i < tempbytes.length ; i++ ) {
rst[ i + 7 ] = tempbytes[ i ] ;
}
}
else
{ //多條
multihead[ 9 ] = ( byte ) ( Math.random () * 1000 % 255 ) ;
byte[] tempbytes = rst ;
rst = new byte[ 140 ] ; //構造長度=140的數組
for ( int i = 0 ; i < multihead.length ; i++ ) {
rst[ i ] = multihead[ i ] ;
}
rst[ 10 ] = 2 ;
rst[ 11 ] = 1 ;
for ( int i = 0 ; i < 128 ; i++ ) {
rst[ i + 12 ] = tempbytes[ i ] ;
}
rst = new byte[ tempbytes.length - 128 + 12 ] ;
for ( int i = 0 ; i < multihead.length ; i++ ) {
rst[ i ] = multihead[ i ] ;
}
rst[ 10 ] = 2 ;
rst[ 11 ] = 2 ;
for ( int i = 0 ; i < tempbytes.length - 128 ; i++ ) {
rst[ i + 12 ] = tempbytes[ i + 128 ] ;
}
}
return rst ;
}
/**
*
* @param title String
* @param url String
* @return byte[]
*/
public static byte[] combineToStream(String title, String url)
{
try{
int title_len; //標題長度
int url_len; //url長度
int total_len; //結果長度
byte[] title_bytes; //標題byte流
byte[] url_bytes; //url byte流
if ( title==null|| url==null) return null ;
String validTitle = new String ( ( new String(title.getBytes("ISO8859_1") ,"Gb2312")).getBytes("UTF8"), "ISO8859_1") ;
String validUrl = new String ( ( new String(url.getBytes("ISO8859_1") ,"Gb2312")).getBytes("UTF8"), "ISO8859_1") ;
//ISO-8859-1
title_bytes = validTitle.getBytes("ISO8859_1");
url_bytes = validUrl.getBytes("ISO8859_1");
title_len = title_bytes.length;
url_len = url_bytes.length;
total_len = title_len + url_len + 29;//計算總長度
byte[] result_bytes = new byte[total_len];//根據總長度構造結果流
int i = 0;
//頭部17 bytes 赴值
for (i = 0; i < 17; i++) {
result_bytes[i] = head[i];
}
//給特殊位置赴url長度
result_bytes[11] += (byte) (url_len+1);
//標題長度
result_bytes[16] = (byte) (title_len+1);
//標題赴值
for (int j = 0; j < title_len; j++) {
result_bytes[i + j] = title_bytes[j];
}
i += title_len;//指針后移
//urlheader 5 bytes赴值
for (int j = 0; j < 5; j++) {
result_bytes[i++] = urlhead[j];
}
//url 赴值
for (int j = 0; j < url_len; j++) {
result_bytes[i + j] = url_bytes[j];
}
i += url_len;
//尾部
for (int j = 0; j < 7; j++) {
result_bytes[i++] = tail[j];
}
return result_bytes;
} catch (Exception e){
return null;
}
}
// convert gb to unicode
public static String npgb2utf(String npgb) {
try {
String outputstr = new String(npgb.getBytes("UTF8"), "ISO8859_1");
return outputstr;
}
catch (Exception e) {
e.printStackTrace(System.out);
return null;
}
}
public static void addMMSMessage( String hint, String urlstr,
String phone_num ,
String feephone_num ,
ServiceFee serid ,
String srcTermianlID,
ArrayList arrsubmitmsg )
{
addMMSMessage( hint, urlstr,
phone_num ,
feephone_num ,
serid ,
srcTermianlID,
1,
arrsubmitmsg );
}
/**
*
* @param hint String
* @param urlstr String
* @param phone_num String
* @param feephone_num String
* @param serid ServiceFee
* @param srcTermianlID String
* @param arrsubmitmsg ArrayList
*/
public static void addMMSMessage( String hint, String urlstr,
String phone_num ,
String feephone_num ,
ServiceFee serid ,
String srcTermianlID,
int tp_pid ,
ArrayList arrsubmitmsg )
{
//SmsUtils.
addMMSMessage( hint,urlstr, phone_num ,
feephone_num ,
serid ,srcTermianlID,
Sms.PUSH_SP_CODE,
Sms.PUSH_SP_PASSWORD,
tp_pid,
arrsubmitmsg) ;
}
public static void addMMSMessage( String hint, String urlstr,
String phone_num ,
String feephone_num ,
ServiceFee serid ,
String srcTermianlID,
String spCode ,
String spPassword ,
int tp_pid ,
ArrayList arrsubmitmsg )
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -