| 
				 java短信开发包jsp调用示例(8口) 
 
			
			package com.sms.business;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.struts.action.ActionForm;
 import org.apache.struts.action.ActionForward;
 import org.apache.struts.action.ActionMapping;
 import org.apache.struts.actions.DispatchAction;
 import org.springframework.stereotype.Controller;
 
 import com.sms.util.MyOutboundNotification;
 
 import cn.sendsms.MessageEncodings;
 import cn.sendsms.MessagePriorities;
 import cn.sendsms.OutboundMessage;
 import cn.sendsms.SerialModemGateway;
 import cn.sendsms.Service;
 
 @Controller("/sendMessageDispatch")
 public class SendMessageDispatch extends DispatchAction {
 
 public ActionForward sendMessage(ActionMapping mapping, ActionForm form,
 HttpServletRequest request, HttpServletResponse response)
 throws Exception {
 response.setContentType("text/html");
 response.setCharacterEncoding("utf-8");
 
 System.out.println("-- now we start send sms .......");
 
 // 从页面获取要发送的手机号码和短信内容
 String phone = request.getParameter("phone");
 String content = request.getParameter("content");
 
 System.out.println("phone: " + phone);
 System.out.println("content : " + content);
 
 Service srv;
 OutboundMessage msg;
 MyOutboundNotification outboundNotification;
 
 boolean sendMessage = false;
 
 if (phone != null && phone.length() > 0 && content != null
 && content.length() > 0) {
 srv = new Service();
 outboundNotification = new MyOutboundNotification();
 
 SerialModemGateway gateway = new SerialModemGateway("jindi",
 "COM3", 115200, "wavecom", "M1306B", srv.getLogger());
 SerialModemGateway gateway4 = new SerialModemGateway("jindi",
 "COM4", 115200, "wavecom", "M1306B", srv.getLogger());
 SerialModemGateway gateway5 = new SerialModemGateway("jindi",
 "COM5", 115200, "wavecom", "M1306B", srv.getLogger());
 SerialModemGateway gateway6 = new SerialModemGateway("jindi",
 "COM6", 115200, "wavecom", "M1306B", srv.getLogger());
 SerialModemGateway gateway7 = new SerialModemGateway("jindi",
 "COM7", 115200, "wavecom", "M1306B", srv.getLogger());
 SerialModemGateway gateway8 = new SerialModemGateway("jindi",
 "COM8", 115200, "wavecom", "M1306B", srv.getLogger());
 SerialModemGateway gateway9 = new SerialModemGateway("jindi",
 "COM9", 115200, "wavecom", "M1306B", srv.getLogger());
 SerialModemGateway gateway10 = new SerialModemGateway("jindi",
 "COM10", 115200, "wavecom", "M1306B", srv.getLogger());
 
 gateway.setInbound(true);
 gateway.setOutbound(true);
 gateway.setSimPin("0000");
 gateway.setOutboundNotification(outboundNotification);
 
 gateway4.setInbound(true);
 gateway4.setOutbound(true);
 gateway4.setSimPin("0000");
 gateway4.setOutboundNotification(outboundNotification);
 
 gateway5.setInbound(true);
 gateway5.setOutbound(true);
 gateway5.setSimPin("0000");
 gateway5.setOutboundNotification(outboundNotification);
 
 gateway6.setInbound(true);
 gateway6.setOutbound(true);
 gateway6.setSimPin("0000");
 gateway6.setOutboundNotification(outboundNotification);
 
 gateway7.setInbound(true);
 gateway7.setOutbound(true);
 gateway7.setSimPin("0000");
 gateway7.setOutboundNotification(outboundNotification);
 
 gateway8.setInbound(true);
 gateway8.setOutbound(true);
 gateway8.setSimPin("0000");
 gateway8.setOutboundNotification(outboundNotification);
 
 gateway9.setInbound(true);
 gateway9.setOutbound(true);
 gateway9.setSimPin("0000");
 gateway9.setOutboundNotification(outboundNotification);
 
 gateway10.setInbound(true);
 gateway10.setOutbound(true);
 gateway10.setSimPin("0000");
 gateway10.setOutboundNotification(outboundNotification);
 
 srv.addGateway(gateway);
 // srv.addGateway(gateway4);
 // srv.addGateway(gateway5);
 // srv.addGateway(gateway6);
 // srv.addGateway(gateway7);
 // srv.addGateway(gateway8);
 // srv.addGateway(gateway9);
 // srv.addGateway(gateway10);
 
 srv.startService();
 
 String[] userPhones = phone.split(",");
 
 // 开始发送短信
 if (userPhones.length > 0) {
 for (String item : userPhones) {
 System.out.println("开始发送短信。。。。");
 if (item != null && item.length() > 0) {
 msg = new OutboundMessage(item, content);
 msg.setEncoding(MessageEncodings.ENCUCS2);
 
 msg.setPriority(MessagePriorities.HIGH);
 // 发送是否成功
 // 同步发送
 sendMessage = srv.sendMessage(msg);
 
 // 异步发送不成功
 // sendMessage = srv.queueMessage(msg);
 System.out.println("发送短信给: " + item + "成功 : "
 + sendMessage);
 }
 }
 }
 srv.stopService();
 }
 
 // jsp的写法
 // String forward = "failure";
 // if (sendMessage)
 // forward = "success";
 // return mapping.findForward(forward);
 // ext的写法
 String str = "{success:true}";
 response.getWriter().print(str);
 return null;
 }
 }
 |