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);
}
}
}
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);
}
}
}
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);
}
}
}
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;
}
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;
}
Aggregations