⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 binarysmstest.java

📁 短信发送的程序。JAVA编写
💻 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 BinarySMSTest extends CMPPAPIExample {

	private Log logger = LogFactory.getLog(BinarySMSTest.class);

	public BinarySMSTest() {
	}

	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("13981819849");
			sm.setDestTerminalId("13981819849");
			sm.setFeeUserType(3);
			sm.setFeeType("01");
			sm.setTpUdhi(1);
			sm.setMsgCoding(0xF6);
			sm.setEncoding(BinaryEncoding.getInstance());
			byte[] message = hexToBytes("72027000006D6C6BC000100166078072316B7B4F60098072316211522B8D7009804E0D8981723162110d8053554EBA5E8A53CC4EBA623F058051AC81F309805E7F5C9B4E4B604B"
					+ "09805FFD71364E4B95F40f8090A34E4872314F604E3A4EC04E480f804F607ED96211591A5C1165F695F40b805982679C6CA167094F60");
			// System.out.println("sm_length=" + sm.getMessageLen());
			sm.setMessage(message);
			logger.info(CMPPAPIExample.encodeHex(sm.getMessage()));
			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/log4j.properties");
		BinarySMSTest st = new BinarySMSTest();
		try {
			st.configure("config/mtConf.properties");
			st.execute();
		} catch (ConfigurationException e) {
			e.printStackTrace();
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -