📄 synctransmitterexample.java
字号:
package com.bci.cmpp.example;
import java.io.IOException;
import java.net.SocketTimeoutException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.PropertyConfigurator;
import com.bci.cmpp.AlreadyBoundException;
import com.bci.cmpp.BadCommandIDException;
import com.bci.cmpp.CMPPConstants;
import com.bci.cmpp.Connection;
import com.bci.cmpp.UnsupportedOperationException;
import com.bci.cmpp.message.*;
import com.bci.cmpp.util.*;
public class SyncTransmitterExample extends CMPPAPIExample {
private Log logger = LogFactory.getLog(SyncTransmitterExample.class);
public SyncTransmitterExample() {
}
public void execute() {
try {
// 发送短信 使用同步模式
while (!isConnected())
reConnect(Connection.TRANSMITTER, false);
// Submit a simple message
CMPPSubmit sm = (CMPPSubmit) myConnection
.newInstance(CMPPConstants.CMPP_SUBMIT);
// sm.setSequenceNum(0);
sm.setSpCode(this.spCode);
sm.setServiceId(this.serviceId);
sm.setSourceAddr(this.sourceAddr);
sm.setFeeTerminalId(getProperty("feeTerm"));
sm.setDestTerminalId(getProperty("destTerm"));
sm.setFeeUserType(Integer.parseInt(getProperty("feeUserType")));
sm.setRegistered(1);
sm.setFeeType(getProperty("feeType"));
sm.setFeeCode(getProperty("feeCode"));
// sm.setEncoding(UCS2Encoding.getInstance());
sm.setMessage(UCS2Encoding.getInstance().encodeString(
"发送测试,费用0.00元。"));
// sm.setMsgText("发送测试,费用0.00元。");
sm.setMsgCoding(24);
// sm.setMessage("注意:关于短信群发的问题,若SP对于群发消息不要求状态报告的回送时".getBytes());
// logger.info(encodeHex(sm.getBytes()));
// for(int i = 0;i<10000;i++){
logger.info(Thread.currentThread().getId() + ".send text msg:"
+ sm.getFeeType() + "|" + sm.getFeeUserType() + "|"
+ sm.getFeeCode() + "|" + sm.getSourceAddr() + "|"
+ sm.getDestTerminalId()[0] + "|" + sm.getFeeTerminalId()
+ "|" + sm.getMsgCoding() + "|" + sm.getMsgText() + "|"
+ sm.getRegistered() + "|" + sm.getTpUdhi());
CMPPSubmitResp smr = (CMPPSubmitResp) myConnection.sendRequest(sm);
if (smr.getCommandStatus() == 0)
logger.info("Submitted message ID: " + smr.getMsgIdStr());
else
logger.info("Submit message returned error:"
+ smr.getCommandStatus());
// }
} catch (UnsupportedOperationException e) {
logger.info("An exception occurred." + e.getMessage());
e.printStackTrace();
} catch (SocketTimeoutException e) {
logger.info("An exception occurred." + e.getMessage());
e.printStackTrace();
} catch (AlreadyBoundException e) {
logger.info("An exception occurred." + e.getMessage());
e.printStackTrace();
} catch (CMPPProtocolException e) {
logger.info("An exception occurred." + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
logger.info("An exception occurred." + e.getMessage());
e.printStackTrace();
} catch (BadCommandIDException e) {
logger.info("An exception occurred." + e.getMessage());
e.printStackTrace();
}
/*
* while (true) { while (!isConnected())
* reConnect(Connection.TRANSMITTER, false); // 每30秒发一次ActiveTest try {
* Thread.sleep(1000 * 30); CMPPActiveTest at = (CMPPActiveTest)
* myConnection .newInstance(CMPPConstants.CMPP_ACTIVE_TEST);
* CMPPActiveTestResp atr = (CMPPActiveTestResp) myConnection
* .sendRequest(at); if (atr != null && atr.getCommandStatus() == 0)
* logger.info("active test seq:" + atr.getSequenceNum()); } catch
* (BadCommandIDException e) { e.printStackTrace(); disConnect(); }
* catch (SocketTimeoutException e) { e.printStackTrace(); disConnect(); }
* catch (AlreadyBoundException e) { e.printStackTrace(); disConnect(); }
* catch (CMPPProtocolException e) { e.printStackTrace(); disConnect(); }
* catch (UnsupportedOperationException e) { e.printStackTrace();
* disConnect(); } catch (IOException e) { e.printStackTrace();
* disConnect(); } catch (InterruptedException e) { e.printStackTrace();
* disConnect(); } }
*/
}
public static void main(String[] arg) {
PropertyConfigurator.configure("config/log4j.properties");
SyncTransmitterExample st = new SyncTransmitterExample();
try {
st.configure("config/mtTest.properties");
st.execute();
} catch (ConfigurationException e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -