| | |
| | | |
| | | @Override |
| | | public void send(String target, String ip) throws IOException { |
| | | String code = null; |
| | | if (chcekIp(ip)) {// 被封的ip直接返回 不操作 |
| | | return; |
| | | } |
| | | /** |
| | | * 短信发送签名 |
| | | */ |
| | | // String smsbao_sign = sysparaService.find("smsbao_sign").getValue(); |
| | | |
| | | // 短信发送文本[TEST]code is :{0} |
| | | String send_code_text; |
| | | |
| | | /** |
| | | * 是否每次发送的code都不一样 |
| | | */ |
| | | String code; |
| | | //是否每次发送的code都不一样 |
| | | boolean send_code_always_new = this.sysparaService.find("send_code_always_new").getBoolean(); |
| | | |
| | | Object object = this.identifyingCodeTimeWindowService.getAuthCode(target); |
| | |
| | | } else { |
| | | code = String.valueOf(object); |
| | | } |
| | | // log.info(MessageFormat.format("target:{0},code:{1},ip:{2}", target, code, ip)); |
| | | |
| | | String content = "[Orion X]"; |
| | | if (target.indexOf("@") == -1) { |
| | | |
| | | send_code_text = this.sysparaService.find("send_code_text").getSvalue(); |
| | | if (StringUtils.isNullOrEmpty(send_code_text)) { |
| | | logger.error("send_code_text 未配置"); |
| | | return; |
| | | } |
| | | /** |
| | | * 发送的短信接口类型 tiantian---天天---smsSendService--->>>>-- |
| | | * moduyun---摩杜云---smsSingleSender |
| | | */ |
| | | String send_code_type = this.sysparaService.find("send_code_type").getSvalue(); |
| | | if (StringUtils.isNullOrEmpty(send_code_type)) { |
| | | logger.error("send_code_type 未配置"); |
| | | return; |
| | | } |
| | | |
| | | if ("buka".equals(send_code_type)) { |
| | | bukasmsUtils.sendSms(target, MessageFormat.format(send_code_text, new Object[] { code })); |
| | | logger.info(MessageFormat.format("buka--target:{0},code:{1},ip:{2}", target, code, ip)); |
| | | } |
| | | |
| | | if ("GoTone".equals(send_code_type)) { |
| | | String response = goToneSmsUtils.sendSms(target, MessageFormat.format(send_code_text, new Object[] { code })); |
| | | logger.info(MessageFormat.format("GoTone--target:{0},code:{1},ip:{2}", target, code, ip)); |
| | | String responseWithChinese = StringEscapeUtils.unescapeJava(response); |
| | | System.out.println("中文发送结果: " + responseWithChinese); |
| | | } |
| | | |
| | | |
| | | if ("tiantian".equals(send_code_type)) { |
| | | smsSendService.send(target, MessageFormat.format(send_code_text, new Object[] { code })); |
| | | logger.info(MessageFormat.format("tiangtian--target:{0},code:{1},ip:{2}", target, code, ip)); |
| | | } |
| | | |
| | | if("eex".equalsIgnoreCase(send_code_type)){ |
| | | String format = MessageFormat.format(send_code_text, new Object[]{code}); |
| | | String apiKey = "5PUIQ2KvNDeC6XfuS0Bl8g=="; |
| | | String apiSecret = "5981db6ff1f94264a88d8ead7b90c93e"; |
| | | String send_url = "https://api.i51sms.com/outauth/verifCodeSend"; |
| | | Date date = new Date(); |
| | | SimpleDateFormat dateFormat= new SimpleDateFormat("yyyyMMddHHmmss"); |
| | | |
| | | Map<String,Object> param = new HashMap<>(); |
| | | param.put("apikey",apiKey); |
| | | param.put("timestamp",dateFormat.format(date)); |
| | | param.put("sign", DigestUtils.md5Hex(apiKey+dateFormat.format(date)+apiSecret)); |
| | | param.put("mobile",target); |
| | | param.put("content",format); |
| | | String s = HttpHelper.sendPostHttpSMS(send_url, param, true); |
| | | } |
| | | |
| | | // else if ("moduyun".equals(send_code_type)) { |
| | | // // -- 摩杜云短信签名的Id--accesskey,secretkey,signId,templateId |
| | | // String send_code_moduyun = this.sysparaService.find("send_code_moduyun").getValue(); |
| | | // String[] send_code_moduyun_parts = send_code_moduyun.split(","); |
| | | // List<String> params = new ArrayList<String>(); |
| | | // params.add(code); |
| | | // String strh_code = ""; |
| | | // strh_code = target.substring(0, 2); |
| | | // if ("86".equals(strh_code)) { |
| | | // try { |
| | | // smsSingleSender.send(0, "86", target.substring(2, target.length()), send_code_moduyun_parts[2], |
| | | // send_code_moduyun_parts[3], params, "", send_code_moduyun_parts[0], |
| | | // send_code_moduyun_parts[1]); |
| | | // log.info(MessageFormat.format("moduyun--target:{0},code:{1},ip:{2}", target, code, ip)); |
| | | // } catch (Exception e) { |
| | | // } |
| | | // } |
| | | // } |
| | | else if ("smsbao".equals(send_code_type)) { |
| | | smsSendService.send(target, MessageFormat.format(send_code_text, new Object[] { code })); |
| | | logger.info(MessageFormat.format("smsbao--target:{0},code:{1},ip:{2}", target, code, ip)); |
| | | } |
| | | |
| | | } else { |
| | | send_code_text = this.sysparaService.find("email_send_code_text").getSvalue(); |
| | | if (StringUtils.isNullOrEmpty(send_code_text)) { |
| | | logger.error("email_send_code_text 未配置"); |
| | | return; |
| | | } |
| | | /** |
| | | * 邮件 |
| | | */ |
| | | //emailSendService.sendEmail(target, content, MessageFormat.format(send_code_text, new Object[] { code })); |
| | | // 调用示例 |
| | | Map<String, Object> model = new HashMap<>(); |
| | | model.put("code", code); |
| | | emailSendService.sendEmail(target, content, "verification_email.ftl", model); |
| | | logger.info(MessageFormat.format("email--target:{0},code:{1},ip:{2}", target, code, ip)); |
| | | } |
| | | |
| | | emailSendService.sendEmail(target,null, code); |
| | | logger.info(MessageFormat.format("email--target:{0},code:{1},ip:{2}", target, code, ip)); |
| | | this.identifyingCodeTimeWindowService.putAuthCode(target, code); |
| | | System.out.println("获取验证码:" + target + "---" + code); |
| | | CodeLog codeLog = new CodeLog(); |
| | | codeLog.setTarget(target); |
| | | codeLog.setLog("发送地址:" + target + ",验证码:" + code + ",ip地址:" + ip); |
| | | codeLog.setCreateTime(new Date()); |
| | | codeLogService.save(codeLog); |
| | | } |
| | | |
| | | /** |
| | | * 返回true:ip已被封, false:ip正常 |
| | | * |
| | | * @param ip |
| | | * @return |
| | | */ |
| | | private boolean chcekIp(String ip) { |
| | | String check_send_count = sysparaService.find("send_code_check_ip").getSvalue(); |
| | | if (!"true".equals(check_send_count)) |
| | | return false;// 不为1时 未开启,直接返回false不做处理 |
| | | if (blacklistIpTimeWindow.getBlackIp(ip) != null) |
| | | return true;// ip被封,不发送 |
| | | |
| | | if (sendCountTimeWindow.getIpSend(ip) != null) { |
| | | Integer count = ipCache.get(ip); |
| | | count++; |
| | | if (count >= 30) {// 从ip发送第一条开始 |
| | | blacklistIpTimeWindow.putBlackIp(ip, ip); |
| | | ipCache.remove(ip); |
| | | sendCountTimeWindow.delIpSend(ip); |
| | | return true; |
| | | } else { |
| | | ipCache.put(ip, count++); |
| | | } |
| | | |
| | | } else { |
| | | ipCache.put(ip, 1); |
| | | sendCountTimeWindow.putIpSend(ip, ip); |
| | | } |
| | | return false; |
| | | |
| | | } |
| | | |
| | | } |