金笛工业手机论坛  

返回   金笛工业手机论坛 > 金笛短信产品 > 产品资料专区

产品资料专区 金笛串口、USB口、网口短信终端、短信猫池、短信一体机等硬件产品资料;短信服务中间件等软件产品资料。

回复
 
LinkBack 主题工具 显示模式
旧 2009-11-30   #1 (permalink)
论坛管理员
 
admin 的头像
 
注册日期: 2009-06-30
帖子: 861
admin 的声望功能已被禁用
默认 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;
}
}
admin 当前在线   回复时引用此帖
回复

书签


当前查看此主题的会员: 1 (0 位会员和 1 位游客)
 
主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码
Trackbacks are 启用
Pingbacks are 启用
Refbacks are 启用



所有时间均为北京时间。现在的时间是 10:09


Powered by vBulletin® 版本 3.8.3
版权所有 ©2000 - 2024,Jelsoft Enterprises Ltd.