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

📄 ismsconnectorbean.java

📁 国内很牛的软件公司花费两年半开发的用EJB3开发的代码,采用STRUTS和EJB3,目前系统进行第二版.所以拿出来共享
💻 JAVA
字号:
package com.ufmobile.platform.mstreet.sms;

import java.sql.CallableStatement;
import java.sql.Connection;
import javax.ejb.Stateless;
import javax.sql.DataSource;

import com.ufmobile.common.UFMobileUUID;
import com.ufmobile.common.param.PublicParam;
import com.ufmobile.platform.ejb.BaseFunction;

import com.ufmobile.platform.log.RunTimeLogger;

import com.ufmobile.platform.mstreet.sms.ISMSConnector;

public @Stateless class ISMSConnectorBean implements ISMSConnector {
	/*
	 * 计算短信发送时需实际占用条数
	 * 
	 * @param strSmsContent   短信内容
	 * @return	int  返回实际条数
	 * */
	public static int GetSMSCount(String strSmsContent)
	{   
		int nSmsLength=strSmsContent.length();
		int nPerSmsLength=159;
		
		for (int i=0; i<nSmsLength; i++)
	    {
	        char c = strSmsContent.charAt(i);
			if (c > 255) 
			{
				nPerSmsLength=70;			
				break;
			}
	    }
		int ret = nSmsLength/nPerSmsLength+((nSmsLength%nPerSmsLength)==0?0:1);
		if(ret > 1){
			nPerSmsLength -= 5;//(1/2)
			ret = nSmsLength/nPerSmsLength+((nSmsLength%nPerSmsLength)==0?0:1);
		}
		return ret;
		
	}
	/*
	 * 计算WAPPUSH发送时需实际占用的条数


	 * 
	 * @param  strSubject WAPPUSH 文本
	 * @param  strURL  WAPPUSH 链接
	 * @return	返回WAPPUSH实际条数
	 * */
	public static int GetWapPushCount(String strSubject,String strURL)
	{
		int nAsciiCount=0;
		int nWideCharCount=0; 
		
		for (int i=0; i<strSubject.length(); i++)
	    {
	        char c = strSubject.charAt(i);
			if (c > 255) 
			{
				nWideCharCount++;
			}else
			{
				nAsciiCount++;
			}
	    }
		
		for (int i=0; i<strURL.length(); i++)
	    {
	        char c = strURL.charAt(i);
			if (c > 255) 
			{
				nWideCharCount++;
			}else
			{
				nAsciiCount++;
			}
	    }
		
		
		int nSumLen=(nAsciiCount+nWideCharCount*3)*2+34;
		
		return nSumLen/140+((nSumLen%140)==0?0:1);
		
	}
	public String sendSms(int systemId, String smsContent, String url, int operationType, int applicantType, int applicant, String[] mobileList) {	
		UFMobileUUID uuid = UFMobileUUID.randomUUID();
		String strBatchNo = uuid.toString();					
		//计数短信条数并调用商街提供接口进行扣费

		int smsType = 0;
		if(url != null && url.trim().compareTo("") != 0)//wappush
		{
			smsType = 1;
		}		
		/*
		 * 调用存储过程(完成分条存储)
		 * */			
		StringBuffer strMobileList = new StringBuffer();
		int nCurCount=0;	
		String retPort = "";
		String retSeqNo = "";
		for(int n = 0; n < mobileList.length; n++)
		{
			if(nCurCount > 0)
			{
				strMobileList.append(",");				
			}
			strMobileList.append(mobileList[n]);
			nCurCount++;
			
			if(nCurCount >= 250 || n == mobileList.length-1)
			{
				//调用存储过程  要保证只生成一个strBatchNo
				/////////				
				Connection conn = null;
				try
				{									
					conn = BaseFunction.getDataSource(systemId).getConnection();
					CallableStatement cstmt = conn.prepareCall("{call pro_Sms_SendSms(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
					cstmt.setString(1, smsContent);
					cstmt.setInt(2,nCurCount);
					cstmt.setString(3,strMobileList.toString());
					cstmt.setInt(4, operationType);
					cstmt.setInt(5, 0);
					cstmt.setInt(6, applicantType);
					cstmt.setInt(7, applicant);
					cstmt.setInt(8, smsType);
					cstmt.setString(9, url);
					cstmt.setString(10, "");
					cstmt.setInt(11, 6);
					cstmt.setString(12, "");
					cstmt.setString(13, retPort);
					cstmt.setString(14, retSeqNo);
					cstmt.setString(15, strBatchNo);
					cstmt.setString(16, "");
					cstmt.setInt(17, systemId);
					cstmt.registerOutParameter(13, java.sql.Types.VARCHAR);
					cstmt.registerOutParameter(14, java.sql.Types.VARCHAR);
					cstmt.registerOutParameter(15, java.sql.Types.VARCHAR);
	
					cstmt.executeQuery();
	
					retPort = cstmt.getString(13);
					retSeqNo = cstmt.getString(14);
					strBatchNo = cstmt.getString(15);							
					
					cstmt.close();
				}catch(Exception e)
				{
					RunTimeLogger.error(ISMSConnectorBean.class, "MtSubmit", e);			
					strBatchNo = null;
				}
				finally{
					if(conn != null){
						try{
							conn.close();
						}
						catch(Exception e){
							RunTimeLogger.error(this, e.getMessage(), e);
						}
					}
				}
				strMobileList.delete(0, strMobileList.length());
				nCurCount=0;
			}
			
		}
		return strBatchNo;
	}

}

⌨️ 快捷键说明

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