You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					164 lines
				
				5.6 KiB
			
		
		
			
		
	
	
					164 lines
				
				5.6 KiB
			| 
								 
											3 years ago
										 
									 | 
							
								package com.ynxbd.common.action;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								import com.alibaba.fastjson.JSONObject;
							 | 
						||
| 
								 | 
							
								import com.ynxbd.common.action.base.BaseAction;
							 | 
						||
| 
								 | 
							
								import com.ynxbd.common.bean.sms.SmsTemplate;
							 | 
						||
| 
								 | 
							
								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 lombok.extern.slf4j.Slf4j;
							 | 
						||
| 
								 | 
							
								import org.apache.struts2.convention.annotation.Action;
							 | 
						||
| 
								 | 
							
								import org.apache.struts2.convention.annotation.Namespace;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								import java.sql.Array;
							 | 
						||
| 
								 | 
							
								import java.util.Arrays;
							 | 
						||
| 
								 | 
							
								import java.util.Map;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @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 "peis_report": // 体检报告
							 | 
						||
| 
								 | 
							
								                isFlag = SmsHelper.sendCode("SMS_164268358", tel, code);
							 | 
						||
| 
								 | 
							
								                break;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            case "user_bind": // 用户绑定
							 | 
						||
| 
								 | 
							
								                isFlag = SmsHelper.sendCode("SMS_164268358", 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": // 东软自助机
							 | 
						||
| 
								 | 
							
								                template = "SMS_173475681";
							 | 
						||
| 
								 | 
							
								                resultFlag = SmsHelper.sendCode(template, 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;
							 | 
						||
| 
								 | 
							
								        switch (callNo) {
							 | 
						||
| 
								 | 
							
								            case "na_admin": // 核酸结果上传逾期
							 | 
						||
| 
								 | 
							
								                isFlag = SmsHelper.send("SMS_260585044", tel, smsObj);
							 | 
						||
| 
								 | 
							
								                break;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            default:
							 | 
						||
| 
								 | 
							
								                return Result.error(ResultEnum.PARAM_CALL_NO_NOT_FOUND);
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        return Result.change(isFlag);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 |