package com.ynxbd.common.action; import com.alibaba.fastjson.JSONObject; import com.ynxbd.common.action.base.BaseAction; import com.ynxbd.common.bean.enums.HospEnum; import com.ynxbd.common.bean.sms.SmsTempEnum; import com.ynxbd.common.bean.sms.SmsTemplate; import com.ynxbd.common.bean.wxMessage.WaitReg; import com.ynxbd.common.dao.RegisterDao; import com.ynxbd.common.helper.common.CodeHelper; import com.ynxbd.common.helper.common.SmsHelper; import com.ynxbd.common.result.Result; import com.ynxbd.common.result.ResultEnum; import com.ynxbd.wx.config.WeChatConfig; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.digest.DigestUtils; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Namespace; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * @Author wsq * @Date 2020/12/11 15:20 * @Copyright @ 2020 云南新八达科技有限公司 All rights reserved. */ @Slf4j @Namespace("/api/sms") public class SmsAction extends BaseAction { /** * 根据患者查询体检报告 */ @Action("smsCode") public Result smsCode(String tel, String callNo) { if (tel == null || tel.length() != 11) { return Result.error(ResultEnum.SMS_TEL_ERROR); } if (callNo == null) { return Result.error(ResultEnum.SMS_CALL_NO_ERROR); } // 判断是否60s内重复请求 SmsTemplate sms = SmsHelper.isRepeat(tel); if (sms != null) { String message = sms.getCountDown() == null ? "" : sms.getCountDown() + "s"; return Result.error(ResultEnum.SMS_SEND_REPEAT, sms, ResultEnum.SMS_SEND_REPEAT.makeMessage(message)); } boolean isFlag = false; // 生成验证码 String code = CodeHelper.getRandomCode(6); switch (callNo) { case "general": // 通用模板【您的验证码${code},您正进行身份验证,该验证码5分钟内有效,请勿泄漏于他人!】 isFlag = SmsHelper.sendCode(SmsTempEnum.SMS_257021489, tel, code); break; case "peis_report": // 体检报告【您的校验码:${code},您正在查看体检报告,感谢您的支持!】 isFlag = SmsHelper.sendCode(SmsTempEnum.SMS_164268358, tel, code); break; case "user_bind": // 用户绑定 isFlag = SmsHelper.sendCode(SmsTempEnum.SMS_257021489, tel, code); break; default: log.info("[短信]调用码无效"); break; } return isFlag ? Result.success() : Result.error(ResultEnum.SMS_SEND_ERROR); } @Action("codeVerify") public Result codeVerify(String tel, String code) { log.info("[短信验证]tel={}, code={}", tel, code); if (tel == null || tel.length() != 11) { return Result.error(ResultEnum.SMS_TEL_ERROR); } if (code == null || code.length() > 6 || code.length() < 4) { return Result.error(ResultEnum.SMS_CODE_ERROR); } if (SmsHelper.codeVerify(tel, code, false)) { return Result.success(); } return Result.error(ResultEnum.SMS_CODE_VERIFY_ERROR); // 短信验证码失效或错误 } /** * 协助第三方发送短信 */ @Action("smsHelp") public Result smsHelp(String tel, String code, String callNo) { log.info("[第三方短信发送] tel={}, code={}, callNo={}", tel, code, callNo); if (callNo == null) { return Result.error(ResultEnum.SMS_CALL_NO_ERROR); } if (tel == null || tel.length() != 11) { return Result.error(ResultEnum.SMS_TEL_ERROR); } if (code == null || code.length() > 6 || code.length() < 4) { return Result.error(ResultEnum.SMS_CODE_ERROR); } // 判断是否60s内重复请求 SmsTemplate sms = SmsHelper.isRepeat(tel); if (sms != null) { String message = sms.getCountDown() == null ? "" : sms.getCountDown() + "s"; return Result.error(ResultEnum.SMS_SEND_REPEAT, sms, ResultEnum.SMS_SEND_REPEAT.makeMessage(message)); } String template; boolean resultFlag = false; switch (callNo) { case "dhzzyyy001": // 东软自助机 resultFlag = SmsHelper.sendCode(SmsTempEnum.SMS_173475681, tel, code); break; case "xbd_code_001": resultFlag = SmsHelper.sendCode(SmsTempEnum.SMS_257021489, tel, code); break; default: log.info("调用码无效"); break; } return resultFlag ? Result.success() : Result.error(ResultEnum.SMS_SEND_ERROR); } /** * [短信]模板推送 * * @param tel 电话号码 * @param callNo 调用码 * @param temParamsJson 请求参数 */ @Action("smsTemplateHelp") public Result smsTemplateHelp(String tel, String callNo, String temParamsJson) { log.info("[模板短信]发送 tel={}, callNo={}, temParamsJson={}", tel, callNo, temParamsJson); if (tel == null || callNo == null || temParamsJson == null) { return Result.error(ResultEnum.PARAM_IS_DEFECT); } JSONObject smsObj; try { smsObj = JSONObject.parseObject(temParamsJson); } catch (Exception e) { return Result.error(ResultEnum.PARAM_IS_INVALID); } // 判断是否60s内重复请求 SmsTemplate sms = SmsHelper.isRepeat(tel); if (sms != null) { String message = sms.getCountDown() == null ? "" : sms.getCountDown() + "s"; return Result.error(ResultEnum.SMS_SEND_REPEAT, sms, ResultEnum.SMS_SEND_REPEAT.makeMessage(message)); } boolean isFlag = false; switch (callNo) { case "na_admin": // 核酸结果上传逾期 // isFlag = SmsHelper.send(SmsTempEnum.SMS_260585044, tel, smsObj); break; default: return Result.error(ResultEnum.PARAM_CALL_NO_NOT_FOUND); } return Result.isOK(isFlag); } /** * [短信]模板推送 * * @param sys 系统编码[CRM] * @param tel 电话号码 * @param templateCode 模板编码 * @param temParamsJson 模板参数 */ @Action("smsTemplate") public Result smsTemplate(String sys, String tel, String templateCode, String temParamsJson) { tel = SmsHelper.decodeRSA(tel); templateCode = SmsHelper.decodeRSA(templateCode); log.info("[{}][模板短信]发送 tel={}, templateCode={}, temParamsJson={}", sys, tel, templateCode, temParamsJson); if (sys == null || tel == null || templateCode == null || temParamsJson == null) { return Result.error(ResultEnum.PARAM_IS_DEFECT); } JSONObject smsJson = SmsHelper.parseJson(temParamsJson); if (smsJson == null) { return Result.error(ResultEnum.PARAM_IS_INVALID); } // 判断是否60s内重复请求 SmsTemplate sms = SmsHelper.isRepeat(tel); if (sms != null) { String message = sms.getCountDown() == null ? "" : sms.getCountDown() + "s"; return Result.error(ResultEnum.SMS_SEND_REPEAT, sms, ResultEnum.SMS_SEND_REPEAT.makeMessage(message)); } boolean isResult = SmsHelper.send(templateCode, tel, smsJson); return Result.isOK(isResult); } // /** // * [短信]模板推送测试 // * // * @param sys 系统编码[CRM] // * @param tel 电话号码 // * @param templateCode 模板编码 // * @param temParamsJson 模板参数 // */ // @Action("smsTemplateTest") // public Result smsTemplateTest(String sys, String tel, String templateCode, String temParamsJson) { // log.warn("[{}][模板短信测试]入参 tel={}, templateCode={}, temParamsJson={}", sys, tel, templateCode, temParamsJson); // // String deTel = SmsHelper.decodeRSA(tel); // String deTemplateCode = SmsHelper.decodeRSA(templateCode); // log.warn("[{}][模板短信测试]解密参数 deTel={}, deTemplateCode={}, temParamsJson={}", sys, deTel, deTemplateCode, temParamsJson); // Map data = new HashMap<>(); // // data.put("tel", tel); // data.put("templateCode", templateCode); // // data.put("deTel", deTel); // data.put("deTemplateCode", deTemplateCode); // return Result.success(data); // } /** * 德宏州中医院每日候诊推送 * * @param startTime 检索推送开始时间 * @param endTime 检索推送结束时间 * @return 推送结果 */ @Action("todayRegSmS") public Result TodayRegSms(String startTime, String endTime) { log.info("[候诊推送短信] begTime={}, endTime={}", startTime, endTime); List waitRegs = new RegisterDao().selectTodayRegRecord(startTime, endTime); for (WaitReg waitReg : waitRegs) { Map sms = new HashMap<>(); sms.put("time", waitReg.getRegDate() + " " + waitReg.getBegTime() + "-" + waitReg.getEndTime()); sms.put("deptName", waitReg.getDeptName()); sms.put("doctorName", waitReg.getDoctName()); sms.put("address", waitReg.getAddress()); sms.put("minute", "15"); sms.put("signView", "个人中心"); sms.put("hospTel", "0692-2991794"); log.info("[候诊推送短信]sendResult-{},tel-{},sms-{}", SmsHelper.send(SmsTempEnum.SMS_475780750, waitReg.getTel(), sms), waitReg.getTel(), sms); } return Result.success(); } /** * 天助平台短信推送(红河州第一人民医院(影像报告使用) * 备注:2025-05-07 只有放射科会发短信 * * @param tel 电话号码 * @param content 内容[网址] * @return 返回发送结果 */ @Action("danMiSms") public Result danMiSms(String tel, String content) { log.info("[天助平台短信]tel={}, content={}", tel, content); if (tel == null || content == null) { return Result.error(ResultEnum.PARAM_IS_INVALID); } return Result.success(SmsHelper.sendDanMi("1000000002608", tel, content)); } /** * [HIS发送短信] * * @param callNo 调用码 * @param tel 电话 * @param temParamsJson 内容json * @param sign 验证签名 */ @Action("smsHis") public Result smsHis(String callNo, String tel, String temParamsJson, String sign) { log.info("[天助平台-旦米短信]callNo={}, tel={}, temParamsJson={}, sign={}", callNo, tel, temParamsJson, sign); if (callNo == null || tel == null || temParamsJson == null || sign == null) { return Result.error(ResultEnum.PARAM_IS_INVALID); } String key = "xbd_sms"; String md5 = DigestUtils.md5Hex(callNo + tel + key).toUpperCase(); if (!md5.equals(sign)) { return Result.error(ResultEnum.SIGN_ERROR); } JSONObject smsJson = SmsHelper.parseJson(temParamsJson); if (smsJson == null) { return Result.error(ResultEnum.PARAM_IS_INVALID); } switch (callNo) { case "dept_kq": // 口腔科复诊通知 {p1:姓名,p2:日期,p3:时间,p4:科室} if (WeChatConfig.APP_ID.equals(HospEnum.红河州人民医院.APP_ID)) { String template = "尊敬的${p1},温馨提醒:您上次${p2}就诊时预约了${p3}到${p4}复诊,无法就诊请提前改期。"; return Result.isOK(SmsHelper.sendTemplateDanMi(tel, template, smsJson)); } return Result.isOK(SmsHelper.send("SMS_508510318", tel, smsJson)); case "pacs": // pacs if (WeChatConfig.APP_ID.equals(HospEnum.红河州人民医院.APP_ID)) { String template = "${p1}"; return Result.isOK(SmsHelper.sendTemplateDanMi(tel, template, smsJson)); } return Result.error("[阿里云短信模板未配置]"); default: return Result.error(ResultEnum.PARAM_CALL_NO_NOT_FOUND); } } }