📄 smstest.java
字号:
/**
*
*/
package test.sms;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.xml.rpc.ServiceException;
import org.apache.axis.types.URI;
import org.apache.axis.types.URI.MalformedURIException;
import org.apache.log4j.Logger;
import test.ismp.IsmpSpEngineSoapBindingImpl;
import test.send.SendMessageEntity;
import cn.com.chinatelecom.www.schema.ctcc.common.v2_1.ChargingInformation;
import cn.com.chinatelecom.www.schema.ctcc.common.v2_1.EndReason;
import cn.com.chinatelecom.www.schema.ctcc.common.v2_1.PolicyException;
import cn.com.chinatelecom.www.schema.ctcc.common.v2_1.RequestSOAPHeader;
import cn.com.chinatelecom.www.schema.ctcc.common.v2_1.SimpleReference;
/**
* @author wangqijun
*
*/
public class SMSTest
{
/**
*
*/
public SMSTest()
{
// TODO 自动生成构造函数存根
}
/**
* 短信单元测试
*
* @param args
*/
public String sendSMS(SendMessageEntity sengMessageEntity)
{
String[] addresses = new String[] { sengMessageEntity.getAddresse() };
String senderAddress = sengMessageEntity.getSenderAddress();
String charging = sengMessageEntity.getCharging();
String ProductId = sengMessageEntity.getProductId();
// 消息
String message = sengMessageEntity.getMessage();
// 费率
String feecode = sengMessageEntity.getFeecode();
String linkId = sengMessageEntity.getLinkId();
String SpId = sengMessageEntity.getSpId();
String SpPassword = sengMessageEntity.getSpPassword();
String SAN = sengMessageEntity.getSAN();
// String smsURL = "http://58.53.194.143:9081/SendSmsService";
// String smsURL = "http://58.53.194.143:9081/SendSmsService";
String smsURL = "http://127.0.0.1:9080/SendSmsService";
//String smsURL = sengMessageEntity.getSmsURL();
String res = null;
try
{
// 目的地址
org.apache.axis.types.URI[] addressesuri = new org.apache.axis.types.URI[addresses.length];
for (int i = 0; i < addresses.length; i++)
{
String sss = addresses[i];
addressesuri[i] = new URI(sss);
}
// 状态报告标识
SimpleReference receiptRequest = new SimpleReference(new URI(
charging), "1", "333");
// 定义消息头对象
RequestSOAPHeader soapHeader = new RequestSOAPHeader();
String TimeStamp = getSysTime();
String temp = SpId + SpPassword + TimeStamp;
// 设置spid
soapHeader.setSpId(SpId);
// sp密码
soapHeader.setSpPassword(MD5Crypt(temp));
// 时间
soapHeader.setTimeStamp(TimeStamp);
// 产品id
soapHeader.setProductId(ProductId);
// 业务流水号,用于组合业务,可选
soapHeader.setTransactionId("");
// 交易结束标识,用于组合业务,可选
String transEnd = "0";
if (!transEnd.equals("") && (transEnd.length() > 0))
{
soapHeader.setTransEnd(EndReason.fromString(transEnd));
}
// 事务关联id,用于点播,可选
soapHeader.setLinkId(linkId);
// 业务订购地址,群发不填
soapHeader.setOA(new URI(addresses[0]));
// 付费地址,可选
//soapHeader.setFA(new URI(""));
// 是否群发
soapHeader.setMulticastMessaging(false);
// 业务接入码,可选
soapHeader.setSAN(SAN);
// 计费方案
ChargingInformation charging1 = new ChargingInformation("haha",
"yes", new java.math.BigDecimal(feecode), charging);
// 发送地址
URL url = new URL(smsURL);
SMSSendSmsLocator locator = new SMSSendSmsLocator();
SMSSendSmsStub service = locator.getSendSms(url);
// 发送
res = service.sendSms(addressesuri, senderAddress, charging1,
message, receiptRequest, soapHeader);
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (ServiceException e)
{
e.printStackTrace();
}
catch (RemoteException e)
{
e.printStackTrace();
}
catch (PolicyException e)
{
e.printStackTrace();
}
catch (cn.com.chinatelecom.www.schema.ctcc.common.v2_1.ServiceException e)
{
e.printStackTrace();
}
catch (MalformedURIException e)
{
e.printStackTrace();
}
System.out.println(res);
System.out.println(SpId);
return res;
}
/**
* 得到系统时间
*
* @return
*/
private static String getSysTime()
{
Date myDate = new Date(System.currentTimeMillis());
SimpleDateFormat sDateFormat = new SimpleDateFormat("MMddHHmmss");
return sDateFormat.format(myDate);
}
/**
* 二进制转字符串
*
* @param b
* @return
*/
public static String byte2hex(byte[] b)
{
String hs = "";
String stmp = "";
for (int n = 0; n < b.length; n++)
{
stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
if (stmp.length() == 1)
hs = hs + "0" + stmp;
else
hs = hs + stmp;
}
return hs.toUpperCase();
}
/**
* md5加密
*
* @param s
* @return
*/
public static String MD5Crypt(String s)
{
try
{
byte[] strTemp = s.getBytes();
MessageDigest mdTemp = MessageDigest.getInstance("MD5");
mdTemp.update(strTemp);
byte[] md = mdTemp.digest();
return byte2hex(md);
}
catch (Exception e)
{
return null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -