示例#1
0
  /** 发送电子邮件 */
  @RequestMapping(value = "/sendEmail")
  @ResponseBody
  public Object sendEmail() {
    PageData pd = new PageData();
    pd = this.getPageData();
    Map<String, Object> map = new HashMap<String, Object>();
    String msg = "ok"; // 发送状态
    int count = 0; // 统计发送成功条数
    int zcount = 0; // 理论条数

    String strEMAIL = Tools.readTxtFile(Const.EMAIL); // 读取邮件配置

    List<PageData> pdList = new ArrayList<PageData>();

    String toEMAIL = pd.getString("EMAIL"); // 对方邮箱
    String TITLE = pd.getString("TITLE"); // 标题
    String CONTENT = pd.getString("CONTENT"); // 内容
    String TYPE = pd.getString("TYPE"); // 类型
    String isAll = pd.getString("isAll"); // 是否发送给全体成员 yes or no

    String fmsg = pd.getString("fmsg"); // 判断是系统用户还是会员 "appuser"为会员用户

    if (null != strEMAIL && !"".equals(strEMAIL)) {
      String strEM[] = strEMAIL.split(",fh,");
      if (strEM.length == 4) {
        if ("yes".endsWith(isAll)) {
          try {
            List<PageData> userList = new ArrayList<PageData>();

            userList =
                "appuser".equals(fmsg)
                    ? appuserService.listAllUser(pd)
                    : userService.listAllUser(pd);

            zcount = userList.size();
            try {
              for (int i = 0; i < userList.size(); i++) {
                if (Tools.checkEmail(userList.get(i).getString("EMAIL"))) { // 邮箱格式不对就跳过
                  SimpleMailSender.sendEmail(
                      strEM[0],
                      strEM[1],
                      strEM[2],
                      strEM[3],
                      userList.get(i).getString("EMAIL"),
                      TITLE,
                      CONTENT,
                      TYPE); // 调用发送邮件函数
                  count++;
                } else {
                  continue;
                }
              }
              msg = "ok";
            } catch (Exception e) {
              msg = "error";
            }

          } catch (Exception e) {
            msg = "error";
          }
        } else {
          toEMAIL = toEMAIL.replaceAll(";", ";");
          toEMAIL = toEMAIL.replaceAll(" ", "");
          String[] arrTITLE = toEMAIL.split(";");
          zcount = arrTITLE.length;
          try {
            for (int i = 0; i < arrTITLE.length; i++) {
              if (Tools.checkEmail(arrTITLE[i])) { // 邮箱格式不对就跳过
                SimpleMailSender.sendEmail(
                    strEM[0],
                    strEM[1],
                    strEM[2],
                    strEM[3],
                    arrTITLE[i],
                    TITLE,
                    CONTENT,
                    TYPE); // 调用发送邮件函数
                count++;
              } else {
                continue;
              }
            }
            msg = "ok";
          } catch (Exception e) {
            msg = "error";
          }
        }
      } else {
        msg = "error";
      }
    } else {
      msg = "error";
    }
    pd.put("msg", msg);
    pd.put("count", count); // 成功数
    pd.put("ecount", zcount - count); // 失败数
    pdList.add(pd);
    map.put("list", pdList);
    return AppUtil.returnObject(pd, map);
  }
示例#2
0
  /** 发送短信 */
  @RequestMapping(value = "/sendSms")
  @ResponseBody
  public Object sendSms() {
    PageData pd = new PageData();
    pd = this.getPageData();
    Map<String, Object> map = new HashMap<String, Object>();
    String msg = "ok"; // 发送状态
    int count = 0; // 统计发送成功条数
    int zcount = 0; // 理论条数

    List<PageData> pdList = new ArrayList<PageData>();

    String PHONEs = pd.getString("PHONE"); // 对方邮箱
    String CONTENT = pd.getString("CONTENT"); // 内容
    String isAll = pd.getString("isAll"); // 是否发送给全体成员 yes or no
    String TYPE = pd.getString("TYPE"); // 类型 1:短信接口1   2:短信接口2
    String fmsg = pd.getString("fmsg"); // 判断是系统用户还是会员 "appuser"为会员用户

    if ("yes".endsWith(isAll)) {
      try {
        List<PageData> userList = new ArrayList<PageData>();

        userList =
            "appuser".equals(fmsg) ? appuserService.listAllUser(pd) : userService.listAllUser(pd);

        zcount = userList.size();
        try {
          for (int i = 0; i < userList.size(); i++) {
            if (Tools.checkMobileNumber(userList.get(i).getString("PHONE"))) { // 手机号格式不对就跳过
              if ("1".equals(TYPE)) {
                SmsUtil.sendSms1(userList.get(i).getString("PHONE"), CONTENT); // 调用发短信函数1
              } else {
                SmsUtil.sendSms2(userList.get(i).getString("PHONE"), CONTENT); // 调用发短信函数2
              }
              count++;
            } else {
              continue;
            }
          }
          msg = "ok";
        } catch (Exception e) {
          msg = "error";
        }

      } catch (Exception e) {
        msg = "error";
      }
    } else {
      PHONEs = PHONEs.replaceAll(";", ";");
      PHONEs = PHONEs.replaceAll(" ", "");
      String[] arrTITLE = PHONEs.split(";");
      zcount = arrTITLE.length;
      try {
        for (int i = 0; i < arrTITLE.length; i++) {
          if (Tools.checkMobileNumber(arrTITLE[i])) { // 手机号式不对就跳过
            if ("1".equals(TYPE)) {
              SmsUtil.sendSms1(arrTITLE[i], CONTENT); // 调用发短信函数1
            } else {
              SmsUtil.sendSms2(arrTITLE[i], CONTENT); // 调用发短信函数2
            }
            count++;
          } else {
            continue;
          }
        }
        msg = "ok";
      } catch (Exception e) {
        msg = "error";
      }
    }
    pd.put("msg", msg);
    pd.put("count", count); // 成功数
    pd.put("ecount", zcount - count); // 失败数
    pdList.add(pd);
    map.put("list", pdList);
    return AppUtil.returnObject(pd, map);
  }