From e59e6a8a2fcf3ac2194a69927cd5690453a83e91 Mon Sep 17 00:00:00 2001 From: ZQN <364596817@qq.com> Date: 星期三, 19 六月 2024 16:34:44 +0800 Subject: [PATCH] 投诉添加,云片短信添加 --- project-framework/src/main/java/com/project/framework/web/service/SysLoginService.java | 27 +++++++++++++++++++++------ 1 files changed, 21 insertions(+), 6 deletions(-) diff --git a/project-framework/src/main/java/com/project/framework/web/service/SysLoginService.java b/project-framework/src/main/java/com/project/framework/web/service/SysLoginService.java index 0a9eb08..50cf765 100644 --- a/project-framework/src/main/java/com/project/framework/web/service/SysLoginService.java +++ b/project-framework/src/main/java/com/project/framework/web/service/SysLoginService.java @@ -21,6 +21,7 @@ import com.project.common.exception.user.CaptchaException; import com.project.common.exception.user.CaptchaExpireException; import com.project.common.exception.user.UserPasswordNotMatchException; +import com.project.common.sms.YPSmsApi; import com.project.common.utils.DateUtils; import com.project.common.utils.MessageUtils; import com.project.common.utils.ServletUtils; @@ -125,14 +126,31 @@ if (user==null){ throw new BaseException("鎮ㄦ墜鏈哄彿灏氭湭娉ㄥ唽锛�"); } - // 鐢熸垚4浣嶉殢鏈烘暟 String code = ""; Random ran = new Random(); int randomNum = ran.nextInt(10000); code = String.format("%04d", randomNum); log.info("鎵嬫満鍙凤細"+phone+"->楠岃瘉鐮侊細"+code); - Boolean flag = true; + boolean send = sendAl(phone, code); + if (send){ + redisCache.setCacheObject(getCacheKey(phone), code, Constants.PHONE_EXPIRATION, TimeUnit.MINUTES); + return true; + } + redisCache.setCacheObject(getCacheKey(phone), code, Constants.PHONE_EXPIRATION, TimeUnit.MINUTES); + return false; + } + + private boolean sendYp(String phone, String code ){ + String result = YPSmsApi.sendSms(phone, StringUtils.format(YPSmsApi.VERIFY_CODE_TEMPLATE, code, Constants.PHONE_EXPIRATION)); + if (result.contains("\"code\":0,\"msg\":\"OK\"")){ + log.info("鍙戦�佹垚鍔� ->楠岃瘉鐮侊細"+code); + return true; + } + return false; + } + + private boolean sendAl(String phone, String code ){ DefaultProfile profile = DefaultProfile.getProfile("cn-beijing", AliyunSmsConstants.SMS_APPID, AliyunSmsConstants.SMS_SECRET); IAcsClient client = new DefaultAcsClient(profile); CommonRequest request = new CommonRequest(); @@ -149,15 +167,12 @@ JSONObject jsonObject = JSON.parseObject(response.getData()); if ("OK".equals(jsonObject.get("Code"))) { log.info("鍙戦�佹垚鍔� ->楠岃瘉鐮侊細"+code); - redisCache.setCacheObject(getCacheKey(phone), code, Constants.PHONE_EXPIRATION, TimeUnit.MINUTES); return true; } - } catch (ClientException e) { e.printStackTrace(); } - redisCache.setCacheObject(getCacheKey(phone), code, Constants.PHONE_EXPIRATION, TimeUnit.MINUTES); - return flag; + return false; } /** -- Gitblit v1.9.1