`
lylyb
  • 浏览: 88856 次
  • 性别: Icon_minigender_1
  • 来自: 烟台
社区版块
存档分类
最新评论

短信网关发送部分源代码

    博客分类:
  • JAVA
阅读更多
package com.etonenet.iiie.sdk;

import java.sql.Timestamp;
import java.util.LinkedList;

/**
*Feb 20, 2007
* Zhou JianGuo
* 小白
* 中国电信上海技术研究院
* MSN:zhuojianguo_leo@hotmail.com
*/
public abstract class Sender {

protected int    status = -1;
protected String desc = null;
protected String messageId = null;

protected String user = null;
protected String password = null;

protected String serviceType = null;
protected String payer = null;
protected Timestamp time = null;
protected int esmClass = 0;
protected int protocolId = 0;
protected byte[] sm = null;
protected int dataCoding = 0;

protected String url = null;

protected int priorityFlag = 1;

protected boolean debug = true;

public boolean smc = false;

public void setDebug(boolean value) {
  debug = value;
}

public void setURL(String url) {
  this.url = url;
}

public String getURL() {
  return url;
}

public void setProtocolId(int id) {
  protocolId = id;
}

public int getProtocolId() {
  return protocolId;
}

public void setShortMessage(byte[] sm, int dataCoding, int esmClass, int protocolId) {
  this.sm = sm;
  this.dataCoding = dataCoding;
  this.esmClass = esmClass;
  this.protocolId = protocolId;
}

/**
  * Set service type.
  *
  * @param serviceType service type, default null.
  */
public void setServiceType(String serviceType) {
  this.serviceType = serviceType;
}


public void setSmc(boolean v) {
  smc = v;
}

public boolean getSmc() {
  return smc;
}

/**
  * Send sms send time.
  *
  * @param time timstamp, string format "yyyy-MM-dd HH:mm:ss"
  */
public void setTime(Timestamp time) {
  this.time = time;
}

public Timestamp getTime() {
  return time;
}
/**
  * Set the user.
  *
  * @param user the user name.
  */
public void setUser(String user) {
  this.user = user;
}

public String getUser() { return user; }

/**
  * Set the password of this user. if the length of password large 32. it will trim to 32.
  *
  * @param password user password.
  */
public void setPassword(String password) {
  if (password == null) {
   this.password = "";
  } else {
   if (password.length() > 32) {
    this.password = password.substring(0, 32);
   } else {
    this.password = password;
   }
  }
}

public String getPassword() {
  return password;
}

/**
  * Set fee information
  *
  * @param payer default null. must at international format.
  */
public void setPayer(String payer) {
  this.payer = payer;
}

public String getPayer() {
  return payer;
}

public void setPriorityFlag(int pf) {
  priorityFlag = pf;
}

public int getPriorityFlag() {
  return priorityFlag;
}

/**
  * Get last post status.
  */
public int getStatus() {
  return status;
}

public String getDescription() {
  return desc;
}

public String getMessageId() {
  return messageId;
}

/**
  * Send sms to special addr through etonenet sms server.
  *
  * @param addr target phone number
  */
public abstract int send(String addr) throws Exception;

static char baseTable[] = {
  'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
  'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
  'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
  'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/'
    };

public static void base64(byte[] arr, StringBuffer sb) {

  byte bytes[] = arr;
  int n = arr != null ? arr.length : 0;

  if (n < 1) return;          // no bytes to encode!?!

  byte buf[] = new byte[4];   // array of base64 characters

  int n3byt      = n / 3;     // how 3 bytes groups?
  int nrest      = n % 3;     // the remaining bytes from the grouping
  int k          = n3byt * 3; // we are doing 3 bytes at a time
  int linelength = 0;         // current linelength
  int i          = 0;         // index

  // do the 3-bytes groups ...
  while ( i < k ) {
   buf[0]= (byte)((bytes[i] & 0xFC) >> 2);
   buf[1]= (byte)(((bytes[i] & 0x03)  << 4)|((bytes[i+1] & 0xF0)>> 4));
   buf[2]= (byte)(((bytes[i+1] & 0x0F)<< 2)|((bytes[i+2] & 0xC0)>> 6));
   buf[3]= (byte)(bytes[i+2] & 0x3F);

   sb.append(baseTable[buf[0]]);
   sb.append(baseTable[buf[1]]);
   sb.append(baseTable[buf[2]]);
   sb.append(baseTable[buf[3]]);

     i += 3;
  }

  // deals with with the padding ...
  if (nrest==2) {
   // 2 bytes left
   buf[0] = (byte)(( bytes[k] & 0xFC)   >> 2);
   buf[1] = (byte)(((bytes[k] & 0x03)   << 4) |
    ((bytes[k+1] & 0xF0) >> 4));
   buf[2] = (byte)(( bytes[k+1] & 0x0F) << 2);
  }
  else if (nrest==1) {
   // 1 byte left
   buf[0] = (byte)((bytes[k] & 0xFC) >> 2);
   buf[1] = (byte)((bytes[k] & 0x03) << 4);
  }
  if (nrest > 0) {
   // send the padding
   sb.append(baseTable[buf[0]]);
   sb.append(baseTable[buf[1]]);
   // Thanks to R. Claerman for the bug fix here!
   if (nrest==2) {
    sb.append(baseTable[buf[2]]);
   }
   else {
    sb.append('=');
   }
   sb.append('=');
  }
  }

/**
  * Send(group send) message to multi phones.
  *
  * @param list phone number list
  */
public void send(LinkedList list) throws Exception {
  for(int i = 0; i < list.size(); i ++) {
   String s = (String)list.get(i);
   send(s);
  }
}

}


分享到:
评论

相关推荐

    短信接口短信网关源代码

    短信网关接口集成 各种语言源代码集成应用 asp php asp.net c# 等接口源码 跟实与网站 集成。验证码发送。短信收发功能。

    短信网关接口源代码+demo

    短信网关接口源代码:口标准:客户端通过Tcp连接到服务器(211.162.36.89:8021, IP可能会变动,变动时,以www.pohoo.com网站公布的为准)。连接成功后客户端应首先发送注册串为:Login Name=【注册名】&Pwd=【注册...

    短信网关源代码(2.0.3)

    这里不但为你提供短信网关信息,同时还提供短信网关源代码及其开发资料,通过Internet网连接到短信网关服务的端口即可,源代码包括短信协议,短信发送及其DEMO程序。有了开发源代码及其开发资料,你可以按自己的要求...

    短信网关源代码

    逢年过节,总要群发一些祝福短信之类的给客户、朋友。使用手机群发太慢,成本还高。要是有几千几万的客户的话...无论今天的免费午餐还能吃多久,我们不妨来试试下面这些免费的手机短信发送方法、愿它能带给你一些实惠。

    联通短信网关发送程序源码(C#)

    c#调用傲天api实现向联通短信网关发送短信,接收状态报告等功能,包内包括傲天api和vs2005下的c#源代码。

    SendSMS (新浪短信网关发送短信)

    SendSMS利用新浪短信网关发送短信的程序和源代码。其实就是操作网页提交来达到发送效果。

    sms-smg-send.rar_smg_sms sender java_smssmG

    电信短信网关发送部分源代码:public abstract class Sender

    SMS.rar_sms_短信网关_短信网关源码

    短信网关发送源代码,包含对短信网关的使用和发送有一定的帮助

    CMPP3.0短信网关.netcore(c#)源代码(亲测可用)

    1.遵照CMPP3.0协议实现,模拟了短信网关,支持CONNECT,SUBMIT,DELIVER,QUERY,CANCEL,TERMINATE消息; 2.net5.0开发支持windows/liunx系统; 3.支持长短信; 4.支持心跳协议; 5.支持多线程; 6.支持收/发短信; 7....

    sms_net.rar_visual c_短信网关c

    短信网关源代码,可以发送短消息,有需要可以

    用PB开发的短信群发

    ▲ 内置各大网站高速短信网关,发送每条短信不超过5秒。 ▲ 支持自编短语库,方便调用。 ▲ 支持短信群发功能,可任意批量生成手机号码。 ▲ 提供了各大短信网站的言情短语库,短语多而且种类齐,不管你...

    企信通短信平台 客户端WEB网页版源代码 全协议网关

    北信正通电信级短信平台MC-SMS在通讯模块、数据接受和发送模块、数据处理模块等方面据具有强大的海量处理能力。平台支持现行运营商的所有短信通信协议(包括Cmpp3.0、Cmpp2.0、Sgip1.2、Sgip2.0、Isag\Ismp以及其他...

    Demonew.rar_HMCMPPA_cmpp_短信接收_网关_长短信

    中国移动长短信接收发送的网关系统工程源程序代码

    C#开发的短信平台源代码

    该短信平台适用于大中小型企业、商场、酒店等,面向企事业单位...主要提供短信网关,短信接口, 网站接口以及 OA 、 CRM 、 ERP 、 SCM 、等系统及B2B大型网站平台使用。 接入方式可灵活使用,24小时发送,多条通道备用。

    JAVA上百实例源码以及开源项目源代码

    2个目标文件 摘要:Java源码,文件操作,TCP,服务器 Tcp服务端与客户端的JAVA实例源代码,一个简单的Java TCP服务器端程序,别外还有一个客户端的程序,两者互相配合可以开发出超多的网络程序,这是最基础的部分。...

    php使用ICQ网关发送手机短信

    通过ICQ网关发送手机短信的php源程序复制代码 代码如下:&lt;?//###########################################################//// For questions and comments// Roland (alias -=: Vlieg :=-)// icq #78354631// ...

Global site tag (gtag.js) - Google Analytics