⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 waputils.java

📁 Wap Push 
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

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 + -