新收集的WAPPUSH代码,并经过改造

 package com.wap;

import java.io.IOException;
import java.sql.Date;


public class WapPush
{

 
 public int sendSMS(String[] mobile_nos, byte[] msg)
 {
。。。。
  return 0;
 }

 public 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
  {
   body += 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;
  System.out.println(pushString);
  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 + "&#x" + hexB + ";";
   }
   else
   {
    unicodeBytes += utfBytes[byteIndex];
   }
  }
  return unicodeBytes;
 }
 
 public static int StringToByte(String str)
 {
  int ret = 0;
  for(int i=0;i<HexCode.length;i++)
  {
   if(HexCode[i].equalsIgnoreCase(str))
    return i;
  }
  return ret;
 }
 
 public static byte[] stringToBytes(String str)
 {
  if(str==null||str.equals(""))
   return null;
 
  byte[] bytes = new byte[str.length()/2];
  for(int i=0;i<bytes.length;i++)
  {
   String high = str.substring(i*2,i*2+1);
   String low = str.substring(i*2+1,i*2+2);
   bytes[i] = (byte) (StringToByte(high)*16 + StringToByte(low));
  }
  return bytes;
 }
 
 public static void main(String[] args)
 {

  WapPush wp= new WapPush();

   

  String[] mobile_nos = {"13812345678"};
 

  int i = wp.sendSMS(mobile_nos,
   WapPush.stringToBytes(
    WapPush.getSMSPush("wap.monternet.com","monternet",
      new java.text.SimpleDateFormat("yyyyMMdd").format(new Date(System.currentTimeMillis())),
      new java.text.SimpleDateFormat("yyyyMMdd").format(new Date(System.currentTimeMillis()))
      )));


 }
}
 

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/cutemouse/archive/2007/02/24/1513559.aspx

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、下载 4使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、 4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值