SMPPService.java

本文介绍了一个名为SMPPService的Java类,该类用于通过设置系统ID、密码、短信中心IP地址、端口等属性来启动短信发送任务。SMPPService通过创建多个RequestWorker实例并启动它们来实现短信的批量发送。
package com.msp.smg;

public class SMPPService {
	private String sysId = "";
	private String syspwd = "";
	private String smscIP = "";
	private int smscPort = 0;
	private int smscRequestCount = 1;
	private String smscName="";
	
	public void setSmscName(String smscName) {
		this.smscName = smscName;
	}
	public SMPPService()
	{
		
	}
	public void setSmscIP(String smscIP) {
		this.smscIP = smscIP;
	}

	public void setSmscPort(int smscPort) {
		this.smscPort = smscPort;
	}

	public void startSender() {

		RequestWorker requestWorker;

		for (int i = 0; i < smscRequestCount; i++) {
			requestWorker = new RequestWorker();
			requestWorker.setSmscIP(smscIP);
			requestWorker.setSmscPort(smscPort);
			requestWorker.setSysId(sysId);
			requestWorker.setSyspwd(syspwd);
			requestWorker.start();
			System.out.println("smscName="+smscName+",index="+i);

		}

	}
	public void setSmscRequestCount(int smscRequestCount) {
		this.smscRequestCount = smscRequestCount;
	}

	public void setSysId(String sysId) {
		this.sysId = sysId;
	}

	public void setSyspwd(String syspwd) {
		this.syspwd = syspwd;
	}
}

 

// 发送心跳包 private void sendEnquireLink() { try { if (session != null && session.getSessionState().isBound()) { session.enquireLink(new EnquireLink(), 1000); // 1秒超时 } } catch (Exception e) { log.warning("EnquireLink failed: " + e.getMessage()); checkConnection(); // 立即触发连接检查 } }这个方法里面有问题 session.enquireLink(new EnquireLink(), 1000); 方法不存在 但是 在连接的时候 好像会自动维护心跳的 代码如下@Override public String connectAndBind(String host, int port, BindParameter bindParam, long timeout) throws IOException { log.debug("Connect and bind to {} port {}", host, port); if (getSessionState() != SessionState.CLOSED) { throw new IOException("Session state is not closed"); } conn = connFactory.createConnection(host, port); log.info("Connected from port {} to {}:{}", conn.getLocalPort(), conn.getInetAddress(), conn.getPort()); conn.setSoTimeout(getEnquireLinkTimer()); sessionContext.open(); try { in = new DataInputStream(conn.getInputStream()); out = conn.getOutputStream(); pduReaderWorker = new PDUReaderWorker(getQueueCapacity()); pduReaderWorker.start(); String smscSystemId = sendBind(bindParam.getBindType(), bindParam.getSystemId(), bindParam.getPassword(), bindParam.getSystemType(), bindParam.getInterfaceVersion(), bindParam.getAddrTon(), bindParam.getAddrNpi(), bindParam.getAddressRange(), timeout); sessionContext.bound(bindParam.getBindType(), bindParam.getInterfaceVersion()); enquireLinkSender = new EnquireLinkSender(); enquireLinkSender.start(); return smscSystemId; } catch (PDUException e) { log.error("Failed sending bind command", e); throw new IOException("Failed sending bind since some string parameter area invalid: " + e.getMessage(), e); } catch (NegativeResponseException e) { String message = "Receive negative bind response"; log.error(message, e); close(); throw new IOException(message + ": " + e.getMessage(), e); } catch (InvalidResponseException e) { String message = "Receive invalid bind response"; log.error(message, e); close(); throw new IOException(message + ": " + e.getMessage(), e); } catch (ResponseTimeoutException e) { String message = "Time out waiting for bind response"; log.error(message, e); close(); throw new IOException(message + ": " + e.getMessage(), e); } catch (IOException e) { log.error("I/O error occurred", e); close(); throw e; } }
最新发布
08-12
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值