From ca1ad791b7b7b04e57db6bd4fb93f0c1066a9f99 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期四, 24 九月 2020 18:31:23 +0800 Subject: [PATCH] 淘口令格式兼容 --- fanli/src/main/java/com/yeshi/fanli/service/impl/user/SMSServiceImpl.java | 223 ++++++++++++++++++++++++++++--------------------------- 1 files changed, 113 insertions(+), 110 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/SMSServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/SMSServiceImpl.java index 0fc72c7..908b11e 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/SMSServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/SMSServiceImpl.java @@ -16,130 +16,133 @@ @Service public class SMSServiceImpl implements SMSService { - @Resource - private SMSHistoryMapper smsHistoryMapper; + @Resource + private SMSHistoryMapper smsHistoryMapper; - @Resource - private RedisManager redisManager; + @Resource + private RedisManager redisManager; - @Override - public String sendLoginVCode(SystemEnum system, String phone, int codeLength) throws SMSException { - boolean limit = redisManager.isSmsFrequencyLimit(phone, SMSHistory.TYPE_LOGIN); - if (limit) - throw new SMSException(1001, "璇疯繃60绉掑啀璇�"); + @Override + public String sendLoginVCode(SystemEnum system, String phone, int codeLength) throws SMSException { + boolean limit = redisManager.isSmsFrequencyLimit(phone, SMSHistory.TYPE_LOGIN); + if (limit) + throw new SMSException(1001, "璇疯繃60绉掑啀璇�"); - String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.emptyKey, StringUtil.Md5("sms-login-tencent-latest-" + phone)); + String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.emptyKey, StringUtil.Md5("sms-login-tencent-latest-" + phone)); - String msgCode = StringUtil.getVerifyCode(codeLength); - // 楠岃瘉鐮佹ā鏉� - String msg = Constant.smsConfig.getSmsLogin().replace("[绛惧悕]", system.getSmsAlias()).replace("[楠岃瘉鐮乚", - msgCode); - // 鍙戦�佺煭淇� - // 鍙戦�侀棿闅�2鍒嗛挓鍐呯殑閲囩敤闃块噷浜戠煭淇″彂閫� - String cacheString = redisManager.getCommonString(key); - if (StringUtil.isNullOrEmpty(cacheString) || Integer.parseInt(cacheString) < 2) { - TencentSMSUtil.sendSingleMsg(phone, msg); - redisManager.increase(key); - redisManager.expire(key, 120); - } else { - redisManager.removeCommonString(key); - // 鍙戦�侀樋閲屼簯鐭俊 - JSONObject data = new JSONObject(); - data.put("code", msgCode); - AliyunSMSUtil.sendSingleMsg(phone, Constant.smsConfig.getAliyunLoginTemplatecode(), data.toString()); - } - // 缂撳瓨 - redisManager.sendSms(phone, SMSHistory.TYPE_LOGIN); - redisManager.saveSMSVCode(phone, SMSHistory.TYPE_LOGIN, msgCode); + String msgCode = StringUtil.getVerifyCode(codeLength); - SMSHistory smsHistory = new SMSHistory(); - smsHistory.setContent(msg); - smsHistory.setCreateTime(new Date()); - smsHistory.setPhone(phone); - smsHistory.setType(SMSHistory.TYPE_LOGIN); - smsHistoryMapper.insertSelective(smsHistory); - return msgCode; - } + // 楠岃瘉鐮佹ā鏉� + String msg = Constant.smsConfig.getSmsLogin().replace("[绛惧悕]", system.getSmsAlias()).replace("[楠岃瘉鐮乚", + msgCode); + if (Constant.IS_TEST) + System.out.println(msg); + // 鍙戦�佺煭淇� + // 鍙戦�侀棿闅�2鍒嗛挓鍐呯殑閲囩敤闃块噷浜戠煭淇″彂閫� + String cacheString = redisManager.getCommonString(key); + if (StringUtil.isNullOrEmpty(cacheString) || Integer.parseInt(cacheString) < 2) { + TencentSMSUtil.sendSingleMsg(phone, msg); + redisManager.increase(key); + redisManager.expire(key, 120); + } else { + redisManager.removeCommonString(key); + // 鍙戦�侀樋閲屼簯鐭俊 + JSONObject data = new JSONObject(); + data.put("code", msgCode); + AliyunSMSUtil.sendSingleMsg(phone, Constant.smsConfig.getAliyunLoginTemplatecode(), data.toString()); + } + // 缂撳瓨 + redisManager.sendSms(phone, SMSHistory.TYPE_LOGIN); + redisManager.saveSMSVCode(phone, SMSHistory.TYPE_LOGIN, msgCode); - @Override - public void sendBindVCode(SystemEnum system,String phone, int codeLength) throws SMSException { - boolean limit = redisManager.isSmsFrequencyLimit(phone, SMSHistory.TYPE_BIND); - if (limit) - throw new SMSException(1001, "璇疯繃60绉掑啀璇�"); - String msgCode = StringUtil.getVerifyCode(codeLength); + SMSHistory smsHistory = new SMSHistory(); + smsHistory.setContent(msg); + smsHistory.setCreateTime(new Date()); + smsHistory.setPhone(phone); + smsHistory.setType(SMSHistory.TYPE_LOGIN); + smsHistoryMapper.insertSelective(smsHistory); + return msgCode; + } - // 楠岃瘉鐮佹ā鏉� - String msg = Constant.smsConfig.getSmsBind().replace("[绛惧悕]", system.getSmsAlias()).replace("[楠岃瘉鐮乚", - msgCode); - // 鍙戦�佺煭淇� - TencentSMSUtil.sendSingleMsg(phone, msg); + @Override + public void sendBindVCode(SystemEnum system, String phone, int codeLength) throws SMSException { + boolean limit = redisManager.isSmsFrequencyLimit(phone, SMSHistory.TYPE_BIND); + if (limit) + throw new SMSException(1001, "璇疯繃60绉掑啀璇�"); + String msgCode = StringUtil.getVerifyCode(codeLength); - // 缂撳瓨 - redisManager.sendSms(phone, SMSHistory.TYPE_BIND); - redisManager.saveSMSVCode(phone, SMSHistory.TYPE_BIND, msgCode); + // 楠岃瘉鐮佹ā鏉� + String msg = Constant.smsConfig.getSmsBind().replace("[绛惧悕]", system.getSmsAlias()).replace("[楠岃瘉鐮乚", + msgCode); + // 鍙戦�佺煭淇� + TencentSMSUtil.sendSingleMsg(phone, msg); - SMSHistory smsHistory = new SMSHistory(); - smsHistory.setContent(msg); - smsHistory.setCreateTime(new Date()); - smsHistory.setPhone(phone); - smsHistory.setType(SMSHistory.TYPE_BIND); - smsHistoryMapper.insertSelective(smsHistory); - } + // 缂撳瓨 + redisManager.sendSms(phone, SMSHistory.TYPE_BIND); + redisManager.saveSMSVCode(phone, SMSHistory.TYPE_BIND, msgCode); - @Override - public void sendRemoveVCode(SystemEnum system,String phone, int codeLength) throws SMSException { - boolean limit = redisManager.isSmsFrequencyLimit(phone, SMSHistory.TYPE_REMVOE); - if (limit) - throw new SMSException(1001, "璇疯繃60绉掑啀璇�"); - String msgCode = StringUtil.getVerifyCode(codeLength); + SMSHistory smsHistory = new SMSHistory(); + smsHistory.setContent(msg); + smsHistory.setCreateTime(new Date()); + smsHistory.setPhone(phone); + smsHistory.setType(SMSHistory.TYPE_BIND); + smsHistoryMapper.insertSelective(smsHistory); + } - // 楠岃瘉鐮佹ā鏉� - String msg = Constant.smsConfig.getSmsBind().replace("[绛惧悕]", system.getSmsAlias()).replace("[楠岃瘉鐮乚", - msgCode); - // 鍙戦�佺煭淇� - TencentSMSUtil.sendSingleMsg(phone, msg); + @Override + public void sendRemoveVCode(SystemEnum system, String phone, int codeLength) throws SMSException { + boolean limit = redisManager.isSmsFrequencyLimit(phone, SMSHistory.TYPE_REMVOE); + if (limit) + throw new SMSException(1001, "璇疯繃60绉掑啀璇�"); + String msgCode = StringUtil.getVerifyCode(codeLength); - // 缂撳瓨 - redisManager.sendSms(phone, SMSHistory.TYPE_REMVOE); - redisManager.saveSMSVCode(phone, SMSHistory.TYPE_REMVOE, msgCode); + // 楠岃瘉鐮佹ā鏉� + String msg = Constant.smsConfig.getSmsBind().replace("[绛惧悕]", system.getSmsAlias()).replace("[楠岃瘉鐮乚", + msgCode); + // 鍙戦�佺煭淇� + TencentSMSUtil.sendSingleMsg(phone, msg); - SMSHistory smsHistory = new SMSHistory(); - smsHistory.setContent(msg); - smsHistory.setCreateTime(new Date()); - smsHistory.setPhone(phone); - smsHistory.setType(SMSHistory.TYPE_REMVOE); - smsHistoryMapper.insertSelective(smsHistory); - } - - @Override - public void sendExtractVCode(SystemEnum system,String phone) throws SMSException { - boolean limit = redisManager.isSmsFrequencyLimit(phone, SMSHistory.TYPE_EXTRACT); - if (limit) - throw new SMSException(1001, "璇疯繃60绉掑啀璇�"); - String msgCode = StringUtil.getRandomCode(6); - String msg = Constant.smsConfig.getSmsExtract().replace("[绛惧悕]",system.getSmsAlias()) - .replace("[楠岃瘉鐮乚", msgCode); - // 鍙戦�佺煭淇� - TencentSMSUtil.sendSingleMsg(phone, msg); - // 缂撳瓨 - redisManager.sendSms(phone, SMSHistory.TYPE_EXTRACT); - redisManager.saveSMSVCode(phone, SMSHistory.TYPE_EXTRACT, msgCode); - } + // 缂撳瓨 + redisManager.sendSms(phone, SMSHistory.TYPE_REMVOE); + redisManager.saveSMSVCode(phone, SMSHistory.TYPE_REMVOE, msgCode); - @Override - public void sendExtractSuccessMsg(SystemEnum system,String phone, BigDecimal money) throws SMSException { - String msg = Constant.smsConfig.getSmsExtractSuccess().replace("[绛惧悕]", system.getSmsAlias()) - .replace("[閲戦]", money.toString()); - // 鍙戦�佺煭淇� - TencentSMSUtil.sendSingleMsg(phone, msg); - } + SMSHistory smsHistory = new SMSHistory(); + smsHistory.setContent(msg); + smsHistory.setCreateTime(new Date()); + smsHistory.setPhone(phone); + smsHistory.setType(SMSHistory.TYPE_REMVOE); + smsHistoryMapper.insertSelective(smsHistory); + } - @Override - public void sendExtractFailMsg(SystemEnum system,String phone, BigDecimal money) throws SMSException { - String msg = Constant.smsConfig.getSmsExtractFail().replace("[绛惧悕]", system.getSmsAlias()) - .replace("[閲戦]", money.toString()); - // 鍙戦�佺煭淇� - TencentSMSUtil.sendSingleMsg(phone, msg); - } + @Override + public void sendExtractVCode(SystemEnum system, String phone) throws SMSException { + boolean limit = redisManager.isSmsFrequencyLimit(phone, SMSHistory.TYPE_EXTRACT); + if (limit) + throw new SMSException(1001, "璇疯繃60绉掑啀璇�"); + String msgCode = StringUtil.getRandomCode(6); + String msg = Constant.smsConfig.getSmsExtract().replace("[绛惧悕]", system.getSmsAlias()) + .replace("[楠岃瘉鐮乚", msgCode); + // 鍙戦�佺煭淇� + TencentSMSUtil.sendSingleMsg(phone, msg); + // 缂撳瓨 + redisManager.sendSms(phone, SMSHistory.TYPE_EXTRACT); + redisManager.saveSMSVCode(phone, SMSHistory.TYPE_EXTRACT, msgCode); + } + + @Override + public void sendExtractSuccessMsg(SystemEnum system, String phone, BigDecimal money) throws SMSException { + String msg = Constant.smsConfig.getSmsExtractSuccess().replace("[绛惧悕]", system.getSmsAlias()) + .replace("[閲戦]", money.toString()); + // 鍙戦�佺煭淇� + TencentSMSUtil.sendSingleMsg(phone, msg); + } + + @Override + public void sendExtractFailMsg(SystemEnum system, String phone, BigDecimal money) throws SMSException { + String msg = Constant.smsConfig.getSmsExtractFail().replace("[绛惧悕]", system.getSmsAlias()) + .replace("[閲戦]", money.toString()); + // 鍙戦�佺煭淇� + TencentSMSUtil.sendSingleMsg(phone, msg); + } } -- Gitblit v1.8.0