示例#1
0
    /*
     * 状态报告
     *
     * 我们下发了submit订购成功消息后会上报一个状态
     * 订购成功:State=2  ErrorCode:100
     *
     *
     */
    private void report(Report command) {
      log.info("report:" + command.getErrorCode());
      log.info("report:" + command.getReportType());
      log.info("report:" + command.getReverse());
      log.info("report:" + command.getState());
      log.info("report:" + command.getSubmitSequenceNumber());
      log.info("report:" + command.getUserNumber());

      ReportModel req = new ReportModel();
      req.setErrorCode("" + command.getErrorCode());
      req.setReportType("" + command.getReportType());
      req.setReverse("" + command.getReverse());
      req.setState("" + command.getState());
      req.setSubmitSequenceNumber("" + command.getSubmitSequenceNumber());
      req.setUserNumber("" + command.getUserNumber());
      try {
        MongodbDAO.insertReport(req);
        // 第二步,更新订购状态,并通知portal已经订购成功
        MongodbDAO.updateMTReqStatus(
            command.getSubmitSequenceNumber(), Byte.toString(command.getErrorCode()));
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
示例#2
0
    /**
     * 处理联通上行信息
     *
     * @throws IOException 接收联通上行时有可能出现的IO流异常
     */
    private void executeMO() throws IOException {
      boolean isUnbind = false; // 收到unbind命令后,退出循环
      unicomIn = new DataInputStream(socket.getInputStream());
      spout = new DataOutputStream(socket.getOutputStream());
      // 读取联通发送来的字节流
      while (!isUnbind
          && !socket.isClosed()
          && socket.isConnected()
          && !socket.isInputShutdown()
          && !socket.isOutputShutdown()) {
        SGIPCommand command = null;
        try {
          command = read(unicomIn);
        } catch (IOException ex) {
          log.info("socket.getInputStream().available():" + socket.getInputStream().available());
          log.info("socket.isClosed:" + socket.isClosed()); // false
          log.info("socket.isConnected:" + socket.isConnected()); // true
          log.info("socket.isInputShutdown:" + socket.isInputShutdown()); // false
          log.info("socket.isOutputShutdown:" + socket.isOutputShutdown()); // false
          throw ex;
        }

        log.info(
            "【"
                + Thread.currentThread().getName()
                + "收到SMG "
                + SGIPCommandDefine.getCommandName(this.header.getCommandId())
                + "命令】,{长度="
                + command.header.getTotalmsglen()
                + "序列="
                + command.header.getSequenceNumber()
                + "}");

        switch (Bytes4ToInt(command.header.getCommandId())) {
            // -----------------------------------
          case 0x1: // 联通向SP发送的绑定命令
            log.info("收到SMG ->Bind命令");
            Bind bind = (Bind) command;
            log.info("LoginType:" + bind.getLoginType());
            log.info("LoginName:" + bind.getLoginName());
            log.info("LoginPassword:"******"smg loginfo:" + bind.getLoginName()+ "   " +
              // bind.getLoginPassword());
              // System.out.println("spcheck loginfo:"+ UnicomSPMonitor.smgLoginUserName + "   "+
              // UnicomSPMonitor.smgLoginPassword);
              if (bind.getLoginName().equals(UnicomSPMonitor.smgLoginUserName)
                  && bind.getLoginPassword().equals(UnicomSPMonitor.smgLoginPassword)) {
                log.info("SMG登陆SP,验证通过!");
                bindresp.setResult((byte) 0);
              } else {
                log.info("SMG登陆SP验证失败,SMG使用的用户名与密码与SP配置的参数不匹配!");
                bindresp.setResult((byte) 1);
              }
              bindresp.write(spout);
              log.info("Bind_Resp响应码:" + bindresp.getResult());
            }
            break;
            // ------------------------------------
          case 0x2: // 联通向SP发送的注销绑定命令
            // 响应
            log.info("收到SMG ->Unbind命令");
            UnbindResp resp = new UnbindResp(command.header.getUnicomSN());
            resp.write(spout);
            isUnbind = true;
            break;
            // ------------------------------------
          case 0x4: // 联通向SP上行一条用户短信
            log.info("收到SMG ->Deliver命令");
            Deliver deliver = (Deliver) command;
            log.info("SPNumber:" + deliver.getSPNumber());
            log.info("UserNumber:" + deliver.getUserNumber());
            log.info("MessageContent:" + deliver.getMessageContent());
            log.info("LinkID:" + deliver.getLinkID());
            // 收到响应
            DeliverResp deliverresp = new DeliverResp(command.header.getUnicomSN());
            deliverresp.setResult((byte) 0);
            deliverresp.write(spout);
            try {
              deliver(deliver); // 上行转发
            } catch (Exception ex) {
              ex.printStackTrace();
            }
            break;
            // -------------------------------------
          case 0x5: // 联通向SP报告之前一条MT的状态
            log.info("收到SMG ->Report命令");
            final Report report = (Report) command;
            log.info("ReportType:" + report.getReportType());
            log.info("UserNumber:" + report.getUserNumber());
            log.info("State:" + report.getState());
            log.info("ErrorCode:" + report.getErrorCode());
            // 返回响应
            ReportResp reportResp = new ReportResp(command.header.getUnicomSN());
            reportResp.setResult((byte) 0);
            reportResp.write(spout);
            if (report.getReportType() == 0) { // 对先前的一条Submit命令的状态报告
              try {
                report(report);
              } catch (Exception ex) {
                ex.printStackTrace();
              }
            }
            break;
            // --------------------------------------
          case 0x11: // 联通向SP报告一条手机用户的状态信息
            log.info("收到SMG ->UserRpt命令");
            UserRpt userRpt = (UserRpt) command;
            log.info("SPNumber:" + userRpt.getSPNumber());
            log.info("UserNumber:" + userRpt.getUserNumber());
            log.info("UserCondition:" + userRpt.getUserCondition());
            // 响应
            UserRptResp userRptresp = new UserRptResp(command.header.getUnicomSN());
            userRptresp.setResult((byte) 0);
            userRptresp.write(spout);

            break;
          default:
            log.error("error!! -->default:" + Bytes4ToInt(command.header.getCommandId()));
            break;
        }
      }

      log.info("socket.isClosed:" + socket.isClosed());
      log.info("socket.isClosed:" + socket.isConnected());
      log.info("socket.isInputShutdown:" + socket.isInputShutdown());
      log.info("socket.isOutputShutdown:" + socket.isOutputShutdown());
    }