Search in sources :

Example 6 with MessageTemplate

use of com.itrus.portal.db.MessageTemplate in project portal by ixinportal.

the class DynamicCodeServiceImpl method sendCodeCert.

/**
 * 银行卡认证时,发送动态码
 *
 * @param mPhone
 *            手机
 * @param project
 *            项目id
 * @param smsType
 *            短信模版类型(DTM:动态码)
 *
 * @throws UserInfoServiceException
 */
public void sendCodeCert(String mPhone, Long project, String smsType) throws UserInfoServiceException {
    // 同一手机号指定时间内不能重发
    DynamicCodeExample dynamicCodeExample = new DynamicCodeExample();
    DynamicCodeExample.Criteria criteria = dynamicCodeExample.or();
    Calendar c = Calendar.getInstance();
    c.add(Calendar.SECOND, -RESEND_TIME);
    criteria.andMPhoneEqualTo(mPhone);
    // 发送时间大于等于当前时间减去1分钟
    criteria.andSendTimeGreaterThanOrEqualTo(c.getTime());
    List<DynamicCode> dynamicCodes = sqlSession.selectList("com.itrus.portal.db.DynamicCodeMapper.selectByExample", dynamicCodeExample);
    if (null != dynamicCodes && !dynamicCodes.isEmpty()) {
        throw new UserInfoServiceException("此手机号" + RESEND_TIME + "秒内不能连续发送,请稍后重试");
    }
    // 产生动态码
    DynamicCode code = genCode();
    if (null == code) {
        throw new UserInfoServiceException("发送动态码失败,请稍后重试");
    }
    // 发送动态码,获取发送的短信内容
    MessageTemplate messageTemplate = messageTemplateService.getMsgTemp(project, smsType);
    if (null == messageTemplate) {
        throw new UserInfoServiceException("未找到对应的短信模版,请联系管理员配置");
    }
    String content = messageTemplate.getMessageContent();
    content = content.replaceAll("code", code.getCode());
    if (smsType.equals("DTM")) {
        smsType = "动态码";
    }
    if (!smsSendService.sendDynamicCodeSmsCert(mPhone, content, smsType, project)) {
        // 发送失败
        throw new UserInfoServiceException("动态码发送失败,请联系管理员查看原因");
    } else {
        // 记录动态码之前将该手机号关联的有效验证码设置为无效
        dynamicCodeExample.clear();
        criteria = dynamicCodeExample.createCriteria();
        criteria.andMPhoneEqualTo(mPhone);
        criteria.andCodeStatusEqualTo(ComNames.DYNAMIC_CODE_ENROLL);
        DynamicCode updateCode = new DynamicCode();
        updateCode.setCodeStatus(ComNames.DYNAMIC_CODE_USED);
        updateCode.setFailTime(new Date());
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("record", updateCode);
        map.put("example", dynamicCodeExample);
        sqlSession.update("com.itrus.portal.db.DynamicCodeMapper.updateByExampleSelective", map);
        // 发送成功: 记录动态码
        Calendar calendar = Calendar.getInstance();
        code.setSendTime(calendar.getTime());
        // 失效时间为5分钟后
        calendar.add(Calendar.MINUTE, FAIL_TIME);
        // 设置失效时间
        code.setFailTime(calendar.getTime());
        code.setmPhone(mPhone);
        if (code.getId() == null) {
            sqlSession.insert("com.itrus.portal.db.DynamicCodeMapper.insert", code);
        } else {
            sqlSession.update("com.itrus.portal.db.DynamicCodeMapper.updateByPrimaryKey", code);
        }
    }
}
Also used : MessageTemplate(com.itrus.portal.db.MessageTemplate) DynamicCodeExample(com.itrus.portal.db.DynamicCodeExample) HashMap(java.util.HashMap) Calendar(java.util.Calendar) DynamicCode(com.itrus.portal.db.DynamicCode) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) Date(java.util.Date)

Example 7 with MessageTemplate

use of com.itrus.portal.db.MessageTemplate in project portal by ixinportal.

the class DynamicCodeServiceImpl method sendCodeJSSQYZ.

/**
 * 证书解锁申请验证码发送接口
 * @param mPhone
 * @param project
 * @param smsType
 * @throws UserInfoServiceException
 */
