| | |
| | | import org.springblade.modules.sms.entity.SmsTemplateEntity; |
| | | import org.springblade.modules.sms.mapper.SmsTemplateMapper; |
| | | import org.springblade.modules.sms.service.ISmsSendService; |
| | | import org.springblade.modules.sms.service.ISmsTemplateService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | @Service |
| | | public class SmsSendServiceImpl extends ServiceImpl<SmsTemplateMapper, SmsTemplateEntity> implements ISmsSendService { |
| | | @Autowired |
| | | private BladeRedis redisTemplate; |
| | | private BladeRedis redisTemplate; |
| | | private static Logger logger = LoggerFactory.getLogger(SmsSendServiceImpl.class); |
| | | |
| | | // 确保这些字符串被适当地定义和管理 |
| | | public static final String SMS_VALIDATE_PHONE = "sms:validate:code:"; |
| | | public static final String SMS_VALIDATE_PHONE_NUM = "sms:validate:phone:"; |
| | | private static final String SMS_SEND_FAILED = "短信发送失败!"; |
| | | private static final String MESSAGE_SOP_EQUALS_MES_RESPONSE_CODE = "message_sop_equalsMes_response"; |
| | | private static final String SEND_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; |
| | | |
| | | // @Autowired |
| | | // private SmsConfig smsConfig; |
| | | |
| | | @Autowired |
| | | private ISmsService iSmsService; |
| | | |
| | | @Autowired |
| | | private ISmsTemplateService iSmsTemplateService; |
| | | |
| | | @Override |
| | | public Boolean smsSend(String phone) { |
| | | |
| | | Sms serviceOne = iSmsService.getOne(Wrappers.<Sms>lambdaQuery().eq(Sms::getSmsCode, "106575361457")); |
| | | Sms serviceOne = iSmsService.getOne(Wrappers.<Sms>lambdaQuery().eq(Sms::getStatus, 2)); |
| | | if (serviceOne == null) { |
| | | logger.error("未找到状态为2的Sms服务"); |
| | | return false; |
| | | } |
| | | SmsTemplateEntity smsTemplateEntity = iSmsTemplateService.getOne(Wrappers.<SmsTemplateEntity>lambdaQuery() |
| | | .eq(SmsTemplateEntity::getId, serviceOne.getTemplateId())); |
| | | if (smsTemplateEntity == null) { |
| | | logger.error("未找到对应的短信模板"); |
| | | return false; |
| | | } |
| | | |
| | | //发送的手机号 |
| | | List<Map> phonesList = new ArrayList<>(); |
| | | |
| | |
| | | //短信主题 |
| | | String subject = "对外接口不同内容发送-动态模板"; |
| | | //短信内容 |
| | | String content = "您正在验证投票操作,验证码:#P_1#。如非本人操作,则密码可能已泄露,建议立即修改密码或联系客服。"; |
| | | // String content = "尊敬的#P_1#,你得工资#P_2#,测试#P_3#"; |
| | | String content = smsTemplateEntity.getContent(); |
| | | //短信模板 |
| | | String template_id = null; |
| | | //发送时间 |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | SimpleDateFormat df = new SimpleDateFormat(SEND_TIME_FORMAT); |
| | | String send_time = df.format(new Date()); |
| | | //优先级,高级=5,中级=3,低级=1 |
| | | String priority = "1"; |
| | |
| | | params.put("sop_create_by", serviceOne.getSmsCode()); |
| | | String s = null; |
| | | try { |
| | | s = testGet(params, "message.sop.differentMes",serviceOne); |
| | | s = testGet(params, "message.sop.differentMes", serviceOne); |
| | | JSONObject jsonObject = JSON.parseObject(s); |
| | | JSONObject messageSopEqualsMesResponse = (JSONObject) jsonObject.get("message_sop_equalsMes_response"); |
| | | JSONObject messageSopEqualsMesResponse = (JSONObject) jsonObject.get(MESSAGE_SOP_EQUALS_MES_RESPONSE_CODE); |
| | | if (messageSopEqualsMesResponse.get("code").equals(200)) { |
| | | // 将验证码存入redis |
| | | redisTemplate.setEx(SMS_VALIDATE_PHONE + phone, code, 300L); |
| | |
| | | return true; |
| | | } |
| | | } catch (Exception e) { |
| | | logger.error("短信发送失败!", e); |
| | | logger.error(SMS_SEND_FAILED, e); |
| | | throw new RuntimeException(e); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | public String testGet(Object bizContent, String method,Sms serviceOne) throws Exception { |
| | | public String testGet(Object bizContent, String method, Sms serviceOne) throws Exception { |
| | | |
| | | // 公共请求参数 |
| | | Map<String, String> params = new HashMap<String, String>(); |