我想用JAVA发送短信。谷歌搜索后,我发现SMPP协议将用于它,并偶然发现了下面的源代码。使用SMPP在JAVA中发送短信文本
public class SendSMS
{
public static void main(String[] args) throws Exception
{
SendSMS obj = new SendSMS();
SendSMS.sendTextMessage("<mobile number>");
}
private TimeFormatter tF = new AbsoluteTimeFormatter();
/*
* This method is used to send SMS to for the given MSISDN
*/
public void sendTextMessage(String MSISDN)
{
// bind param instance is created with parameters for binding with SMSC
BindParameter bP = new BindParameter(
BindType.BIND_TX,
"<user_name>",
"<pass_word>",
"<SYSTEM_TYPE>",
TypeOfNumber.UNKNOWN,
NumberingPlanIndicator.UNKNOWN,
null);
SMPPSession smppSession = null;
try
{
// smpp session is created using the bindparam and the smsc ip address/port
smppSession = new SMPPSession("<SMSC_IP_ADDRESS>", 7777, bP);
}
catch (IOException e1)
{
e1.printStackTrace();
}
// Sample TextMessage
String message = "This is a Test Message";
GeneralDataCoding dataCoding = new GeneralDataCoding(false, true,
MessageClass.CLASS1, Alphabet.ALPHA_DEFAULT);
ESMClass esmClass = new ESMClass();
try
{
// submitShortMessage(..) method is parametrized with necessary
// elements of SMPP submit_sm PDU to send a short message
// the message length for short message is 140
smppSession.submitShortMessage(
"CMT",
TypeOfNumber.NATIONAL,
NumberingPlanIndicator.ISDN,
"<MSISDN>",
TypeOfNumber.NATIONAL,
NumberingPlanIndicator.ISDN,
MSISDN,
esmClass,
(byte) 0,
(byte) 0,
tF.format(new Date()),
null,
new RegisteredDelivery(SMSCDeliveryReceipt.DEFAULT),
(byte) 0,
dataCoding,
(byte) 0,
message.getBytes());
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
但我的源代码遇到的问题是,它需要特定的一组像USER_NAME,pass_word,system_type,SMSC IP地址等参数,我没有任何的线索。我最近才知道SMPP协议,所以我不知道如何让这个代码工作,以完成我的手机发送短信的用例。那么有人可以帮我让这段代码工作,或者引导我到一个我可以学习如何做的地方?
您使用哪个库在网络上创建和发送SMPP包? – gkiko 2014-11-04 07:45:11
首先,您必须向任何SMS服务提供商进行注册,例如cellent等。他们将为您提供SMPP连接的所有细节。 – 2014-11-04 07:45:30
@gkiko我使用jsmpp – 2014-11-04 07:46:57