|  | @@ -1,5 +1,10 @@
 | 
	
		
			
				|  |  |  package com.miniframe.tools.msg;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import com.aliyun.dysmsapi20170525.Client;
 | 
	
		
			
				|  |  | +import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
 | 
	
		
			
				|  |  | +import com.aliyun.tea.TeaException;
 | 
	
		
			
				|  |  | +import com.aliyun.teautil.Common;
 | 
	
		
			
				|  |  | +import com.aliyun.teautil.models.RuntimeOptions;
 | 
	
		
			
				|  |  |  import com.miniframe.core.IniFileReader;
 | 
	
		
			
				|  |  |  import com.miniframe.core.exception.BusinessException;
 | 
	
		
			
				|  |  |  import com.miniframe.core.ext.UtilTools;
 | 
	
	
		
			
				|  | @@ -40,23 +45,26 @@ public class IdentifyingCodeUtil {
 | 
	
		
			
				|  |  |      public static String action;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      static {
 | 
	
		
			
				|  |  | -        IniFileReader ini = new IniFileReader("userconfig/sms.properties");
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        userid = ini.getStrValue("userid");//
 | 
	
		
			
				|  |  | -        account = ini.getStrValue("account");// 发送用户帐号 用户帐号,由系统管理员
 | 
	
		
			
				|  |  | -        password = ini.getStrValue("password");// 发送帐号密码 用户账号对应的密码
 | 
	
		
			
				|  |  | -        contentHead = ini.getStrValue("contentHead");// 发送内容 短信的内容头,内容需要UTF-8编码
 | 
	
		
			
				|  |  | -        contentHead = UtilTools.unicodeToUtf8(contentHead);// unicode转中文
 | 
	
		
			
				|  |  | -        sendTime = ini.getStrValue("sendTime");// 定时发送时间,为空表示立即发送,定时发送格式2010-10-24 09:08:10
 | 
	
		
			
				|  |  | -        action = ini.getStrValue("action"); // 发送任务命令 设置为固定的:send
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        requestConfig = RequestConfig.custom().setConnectTimeout(connectionTimeOut).setSocketTimeout(socketTimeOut).setConnectionRequestTimeout(connectionTimeOut).build();
 | 
	
		
			
				|  |  | +//        IniFileReader ini = new IniFileReader("sms.properties");
 | 
	
		
			
				|  |  | +//
 | 
	
		
			
				|  |  | +//        userid = ini.getStrValue("userid");//
 | 
	
		
			
				|  |  | +//        account = ini.getStrValue("account");// 发送用户帐号 用户帐号,由系统管理员
 | 
	
		
			
				|  |  | +//        password = ini.getStrValue("password");// 发送帐号密码 用户账号对应的密码
 | 
	
		
			
				|  |  | +//        contentHead = ini.getStrValue("contentHead");// 发送内容 短信的内容头,内容需要UTF-8编码
 | 
	
		
			
				|  |  | +//        contentHead = UtilTools.unicodeToUtf8(contentHead);// unicode转中文
 | 
	
		
			
				|  |  | +//        sendTime = ini.getStrValue("sendTime");// 定时发送时间,为空表示立即发送,定时发送格式2010-10-24 09:08:10
 | 
	
		
			
				|  |  | +//        action = ini.getStrValue("action"); // 发送任务命令 设置为固定的:send
 | 
	
		
			
				|  |  | +//        requestConfig = RequestConfig.custom().setConnectTimeout(connectionTimeOut).setSocketTimeout(socketTimeOut).setConnectionRequestTimeout(connectionTimeOut).build();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    private static String appkey = "LTAI5tEupgaUejG7mC6VHNF6";
 | 
	
		
			
				|  |  | -    private static String secret = "QlRvqFRc51OzANL4uYlLx7MKZUB2rx";
 | 
	
		
			
				|  |  | -    private static String url = "http://gw.api.taobao.com/router/rest";
 | 
	
		
			
				|  |  | +    	private static String appkey = "LTAI5tEupgaUejG7mC6VHNF6";
 | 
	
		
			
				|  |  | +	private static String secret = "QlRvqFRc51OzANL4uYlLx7MKZUB2rx";
 | 
	
		
			
				|  |  | +	private static String url = "http://gw.api.taobao.com/router/rest";
 | 
	
		
			
				|  |  | +//    private static String appkey = "24239810";
 | 
	
		
			
				|  |  | +//    private static String secret = "ea55a8bf52aa2672b802716e82a15dea";
 | 
	
		
			
				|  |  | +//    private static String url = "http://gw.api.taobao.com/router/rest";
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 生成 验证码
 | 
	
	
		
			
				|  | @@ -82,14 +90,14 @@ public class IdentifyingCodeUtil {
 | 
	
		
			
				|  |  |          // 生成验证码
 | 
	
		
			
				|  |  |          String code = createCode();
 | 
	
		
			
				|  |  |  //		String code = "111111";
 | 
	
		
			
				|  |  | -        code = "123456";//测试
 | 
	
		
			
				|  |  | -        String lastTimeKey = IDENTIFYINGCODE + UtilTools.getBaseCode() + "_" + tel + "_lasttime";
 | 
	
		
			
				|  |  | +        code="123456";//测试
 | 
	
		
			
				|  |  | +        String lastTimeKey = IDENTIFYINGCODE+UtilTools.getBaseCode() + "_" + tel+"_lasttime";
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        Long lastTime = (Long) UtilTools.getUserCache(lastTimeKey);
 | 
	
		
			
				|  |  | +        Long lastTime=  (Long) UtilTools.getUserCache(lastTimeKey);
 | 
	
		
			
				|  |  |          Long currentTime = XIDateTimeUtils.getNowTimeStampMs();
 | 
	
		
			
				|  |  | -        if (null != lastTime && currentTime - lastTime < 60000L) {
 | 
	
		
			
				|  |  | +        if(null != lastTime && currentTime-lastTime < 60000L) {
 | 
	
		
			
				|  |  |              throw new BusinessException("EB8000028");
 | 
	
		
			
				|  |  | -        } else {
 | 
	
		
			
				|  |  | +        }else {
 | 
	
		
			
				|  |  |              UtilTools.putUserCache(lastTimeKey, currentTime);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          // 唯一标识
 | 
	
	
		
			
				|  | @@ -112,8 +120,8 @@ public class IdentifyingCodeUtil {
 | 
	
		
			
				|  |  |          String ID = IDENTIFYINGCODE + UtilTools.getBaseCode() + "_" + tel; // 唯一标识
 | 
	
		
			
				|  |  |          String saveCode = (String) UtilTools.getUserCache(ID); // 获取上次保存
 | 
	
		
			
				|  |  |          logger.info("=========短信验证码============>start");
 | 
	
		
			
				|  |  | -        logger.info("系统存储的验证信息" + saveCode);
 | 
	
		
			
				|  |  | -        logger.info("用户输入的验证信息" + code);
 | 
	
		
			
				|  |  | +        logger.info("系统存储的验证信息"+saveCode);
 | 
	
		
			
				|  |  | +        logger.info("用户输入的验证信息"+code);
 | 
	
		
			
				|  |  |          logger.info("=========短信验证码============>end");
 | 
	
		
			
				|  |  |          if (saveCode == null) {
 | 
	
		
			
				|  |  |              return false;
 | 
	
	
		
			
				|  | @@ -121,18 +129,16 @@ public class IdentifyingCodeUtil {
 | 
	
		
			
				|  |  |          if (code == null) {
 | 
	
		
			
				|  |  |              return false;
 | 
	
		
			
				|  |  |          } // 删除保存在cache中的数据
 | 
	
		
			
				|  |  | -        if (saveCode.equals(code)) {
 | 
	
		
			
				|  |  | +        if(saveCode.equals(code)) {
 | 
	
		
			
				|  |  |              UtilTools.removeUserCache(ID);
 | 
	
		
			
				|  |  |              return true;
 | 
	
		
			
				|  |  | -        } else {
 | 
	
		
			
				|  |  | +        }else {
 | 
	
		
			
				|  |  |              return false;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 验证码使用一次后不删除,因此可以使用多次;  验证成功后删除
 | 
	
		
			
				|  |  | -     *
 | 
	
		
			
				|  |  |       * @param tel
 | 
	
		
			
				|  |  |       * @param code
 | 
	
		
			
				|  |  |       * @return
 | 
	
	
		
			
				|  | @@ -147,26 +153,35 @@ public class IdentifyingCodeUtil {
 | 
	
		
			
				|  |  |          if (code == null) {
 | 
	
		
			
				|  |  |              return false;
 | 
	
		
			
				|  |  |          } // 删除保存在cache中的数据
 | 
	
		
			
				|  |  | -        if (saveCode.equals(code)) {
 | 
	
		
			
				|  |  | +        if(saveCode.equals(code)) {
 | 
	
		
			
				|  |  |              UtilTools.removeUserCache(ID);
 | 
	
		
			
				|  |  |              return true;
 | 
	
		
			
				|  |  | -        } else {
 | 
	
		
			
				|  |  | +        }else {
 | 
	
		
			
				|  |  |              //是否添加验证码的时间限制
 | 
	
		
			
				|  |  |              //暂不需要,缓存默认30分钟过期
 | 
	
		
			
				|  |  |              return false;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    // 发送短信的
 | 
	
		
			
				|  |  | -    public static boolean sendSMSAli(String mobileNo, String text) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 报名到期提醒
 | 
	
		
			
				|  |  | +     *  尊敬的${name},第一届“智博杯”全国大学生仿真软件应用设计大赛报名,将于${duedate}正式截止;
 | 
	
		
			
				|  |  | +     * 请于报名截止前及时安排学生进行参赛。
 | 
	
		
			
				|  |  | +     * @param mobileNo
 | 
	
		
			
				|  |  | +     * @param name
 | 
	
		
			
				|  |  | +     * @param duedate
 | 
	
		
			
				|  |  | +     * @return
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public static boolean sendDS1(String mobileNo, String name,String duedate) {
 | 
	
		
			
				|  |  |          TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
 | 
	
		
			
				|  |  |          AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
 | 
	
		
			
				|  |  |          req.setExtend("123456");
 | 
	
		
			
				|  |  |          req.setSmsType("normal");
 | 
	
		
			
				|  |  | -        req.setSmsFreeSignName("前沿动力");
 | 
	
		
			
				|  |  | -        req.setSmsParamString("{code:" + text + "}");
 | 
	
		
			
				|  |  | +        req.setSmsFreeSignName("小犀智能");
 | 
	
		
			
				|  |  | +        req.setSmsParamString("{\"name\":\"" + name + "\"; \"duedate\":\""+duedate+"\"}");
 | 
	
		
			
				|  |  |          req.setRecNum(mobileNo);
 | 
	
		
			
				|  |  | -        req.setSmsTemplateCode("SMS_221636828");
 | 
	
		
			
				|  |  | +        req.setSmsTemplateCode("SMS_216427923");
 | 
	
		
			
				|  |  |          AlibabaAliqinFcSmsNumSendResponse rsp = null;
 | 
	
		
			
				|  |  |          try {
 | 
	
		
			
				|  |  |              rsp = client.execute(req);
 | 
	
	
		
			
				|  | @@ -182,7 +197,129 @@ public class IdentifyingCodeUtil {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 报名成功提醒
 | 
	
		
			
				|  |  | +     *  尊敬的${name},第一届“智博杯”全国大学生仿真软件应用设计大赛您参赛成功;请您尽快参与预演题目的学习!
 | 
	
		
			
				|  |  | +     * @param mobileNo
 | 
	
		
			
				|  |  | +     * @param name
 | 
	
		
			
				|  |  | +     * @return
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public static boolean sendDS2(String mobileNo, String name) {
 | 
	
		
			
				|  |  | +        TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
 | 
	
		
			
				|  |  | +        AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
 | 
	
		
			
				|  |  | +        req.setExtend("123456");
 | 
	
		
			
				|  |  | +        req.setSmsType("normal");
 | 
	
		
			
				|  |  | +        req.setSmsFreeSignName("小犀智能");
 | 
	
		
			
				|  |  | +        req.setSmsParamString("{\"name\":\"" + name + "\"}");
 | 
	
		
			
				|  |  | +        req.setRecNum(mobileNo);
 | 
	
		
			
				|  |  | +        req.setSmsTemplateCode("SMS_216427963");
 | 
	
		
			
				|  |  | +        AlibabaAliqinFcSmsNumSendResponse rsp = null;
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            rsp = client.execute(req);
 | 
	
		
			
				|  |  | +        } catch (ApiException e) {
 | 
	
		
			
				|  |  | +            logger.error("",e);
 | 
	
		
			
				|  |  | +            return false;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        // System.out.println(rsp.getBody());
 | 
	
		
			
				|  |  | +        if ((rsp != null) && (rsp.getResult() != null) && rsp.getResult().getSuccess()) {
 | 
	
		
			
				|  |  | +            return true;
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            return false;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 正式比赛消息提醒
 | 
	
		
			
				|  |  | +     *  尊敬的${name},第一届“智博杯”全国大学生仿真软件应用设计大赛,正式比赛将于${sdate}正式开始;
 | 
	
		
			
				|  |  | +     *  请您于${ledate}之前完成题目领取,${qedate}之前完成题目求解,${redate}之前完成题目报告上传。
 | 
	
		
			
				|  |  | +     * @param mobileNo
 | 
	
		
			
				|  |  | +     * @param name
 | 
	
		
			
				|  |  | +     * @return
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public static boolean sendDS3(String mobileNo, String name,String sdate,String ledate,String qedate,String redate) {
 | 
	
		
			
				|  |  | +        TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
 | 
	
		
			
				|  |  | +        AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
 | 
	
		
			
				|  |  | +        req.setExtend("123456");
 | 
	
		
			
				|  |  | +        req.setSmsType("normal");
 | 
	
		
			
				|  |  | +        req.setSmsFreeSignName("小犀智能");
 | 
	
		
			
				|  |  | +        req.setSmsParamString("{\"name\":\"" + name + "\"; "
 | 
	
		
			
				|  |  | +                + "\"sdate\":\""+sdate+"\"; "
 | 
	
		
			
				|  |  | +                + "\"ledate\":\""+ledate+"\"; "
 | 
	
		
			
				|  |  | +                + "\"qedate\":\""+qedate+"\"; "
 | 
	
		
			
				|  |  | +                + "\"redate\":\""+redate+"\""
 | 
	
		
			
				|  |  | +                +"}");
 | 
	
		
			
				|  |  | +        req.setRecNum(mobileNo);
 | 
	
		
			
				|  |  | +        req.setSmsTemplateCode("SMS_216372839");
 | 
	
		
			
				|  |  | +        AlibabaAliqinFcSmsNumSendResponse rsp = null;
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            rsp = client.execute(req);
 | 
	
		
			
				|  |  | +        } catch (ApiException e) {
 | 
	
		
			
				|  |  | +            logger.error("",e);
 | 
	
		
			
				|  |  | +            return false;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        // System.out.println(rsp.getBody());
 | 
	
		
			
				|  |  | +        if ((rsp != null) && (rsp.getResult() != null) && rsp.getResult().getSuccess()) {
 | 
	
		
			
				|  |  | +            return true;
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            return false;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 报告提交消息提醒
 | 
	
		
			
				|  |  | +     *  尊敬的${name},第一届“智博杯”全国大学生仿真软件应用设计大赛,报告提交将于${redate}正式截止;请您于报告提交截止期之前完成题目报告上传。
 | 
	
		
			
				|  |  | +     * @param mobileNo
 | 
	
		
			
				|  |  | +     * @param name
 | 
	
		
			
				|  |  | +     * @return
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public static boolean sendDS4(String mobileNo, String name,String redate) {
 | 
	
		
			
				|  |  | +        TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
 | 
	
		
			
				|  |  | +        AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
 | 
	
		
			
				|  |  | +        req.setExtend("123456");
 | 
	
		
			
				|  |  | +        req.setSmsType("normal");
 | 
	
		
			
				|  |  | +        req.setSmsFreeSignName("小犀智能");
 | 
	
		
			
				|  |  | +        req.setSmsParamString("{\"name\":\"" + name + "\"; "
 | 
	
		
			
				|  |  | +                + "\"redate\":\""+redate+"\""
 | 
	
		
			
				|  |  | +                +"}");
 | 
	
		
			
				|  |  | +        req.setRecNum(mobileNo);
 | 
	
		
			
				|  |  | +        req.setSmsTemplateCode("SMS_216427966");
 | 
	
		
			
				|  |  | +        AlibabaAliqinFcSmsNumSendResponse rsp = null;
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            rsp = client.execute(req);
 | 
	
		
			
				|  |  | +        } catch (ApiException e) {
 | 
	
		
			
				|  |  | +            logger.error("",e);
 | 
	
		
			
				|  |  | +            return false;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        // System.out.println(rsp.getBody());
 | 
	
		
			
				|  |  | +        if ((rsp != null) && (rsp.getResult() != null) && rsp.getResult().getSuccess()) {
 | 
	
		
			
				|  |  | +            return true;
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            return false;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    // 发送短信的
 | 
	
		
			
				|  |  | +    public static boolean sendSMSAli(String mobileNo, String text) throws Exception {
 | 
	
		
			
				|  |  | +        Client client = ShotMsgUtil.createClient("LTAI5tEupgaUejG7mC6VHNF6", "QlRvqFRc51OzANL4uYlLx7MKZUB2rx");
 | 
	
		
			
				|  |  | +        SendSmsRequest sendSmsRequest = new SendSmsRequest()
 | 
	
		
			
				|  |  | +                .setPhoneNumbers("19802329506")
 | 
	
		
			
				|  |  | +                .setSignName("前沿动力")
 | 
	
		
			
				|  |  | +                .setTemplateCode("SMS_221636828")
 | 
	
		
			
				|  |  | +                .setTemplateParam("{code:" + text + "}");
 | 
	
		
			
				|  |  | +        RuntimeOptions runtime = new RuntimeOptions();
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            // 复制代码运行请自行打印 API 的返回值
 | 
	
		
			
				|  |  | +            client.sendSmsWithOptions(sendSmsRequest, runtime);
 | 
	
		
			
				|  |  | +        } catch (TeaException error) {
 | 
	
		
			
				|  |  | +            // 如有需要,请打印 error
 | 
	
		
			
				|  |  | +            Common.assertAsString(error.message);
 | 
	
		
			
				|  |  | +        } catch (Exception _error) {
 | 
	
		
			
				|  |  | +            TeaException error = new TeaException(_error.getMessage(), _error);
 | 
	
		
			
				|  |  | +            // 如有需要,请打印 error
 | 
	
		
			
				|  |  | +            Common.assertAsString(error.message);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return true;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 验证发送短信是否成功
 | 
	
		
			
				|  |  |       *
 | 
	
	
		
			
				|  | @@ -211,8 +348,13 @@ public class IdentifyingCodeUtil {
 | 
	
		
			
				|  |  |  //		 String tel = "17180135310";
 | 
	
		
			
				|  |  |          // String tel = "18410269923";
 | 
	
		
			
				|  |  |          String tel = "19802329506";
 | 
	
		
			
				|  |  | -        boolean result = IdentifyingCodeUtil.sendSMSAli(tel, createCode());
 | 
	
		
			
				|  |  | -        System.out.println(result);
 | 
	
		
			
				|  |  | +		IdentifyingCodeUtil.sendSMSAli(tel,"123");
 | 
	
		
			
				|  |  | +//        boolean result = IdentifyingCodeUtil.sendDS1(tel, "黄先生","2021年5月30日");
 | 
	
		
			
				|  |  | +//		System.out.println(result);
 | 
	
		
			
				|  |  | +//		IdentifyingCodeUtil.sendDS1(tel, "黄先生","2021年5月30日");
 | 
	
		
			
				|  |  | +//		IdentifyingCodeUtil.sendDS2(tel, "黄先生");
 | 
	
		
			
				|  |  | +//		IdentifyingCodeUtil.sendds3(tel, "黄先生","2021年5月30日","2021年6月15日","2021年6月30日","2021年7月30日");
 | 
	
		
			
				|  |  | +//		IdentifyingCodeUtil.sendDS4(tel, "黄先生","2021年5月30日");
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 |