分类:
2008-10-15 16:40:34
package org.crabo.blog;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.commerceware.cmpp.*;
public class SMSAPI {
static Log log;
static cmppe_result result;
static CMPP cmpp;
static conn_desc connDesc;
public static void main(String[] args) {
String loginID = "*****";
String userID = "*****\0";
String passWord = "*****";
String icpID = "*****\0";
String dst = "*****";
String mess = "*****";
String svcType = "*****\0";
String ip = "*****";
int port = 7890;
////////////////////////////////////////////////////////
log = LogFactory.getLog(SMSAPI.class);
result = null;
cmpp = new CMPP();
connDesc = new conn_desc();
////////////////////////////////////////////////////////
//截取多个联系人
String[] dstArray = dst.split(";");
//计算消息截取段数 :56/70 = 0 => messPart=messPart=1
int messLen = mess.length();
int messPart = messLen/70 +1;
String[] messArray = new String[messPart];
for(int i=0;i
messArray[i] = mess.substring(70*i,(70*(i+1)
////////////////////////////////////////////////////////
log.info("开始运行... ");
try{
cmpp.cmpp_connect_to_ismg(ip, port, connDesc);
log.info("连接完毕!");
cmpp.cmpp_login(connDesc, loginID, password, (byte)2, 0x12, (int)System.currentTimeMillis());
result = cmpp.readResPack(connDesc);
if (result.stat != CMPP.CMPPE_RSP_SUCCESS)
throw new Exception("状态错误,stat "+ result.stat);
else
log.info("登录成功! ");
}catch(Exception e){
log.error("登录失败 " + e);
System.exit(0);
}
////////////////////////////////////////////////////////
log.info("开始发送... ");
try{
cmppe_submit submitStruct = new cmppe_submit();
submitStruct.set_svctype(svcType.getBytes());
submitStruct.set_srcaddr(userID.getBytes());
submitStruct.set_ducount((byte)1);
submitStruct.set_msgmode((byte)1);
submitStruct.set_icpid(icpID.getBytes());
//submitStruct.set_feetype((byte)1);
//submitStruct.set_infofee(300);
byte[][] dstByte= {{0,0},{0,0}};
byte[] message;
for(int i=0;i
dstArray[i] += "\0"; //每个号码必须以byte 0结尾
dstByte[0] = dstArray[i].getBytes();
submitStruct.set_dstaddr(dstByte);
for(int j=0;j
message = messArray[j].getBytes();
submitStruct.set_msg((byte)15, message.length, message);
cmpp.cmpp_submit(connDesc, submitStruct);
ReadResponse();//Submit
ReadResponse();//Deliver
}
}
}catch(Exception e){
log.error("发送异常 "+ e);
System.exit(1);
}
////////////////////////////////////////////////////////
log.info("登出 ");
try{
cmpp.cmpp_logout(connDesc);
}catch(Exception e)
{
log.error("登出异常 "+ e);
}
}
}