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

📄 outsendtask.java

📁 短信系统SMS:支持普通短信、长短信和wap push短信的发送。
💻 JAVA
字号:
package com.casin.biz;

import com.ekun.biz.vo.OutsmsVO;
import com.ekun.common.sms.*;
import com.ekun.common.log.Logger;
import com.ekun.common.log.LoggerFactory;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Connection;
import com.ekun.common.db.DBManager;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * @author ekun
 * @version 1.0
 */
public class OutSendTask implements Runnable
{
  static Logger logger = LoggerFactory.getLogger(OutSendTask.class);
  //0:CMCC; 1:UNICOM
  private int taskType = 0;
  //当前扫描到的数据库记录ID
  private long currDBID = -9999;
  private static boolean allowRun = true;

  public OutSendTask(int linkType)
  {
    this.taskType = linkType;
  }

  public synchronized void run()
  {
    OutsmsDAO dao = new OutsmsDAO();
    Connection conn = null;
    PreparedStatement preparedStatement = null;
    ResultSet rs = null;

    while(allowRun)
    {
      String strWhere = this.getWhereStr();
      OutsmsVO[] vos = dao.filterByWhere(strWhere);
      if ((vos == null) || (vos.length <= 0))
      {
        try{ Thread.currentThread().sleep(3000);} catch(Exception ex){}
        continue;
      }
      logger.info("待发表扫描线程扫描到[" + vos.length +"]条数据待发送,当前过滤条件:"+strWhere);
      for(int i = 0; i < vos.length; i++)
      {
        try
        {
          SmsInfo smsInfo = new SmsInfo();
          smsInfo.DBMsgID = vos[i].getMSGID();
          smsInfo.DBMsgFrom = CmppLinker.getInstance().sendPort;
          smsInfo.DBMsgTo = vos[i].getACCEMOBI();
          smsInfo.DBfee_total = vos[i].getFEECODE();
          smsInfo.DBIsNeedStateReport = vos[i].getREPORTFLAG();
          smsInfo.DBfee_type = vos[i].getFEETYPE();
          smsInfo.DBServiceType = vos[i].getSERVICETYPE();

          conn = DBManager.getDBConn();
          String sql ="select hint,push from alarm_sms  where id=" + Integer.parseInt(vos[i].getMSGID());
          preparedStatement = conn.prepareStatement(sql);
          rs = preparedStatement.executeQuery();
          while(rs.next()){
            smsInfo.DBfee_number = vos[i].getACCEMOBI();
            currDBID = Long.parseLong(smsInfo.DBMsgID);
            int type = rs.getInt("push");
            if (type == 2)
            {
              String hint = rs.getString("hint");
              WAPPushSmsConstructor wpsc = new WAPPushSmsConstructor(smsInfo.DBMsgTo, hint, vos[i].getCONTENT()); //发送WAP信息;

              //短信超过140字节
              byte[][] result = wpsc.getMultiSMSBinaryData();
              for(int n=0; n<result.length; n++){
                smsInfo.DBMsgContent = result[n];
                smsInfo.smsType = 2;
                CmppLinker.getInstance().sendSubmit(smsInfo);
              }

              //短信没有超过140字节
              //smsInfo.DBMsgContent = wpsc.GetSMSBinaryData();
              //smsInfo.smsType = 2; //wap push over sms
              break;
            }
            if (type == 8)
            {
              smsInfo.DBMsgContent = vos[i].getCONTENT().getBytes();
              smsInfo.smsType = 8; //普通短信
              CmppLinker.getInstance().sendSubmit(smsInfo);
              break;
            }
          }

          //smsInfo.DBfee_number = vos[i].getACCEMOBI();
          //currDBID = Long.parseLong(smsInfo.DBMsgID);

          //CmppLinker.getInstance().sendSubmit(smsInfo);
        }catch(Exception ex)
        {
          logger.error("扫描待发表异常(或数据库连接异常),当前记录号:"+currDBID, ex);
        }
      }
    }
    logger.error("待发表扫描线程退出,类型:" + (taskType == 0 ? "CMPP" : "SGIP"));
  }

  private String getWhereStr()
  {
    StringBuffer sb = new StringBuffer();
    sb.append(" where  isdone=0 and ischeck=1 and id >").append(currDBID).
        append(" order by id limit 0, 200");
    return sb.toString();
  }
}

⌨️ 快捷键说明

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