📄 pushtest.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.CMPPActiveTest;
import com.bci.cmpp.message.CMPPActiveTestResp;
import com.bci.cmpp.message.CMPPProtocolException;
import com.bci.cmpp.message.CMPPSubmit;
import com.bci.cmpp.message.CMPPSubmitResp;
import com.bci.cmpp.util.*;
public class PushTest extends CMPPAPIExample {
private Log logger = LogFactory.getLog(PushTest.class);
public PushTest() {
}
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.setFeeUserType(3);
sm.setFeeType("01");
sm.setFeeCode("000000");
sm.setRegistered(1);
sm.setFeeTerminalId("13981819849");
sm.setDestTerminalId("13981819849");
sm.setTpUdhi(1);
sm.setMsgCoding(0x04);
sm.setEncoding(BinaryEncoding.getInstance());
byte[] head = hexToBytes("0605040B8423F0DC0601AE02056A0045C60C03");
String url = "211.137.96.150:8080/12580/test.jsp";
byte[] ubody = url.getBytes();
String title = "测试WAPPUSH信息元素数据";
byte[] tbody = title.getBytes("UTF-8");
byte[] message = new byte[head.length + ubody.length + tbody.length
+ 6];
System.arraycopy(head, 0, message, 0, head.length);
System.arraycopy(ubody, 0, message, head.length, ubody.length);
message[head.length + ubody.length] = 0x00;
message[head.length + ubody.length + 1] = 0x01;
message[head.length + ubody.length + 2] = 0x03;
System.arraycopy(tbody, 0, message, head.length + ubody.length + 3,
tbody.length);
message[head.length + ubody.length + tbody.length + 3] = 0x00;
message[head.length + ubody.length + tbody.length + 4] = 0x01;
message[head.length + ubody.length + tbody.length + 5] = 0x01;
// System.out.println("sm_length=" + sm.getMessageLen());
sm.setMessage(message);
// 01|3|000000|10658225000443|13981819849|13880223354|4|0605040b3f23f0dc06013f02056a00453f0c033231312e3133372e39362e3135303a383038302f31323538302f746573742e6a7370000103e6b58be8af9557415050555348e4bfa1e681afe58583e7b4a0e695b0e68dae000101|1|1
// 01|3|000000|10658225000443|13981819849|13981819849|4|0605040b8423f0dc0601ae02056a0045c60c033231312e3133372e39362e3135303a383038302f31323538302f746573742e6a7370000103e6b58be8af9557415050555348e4bfa1e681afe58583e7b4a0e695b0e68dae000101|1|1
logger.info(sm.getFeeType() + "|" + sm.getFeeUserType() + "|"
+ sm.getFeeCode() + "|" + sm.getSourceAddr() + "|"
+ sm.getDestTerminalId()[0] + "|" + sm.getFeeTerminalId()
+ "|" + sm.getMsgCoding() + "|"
+ CMPPAPIExample.encodeHex(sm.getMessage()) + "|"
+ sm.getRegistered() + "|" + sm.getTpUdhi());
logger.info(CMPPAPIExample.encodeHex(sm.getBuffer()));
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 (Exception x) {
logger.info("An exception occurred.");
x.printStackTrace(System.err);
}
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/mtLog4j.properties");
PushTest st = new PushTest();
try {
st.configure("config/mtTest.properties");
st.execute();
} catch (ConfigurationException e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -