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

📄 sample.java

📁 上海移动通信企信通客户端接口例程,采用Empp API函数
💻 JAVA
字号:

import java.math.BigInteger;
import java.util.ArrayList;

import com.wondertek.esmp.esms.empp.EMPPSubmitSMResp;

public class Sample {
	
	private static boolean isConnect = false;
	
	private static LogManager logMan = new LogManager( Sample.class.getName() );

	private static ArrayList destMobileList = new ArrayList();
	
	public static String msgContent = "测试";
	
	public static long interval = 1000L;//发送短信时间间隔,单位:毫秒。
	
	public Sample()
	{
		new SendThread();
		logMan.printLogInfo( "移动短信程序已运行" );
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) 
	{	
		String mobiles = TypeConverter.getTxtString( "mobilephone.txt" );
		String[] mobileList = mobiles.split( "\n" );
				
		isConnect = EmppClient.connect();
		
		if( isConnect )
		{
			logMan.printLogInfo( "连接上海移动短信服务器成功" );			
		}
		else
		{
			logMan.printLogInfo( "连接上海移动短信服务器失败" );
		}
		
		for( int i=0;i<mobileList.length;i++ )
		{
			String one = mobileList[i] ;
			destMobileList.add( one );
		}
		
		logMan.printLogInfo( "有" + destMobileList.size() + "条短信等待发送" );
		
		logMan.printLogInfo( "待发短信的内容为:{" + msgContent + "}" );
		
		new Sample();
		
	}
	
	/**
	 * 内部发送线程
	 * @author lenovo
	 *
	 */
	class SendThread extends Thread
	{
		public SendThread()
		{
			super();
			this.start();
		}
		
		public void run()
		{
			while( true )
			{
				if( destMobileList.size()>0 )
				{	
					String mobile = (String)destMobileList.get(0);//单发模式
					
					EMPPSubmitSMResp[] emppResponse = EmppClient.send( new String[]{ mobile }, msgContent );
					String temp = "";
					for( int i=0;i<emppResponse.length;i++ )
					{
						temp += "emppresp.result=" + emppResponse[i].getResult() 
							+ ",emppresp.seqid=" + emppResponse[i].getSequenceNumber()
							+ ",emppresp.msgid=" + new BigInteger( fiterBinaryZero(emppResponse[i].getMsgId()) ).toString() + ".";
					}
					logMan.printLogInfo( "一条移动短信已提交到网关(mobile=" + mobile 
							+ ",message=" + msgContent 
							+ "," + temp);
					
					destMobileList.remove( mobile );
				}
				try 
				{
					Thread.sleep( interval );//控制发送速度
				} 
				catch (InterruptedException e) 
				{
					logMan.printLogError( e.getMessage() );
				}
			}
		}
	}
	
	 /**
	  * 过滤二进制的0
	  * @param bytes
	  * @return
	  */
	 private static byte[] fiterBinaryZero(byte[] bytes) 
	 {
	        byte[] returnBytes = new byte[8];
	        for (int i = 0; i < 8; i++) 
	        {
	            returnBytes[i] = bytes[i];
	        }
	        return returnBytes;
	 }

}

⌨️ 快捷键说明

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