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

📄 emppclient.java

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

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


public class EmppClient 
{
	private static LogManager logMan = new LogManager( EmppClient.class.getName() );
	
	public static EmppApi emppObject = new EmppApi();	
	public static MobileListener listener = new MobileListener( emppObject );
		
	private static String accountId = "106571090";	
	private static String password = "";	
	private static String srcId = "106571090";
	
	public static long interval = 1000L;//发送短信的时间间隔,单位:毫秒.	
	public static String msgContent = "初始:测试";
	
	/**
	 * 读取移动短信配置参数
	 * @return
	 */
	private static boolean init()
	{
		try 
		{
			accountId = IniUtil.getProfileString( "configsms.ini", "Mobile", 
					"Accountid", "10657109011111" );
			password = IniUtil.getProfileString( "configsms.ini", "Mobile", 
					"Password", "" );
			srcId = IniUtil.getProfileString( "configsms.ini", "Mobile", 
					"Srcid", "10657109011111" );
			Sample.interval = Long.valueOf( IniUtil.getProfileString( "configsms.ini", "Mobile", 
					"Interval", "1000" ) ).longValue();			
			Sample.msgContent = IniUtil.getProfileString( "configsms.ini", "Mobile", 
					"Message", "默认:测试" );
			
			logMan.printLogInfo( "读取移动配置成功" );
			return true;
		} 
		catch (IOException e) 
		{
			logMan.printLogInfo( "读取移动配置失败" );
			return false;
		}
	}
	
	/**
	 * 连接上海移动短信服务器
	 * @return
	 */
	public static boolean connect()
	{
		if( !init() )
		{
			return false;
		}
		try 
		{
			EMPPConnectResp response = emppObject.connect( "211.136.163.68", 9981, 
					accountId, password, listener );
			if( response.getStatus()==0 )
			{
				return true;
			}
			else
			{
				return false;
			}
		} 
		catch ( Exception e ) 
		{
			return false;
		} 
	}
	
	/**
	 * 发送移动短信
	 * @param mobiles
	 * @param content
	 * @return
	 */
	public static EMPPSubmitSMResp[] send( String[] mobiles, String content )
	{
		try
		{
			int sendRate = 1;
			if( interval<1000 )
			{
				sendRate = 1000/(int)interval;
			}
			EMPPSubmitSMResp[] response = emppObject.submitMsg( 
					content, mobiles, 
					"1", srcId, sendRate ) ;
			return response;
		}
		catch( Exception e )
		{
			logMan.printLogError( "发送移动短信异常:" + e.getMessage() );
			return null;
		}
	}

}

⌨️ 快捷键说明

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