public void sendCodeJSSQYZ(String mPhone, Long project, String smsType) throws UserInfoServiceException {
    // 同一手机号指定时间内不能重发
    DynamicCodeExample dynamicCodeExample = new DynamicCodeExample();
    DynamicCodeExample.Criteria criteria = dynamicCodeExample.or();
    Calendar c = Calendar.getInstance();
    c.add(Calendar.SECOND, -RESEND_TIME);
    criteria.andMPhoneEqualTo(mPhone);
    // 发送时间大于等于当前时间减去1分钟
    criteria.andSendTimeGreaterThanOrEqualTo(c.getTime());
    List<DynamicCode> dynamicCodes = sqlSession.selectList("com.itrus.portal.db.DynamicCodeMapper.selectByExample", dynamicCodeExample);
    if (null != dynamicCodes && !dynamicCodes.isEmpty()) {
        throw new UserInfoServiceException("此手机号" + RESEND_TIME + "秒内不能连续发送,请稍后重试");
    }
    // 产生动态码
    DynamicCode code = genCode();
    if (null == code) {
        throw new UserInfoServiceException("发送解锁申请验证码失败,请稍后重试");
    }
    // 发送动态码,获取发送的短信内容
    MessageTemplate messageTemplate = messageTemplateService.getMsgTemp(project, smsType);
    if (null == messageTemplate) {
        throw new UserInfoServiceException("未找到对应的短信模版,请联系管理员配置");
    }
    String content = messageTemplate.getMessageContent();
    content = content.replaceAll("code", code.getCode());
    if (smsType.equals("JSSQYZ")) {
        smsType = "解锁申请验证";
    }
    if (!smsSendService.sendDynamicCodeSms(mPhone, content, smsType, project)) {
        // 发送失败
        throw new UserInfoServiceException("动态码发送失败,请联系管理员查看原因");
    } else {
        // 记录动态码之前将该手机号关联的有效验证码设置为无效
        dynamicCodeExample.clear();
        criteria = dynamicCodeExample.createCriteria();
        criteria.andMPhoneEqualTo(mPhone);
        criteria.andCodeStatusEqualTo(ComNames.DYNAMIC_CODE_ENROLL);
        DynamicCode updateCode = new DynamicCode();
        updateCode.setCodeStatus(ComNames.DYNAMIC_CODE_USED);
        updateCode.setFailTime(new Date());
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("record", updateCode);
        map.put("example", dynamicCodeExample);
        sqlSession.update("com.itrus.portal.db.DynamicCodeMapper.updateByExampleSelective", map);
        // 发送成功: 记录动态码
        Calendar calendar = Calendar.getInstance();
        code.setSendTime(calendar.getTime());
        // 失效时间为30分钟后
        calendar.add(Calendar.MINUTE, FAIL_TIME_30_MINUTE);
        // 设置失效时间
        code.setFailTime(calendar.getTime());
        code.setmPhone(mPhone);
        if (code.getId() == null) {
            sqlSession.insert("com.itrus.portal.db.DynamicCodeMapper.insert", code);
        } else {
            sqlSession.update("com.itrus.portal.db.DynamicCodeMapper.updateByPrimaryKey", code);
        }
    }
}
Also used : MessageTemplate(com.itrus.portal.db.MessageTemplate) DynamicCodeExample(com.itrus.portal.db.DynamicCodeExample) HashMap(java.util.HashMap) Calendar(java.util.Calendar) DynamicCode(com.itrus.portal.db.DynamicCode) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) Date(java.util.Date)

Example 8 with MessageTemplate

use of com.itrus.portal.db.MessageTemplate in project portal by ixinportal.

the class DynamicCodeServiceImpl method sendCode.

/**
 * 用户登录/注册时,发送动态码
 *
 * @param mPhone
 *            手机
 * @param project
 *            项目id
 * @param smsType
 *            短信模版类型(DTM:动态码)
 *
 * @throws UserInfoServiceException
 */
