做法1
我知道有两种方法啊 给你参考一下 第一:是获得移动、联通或电信的网关接口 这样就可以随意的免费接发短信 第二:设备,这个设备的原理是有一个可以插入多张手机卡,然后供应商会提供你的开发接口或者文档
今天在网上看到有人用java编写了发送短信的代码,原来以为是走什么样的方法,后来看了后知道就是在服务器上做好和短信服务商的接口后,java通过那个端口来控制发送的号码和内容。
估计这样群发短信就方便了,呵呵。
下面是代码,编译没问题,因为没有硬件环境所以没有办法运行(用到两个jar包:commons-net-1.4.1.jar和comm.jar):
import java.util.ArrayList;
import java.util.List;
import
java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.smslib.IOutboundMessageNotification;
import
org.smslib.OutboundMessage;
import org.smslib.Service;
import
org.smslib.Message.MessageEncodings;
import
org.smslib.modem.SerialModemGateway;
/**
* 短信发送类
*
*/
public class SMSUtil
{
public class
OutboundNotification implements IOutboundMessageNotification
{
public void process(String gatewayId, OutboundMessage msg)
{
System.out.println("Outbound handler called from Gateway: " + gatewayId);
System.out.println(msg);
}
}
public void sendSMS(String
mobilePhones,String content)
{
Service srv;
OutboundMessage
msg;
OutboundNotification outboundNotification = new
OutboundNotification();
srv = new Service();
SerialModemGateway
gateway = new SerialModemGateway("modem.com1", "COM1", 115200, "wavecom",
"9600");
gateway.setInbound(true);
gateway.setOutbound(true);
gateway.setSimPin("0000");
gateway.setOutboundNotification(outboundNotification);
srv.addGateway(gateway);
System.out.println("初始化成功,准备开启服务");
try
{
srv.startService();
System.out.println("服务启动成功");
String[] phones =
mobilePhones.split(",");
for(int
i=0;i<phones.length;i++)
{
msg = new
OutboundMessage(phones[i], content);//手机号码,和短信内容
msg.setEncoding(MessageEncodings.ENCUCS2);//这句话是发中文短信必须的
srv.sendMessage(msg);
System.out.println(phones[i]+" ==
"+content);
}
srv.stopService();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
SMSUtil util =
new SMSUtil(); //初始化
util.sendSMS("1590xxxxxxx","林春彬"); //输入电话号码和内容
}
}
做法3