| | |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springblade.common.config.SmsConfig; |
| | | import org.springblade.common.utils.HttpClientUtils; |
| | | import org.springblade.common.utils.SpringUtils; |
| | | import org.springblade.common.utils.UtilRandom; |
| | | import org.springblade.common.utils.sms.AlipaySignature; |
| | | import org.springblade.core.redis.cache.BladeRedis; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.modules.resource.entity.Sms; |
| | | import org.springblade.modules.resource.service.ISmsService; |
| | | 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.springblade.modules.smsRecord.entity.SmsRecordEntity; |
| | | import org.springblade.modules.smsRecord.service.ISmsRecordService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | |
| | | @Override |
| | | public Boolean smsSend(String phone) { |
| | | if (phone == null || phone.length() != 11) { |
| | | logger.error("手机号格式错误"); |
| | | return false; |
| | | } |
| | | |
| | | Sms serviceOne = iSmsService.getOne(Wrappers.<Sms>lambdaQuery().eq(Sms::getStatus, 2)); |
| | | if (serviceOne == null) { |
| | |
| | | params.put("type", type); |
| | | //创建人主键 |
| | | params.put("sop_create_by", serviceOne.getSmsCode()); |
| | | String s = null; |
| | | String result = null; |
| | | try { |
| | | s = testGet(params, "message.sop.differentMes", serviceOne); |
| | | JSONObject jsonObject = JSON.parseObject(s); |
| | | //短信发送记录 |
| | | saveSmsRecord(phone, serviceOne, code, content); |
| | | result = testGet(params, "message.sop.differentMes", serviceOne); |
| | | JSONObject jsonObject = JSON.parseObject(result); |
| | | JSONObject messageSopEqualsMesResponse = (JSONObject) jsonObject.get(MESSAGE_SOP_EQUALS_MES_RESPONSE_CODE); |
| | | if (messageSopEqualsMesResponse.get("code").equals(200)) { |
| | | // 将验证码存入redis |
| | |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 保存短信发送记录 |
| | | * |
| | | * @param phone 接收短信的手机号码 |
| | | * @param serviceOne 发送短信所使用的服务 |
| | | * @param code 短信中的验证码 |
| | | * @param content 短信内容,其中可能包含占位符"#P_1#"用于被验证码替换 |
| | | */ |
| | | private static void saveSmsRecord(String phone, Sms serviceOne, Integer code, String content) { |
| | | // 通过Spring工具类获取短信记录服务的实例 |
| | | ISmsRecordService smsRecordService = SpringUtils.getBean(ISmsRecordService.class); |
| | | // 创建一个新的短信记录实体 |
| | | SmsRecordEntity smsRecordEntity = new SmsRecordEntity(); |
| | | // 设置短信内容,将占位符"#P_1#"替换为验证码 |
| | | smsRecordEntity.setContent(content.replace("#P_1#", code.toString())); |
| | | // 设置手机号码 |
| | | smsRecordEntity.setPhone(phone); |
| | | // 设置短信模板ID |
| | | smsRecordEntity.setTemplateId(Long.valueOf(serviceOne.getTemplateId())); |
| | | // 设置创建用户ID,来自认证工具类 |
| | | smsRecordEntity.setCreateUser(AuthUtil.getUserId()); |
| | | // 保存短信记录实体 |
| | | smsRecordService.save(smsRecordEntity); |
| | | } |
| | | |
| | | public String testGet(Object bizContent, String method, Sms serviceOne) throws Exception { |
| | | |
| | | // 公共请求参数 |