public void sendCode(String mPhone, Long project, String smsType) throws UserInfoServiceException {
    // 同一手机号指定时间内不能重发
    DynamicCodeExample dynamicCodeExample = new DynamicCodeExample();
    DynamicCodeExample.Criteria criteria = dynamicCodeExample.or();
    Calendar c = Calendar.getInstance();
    c.add(Calendar.SECOND, -RESEND_TIME);
    criteria.andMPhoneEqualTo(mPhone);
    // 发送时间大于等于当前时间减去1分钟
    criteria.andSendTimeGreaterThanOrEqualTo(c.getTime());
    List<DynamicCode> dynamicCodes = sqlSession.selectList("com.itrus.portal.db.DynamicCodeMapper.selectByExample", dynamicCodeExample);
    if (null != dynamicCodes && !dynamicCodes.isEmpty()) {
        throw new UserInfoServiceException("此手机号" + RESEND_TIME + "秒内不能连续发送,请稍后重试");
    }
    // 产生动态码
    DynamicCode code = genCode();
    if (null == code) {
        throw new UserInfoServiceException("发送动态码失败,请稍后重试");
    }
    // 发送动态码,获取发送的短信内容
    MessageTemplate messageTemplate = messageTemplateService.getMsgTemp(project, smsType);
    if (null == messageTemplate) {
        throw new UserInfoServiceException("未找到对应的短信模版,请联系管理员配置");
    }
    String content = messageTemplate.getMessageContent();
    content = content.replaceAll("code", code.getCode());
    if (smsType.equals("DTM")) {
        smsType = "动态码";
    } else if (smsType.equals("ZSBD")) {
        smsType = "证书绑定";
    }
    if (!smsSendService.sendDynamicCodeSms(mPhone, content, smsType, project)) {
        // 发送失败
        throw new UserInfoServiceException("动态码发送失败,请联系管理员查看原因");
    } else {
        // 记录动态码之前将该手机号关联的有效验证码设置为无效
        dynamicCodeExample.clear();
        criteria = dynamicCodeExample.createCriteria();
        criteria.andMPhoneEqualTo(mPhone);
        criteria.andCodeStatusEqualTo(ComNames.DYNAMIC_CODE_ENROLL);
        DynamicCode updateCode = new DynamicCode();
        updateCode.setCodeStatus(ComNames.DYNAMIC_CODE_USED);
        updateCode.setFailTime(new Date());
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("record", updateCode);
        map.put("example", dynamicCodeExample);
        sqlSession.update("com.itrus.portal.db.DynamicCodeMapper.updateByExampleSelective", map);
        // 发送成功: 记录动态码
        Calendar calendar = Calendar.getInstance();
        code.setSendTime(calendar.getTime());
        // 失效时间为5分钟后
        calendar.add(Calendar.MINUTE, FAIL_TIME);
        // 设置失效时间
        code.setFailTime(calendar.getTime());
        code.setmPhone(mPhone);
        if (code.getId() == null) {
            sqlSession.insert("com.itrus.portal.db.DynamicCodeMapper.insert", code);
        } else {
            sqlSession.update("com.itrus.portal.db.DynamicCodeMapper.updateByPrimaryKey", code);
        }
    }
}
Also used : MessageTemplate(com.itrus.portal.db.MessageTemplate) DynamicCodeExample(com.itrus.portal.db.DynamicCodeExample) HashMap(java.util.HashMap) Calendar(java.util.Calendar) DynamicCode(com.itrus.portal.db.DynamicCode) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) Date(java.util.Date)

Example 9 with MessageTemplate

use of com.itrus.portal.db.MessageTemplate in project portal by ixinportal.

the class PayController method sendsms.

@RequestMapping(value = "/sendsms/{id}/{phone}/{type}", produces = "text/html")
@ResponseBody
public String sendsms(@PathVariable("id") Long id, @PathVariable("phone") String phone, @PathVariable("type") String type) {
    Map param = new HashMap();
    param.put("id", id);
    // 管理员项目权限
    Long[] projectsOfAdmin = getProjectLongIdsOfAdmin();
    param.put("hasProjects", Arrays.asList(projectsOfAdmin));
    Map bill = sqlSession.selectOne("com.itrus.portal.db.BillMapper.selectByCondition", param);
    Bill b = sqlSession.selectOne("com.itrus.portal.db.BillMapper.selectByPrimaryKey", id);
    MessageTemplate messageTemplate = messageTemplateService.getMsgTemp(b.getProject(), type);
    if (null == messageTemplate) {
        return "发送短信失败,未找到对应的消息模版";
    }
    String content = messageTemplate.getMessageContent();
    if (StringUtils.isBlank(content) || content.indexOf("content") == -1) {
        return "发送短信失败,消息模版配置错误";
    }
    content = content.replaceAll("content", bill.get("pname").toString());
    smsSendService.sendSms(bill.get("m_phone").toString(), content, type.equals("WZF") ? "支付通知" : "支付异常通知", b.getProject(), null, b.getBillId());
    b.setIsSms(true);
    b.setSendTime(new Date());
    sqlSession.update("com.itrus.portal.db.BillMapper.updateByPrimaryKeySelective", b);
    return null;
}
Also used : MessageTemplate(com.itrus.portal.db.MessageTemplate) HashMap(java.util.HashMap) Bill(com.itrus.portal.db.Bill) Map(java.util.Map) HashMap(java.util.HashMap) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 10 with MessageTemplate

use of com.itrus.portal.db.MessageTemplate in project portal by ixinportal.

the class PsCourierController method sendMoreSmsFhtz.

/**
 * 发送属于快递配送的短信
 */
private Map<String, Object> sendMoreSmsFhtz(Long pcId) {
    Map<String, Object> retMap = new HashMap<String, Object>();
    // 0标识失败,1标识成功
    retMap.put("retCode", 0);
    try {
        CourierInfo ci = sqlSession.selectOne("com.itrus.portal.db.CourierInfoMapper.selectByPrimaryKey", pcId);
        if (null == ci) {
            retMap.put("retMsg", "发送短信失败,未找到对应的快递配送记录");
            return retMap;
        }
        Bill bill = sqlSession.selectOne("com.itrus.portal.db.BillMapper.selectByPrimaryKey", ci.getBill());
        CourierExample courierex = new CourierExample();
        Map<Long, Courier> couriermap = sqlSession.selectMap("com.itrus.portal.db.CourierMapper.selectByExample", courierex, "id");
        // 查找对应项目的消息模版:FHTZ
        MessageTemplate messageTemplate = messageTemplateService.getMsgTemp(bill.getProject(), "FHTZ");
        if (null == messageTemplate) {
            retMap.put("retMsg", "发送短信失败,未找到对应的快递配送消息模版");
            return retMap;
        }
        String content = messageTemplate.getMessageContent();
        if (StringUtils.isBlank(content) || content.indexOf("cItems") == -1 || content.indexOf("cId") == -1 || content.indexOf("cName") == -1) {
            retMap.put("retMsg", "发送短信失败,快递配送消息模版配置错误");
            return retMap;
        }
        String str = null;
        if (ci.getCourierItems() == 1) {
            str = "电子钥匙";
        }
        if (ci.getCourierItems() == 2) {
            str = "发票";
        }
        if (ci.getCourierItems() == 3) {
            str = "电子钥匙和发票";
        }
        content = content.replaceAll("cItems", str);
        content = content.replaceAll("cId", ci.getCourierId());
        content = content.replaceAll("cName", couriermap.get(ci.getCourier()).getCompanyName());
        Delivery delivery = sqlSession.selectOne("com.itrus.portal.db.DeliveryMapper.selectByPrimaryKey", bill.getDelivery());
        if (smsSendService.sendSms(delivery.getRvPhone(), content, "发货通知", bill.getProject(), bill.getUniqueId(), bill.getBillId())) {
            ci.setMessageSms(1);
            sqlSession.update("com.itrus.portal.db.CourierInfoMapper.updateByPrimaryKeySelective", ci);
            retMap.put("retCode", 1);
            retMap.put("retMsg", "发送短信成功");
        }
    } catch (Exception e) {
        e.printStackTrace();
        retMap.put("retMsg", "发送短信失败,errmsg:" + e.getMessage());
        return retMap;
    }
    return retMap;
}
Also used : HashMap(java.util.HashMap) CourierInfo(com.itrus.portal.db.CourierInfo) MessageTemplate(com.itrus.portal.db.MessageTemplate) Bill(com.itrus.portal.db.Bill) CourierExample(com.itrus.portal.db.CourierExample) Delivery(com.itrus.portal.db.Delivery) Courier(com.itrus.portal.db.Courier)

Aggregations

MessageTemplate (com.itrus.portal.db.MessageTemplate)18 Date (java.util.Date)10 HashMap (java.util.HashMap)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 UserInfoServiceException (com.itrus.portal.exception.UserInfoServiceException)6 Calendar (java.util.Calendar)5 DynamicCode (com.itrus.portal.db.DynamicCode)4 DynamicCodeExample (com.itrus.portal.db.DynamicCodeExample)4 ExtraBill (com.itrus.portal.db.ExtraBill)4 Project (com.itrus.portal.db.Project)4 Map (java.util.Map)4 Bill (com.itrus.portal.db.Bill)3 Enterprise (com.itrus.portal.db.Enterprise)3 MessageTemplateExample (com.itrus.portal.db.MessageTemplateExample)3 UserInfo (com.itrus.portal.db.UserInfo)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 ExtraProduct (com.itrus.portal.db.ExtraProduct)2 Courier (com.itrus.portal.db.Courier)1 CourierExample (com.itrus.portal.db.CourierExample)1 CourierInfo (com.itrus.portal.db.CourierInfo)1