ruoyi-admin/src/main/java/org/dromara/web/controller/CaptchaController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
ruoyi-admin/src/main/resources/application-dev.yml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
ruoyi-admin/src/main/resources/application-prod.yml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
ruoyi-common/ruoyi-common-sms/pom.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
ruoyi-modules/ruoyi-demo/pom.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
ruoyi-modules/ruoyi-demo/src/main/java/org/dromara/demo/controller/SmsController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
ruoyi-admin/src/main/java/org/dromara/web/controller/CaptchaController.java
@@ -17,6 +17,7 @@ import org.dromara.common.sms.config.properties.SmsProperties; import org.dromara.common.web.config.properties.CaptchaProperties; import org.dromara.common.web.enums.CaptchaType; import org.dromara.sms4j.api.SmsBlend; import org.dromara.sms4j.api.entity.SmsResponse; import org.dromara.sms4j.core.factory.SmsFactory; import org.dromara.sms4j.provider.enumerate.SupplierType; @@ -57,17 +58,15 @@ */ @GetMapping("/resource/sms/code") public R<Void> smsCode(@NotBlank(message = "{user.phonenumber.not.blank}") String phonenumber) { if (!smsProperties.getEnabled()) { return R.fail("当前系统没有开启短信功能!"); } String key = GlobalConstants.CAPTCHA_CODE_KEY + phonenumber; String code = RandomUtil.randomNumbers(4); RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION)); // 验证码模板id 自行处理 (查数据库或写死均可) String templateId = "SMS_460945446"; String templateId = ""; LinkedHashMap<String, String> map = new LinkedHashMap<>(1); map.put("code", code); SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.ALIBABA).sendMessage(phonenumber, templateId, map); SmsBlend smsBlend = SmsFactory.createSmsBlend(SupplierType.ALIBABA); SmsResponse smsResponse = smsBlend.sendMessage(phonenumber, templateId, map); if (!"OK".equals(smsResponse.getCode())) { log.error("验证码短信发送异常 => {}", smsResponse); return R.fail(smsResponse.getMessage()); ruoyi-admin/src/main/resources/application-dev.yml
@@ -158,16 +158,29 @@ # Socket连接超时值,单位毫秒,缺省值不超时 connectionTimeout: 0 --- # sms 短信 https://wind.kim/doc/start/springboot.html --- # sms 短信 支持 阿里云 腾讯云 云片 等等各式各样的短信服务商 # https://wind.kim/doc/start 文档地址 各个厂商可同时使用 sms: enabled: true # 阿里云 dysmsapi.aliyuncs.com alibaba: #请求地址 默认为 dysmsapi.aliyuncs.com 如无特殊改变可以不用设置 requestUrl: dysmsapi.aliyuncs.com #阿里云的accessKey accessKeyId: xxxxxxx #阿里云的accessKeySecret accessKeySecret: xxxxxxx #短信签名 signature: 测试 #请求地址 默认为dysmsapi.aliyuncs.com 如无特殊改变可以不用设置 requestUrl: dysmsapi.aliyuncs.com tencent: #请求地址默认为 sms.tencentcloudapi.com 如无特殊改变可不用设置 requestUrl: sms.tencentcloudapi.com #腾讯云的accessKey accessKeyId: xxxxxxx #腾讯云的accessKeySecret accessKeySecret: xxxxxxx #短信签名 signature: 测试 #短信sdkAppId sdkAppId: appid #地域信息默认为 ap-guangzhou 如无特殊改变可不用设置 territory: ap-guangzhou ruoyi-admin/src/main/resources/application-prod.yml
@@ -161,14 +161,29 @@ # Socket连接超时值,单位毫秒,缺省值不超时 connectionTimeout: 0 --- # sms 短信 --- # sms 短信 支持 阿里云 腾讯云 云片 等等各式各样的短信服务商 # https://wind.kim/doc/start 文档地址 各个厂商可同时使用 sms: enabled: false # 阿里云 dysmsapi.aliyuncs.com # 腾讯云 sms.tencentcloudapi.com endpoint: "dysmsapi.aliyuncs.com" accessKeyId: xxxxxxx accessKeySecret: xxxxxx signName: 测试 # 腾讯专用 sdkAppId: alibaba: #请求地址 默认为 dysmsapi.aliyuncs.com 如无特殊改变可以不用设置 requestUrl: dysmsapi.aliyuncs.com #阿里云的accessKey accessKeyId: xxxxxxx #阿里云的accessKeySecret accessKeySecret: xxxxxxx #短信签名 signature: 测试 tencent: #请求地址默认为 sms.tencentcloudapi.com 如无特殊改变可不用设置 requestUrl: sms.tencentcloudapi.com #腾讯云的accessKey accessKeyId: xxxxxxx #腾讯云的accessKeySecret accessKeySecret: xxxxxxx #短信签名 signature: 测试 #短信sdkAppId sdkAppId: appid #地域信息默认为 ap-guangzhou 如无特殊改变可不用设置 territory: ap-guangzhou ruoyi-common/ruoyi-common-sms/pom.xml
@@ -16,14 +16,17 @@ </description> <dependencies> <dependency> <groupId>org.dromara</groupId> <artifactId>ruoyi-common-json</artifactId> </dependency> <dependency> <groupId>org.dromara.sms4j</groupId> <artifactId>sms4j-spring-boot-starter</artifactId> <exclusions> <!-- 排除京东短信内存在的fastjson等待作者后续修复 --> <exclusion> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> </exclusion> </exclusions> </dependency> </dependencies> ruoyi-modules/ruoyi-demo/pom.xml
@@ -97,16 +97,6 @@ <groupId>org.dromara</groupId> <artifactId>ruoyi-common-websocket</artifactId> </dependency> <!-- 短信 用哪个导入哪个依赖 --> <!-- <dependency>--> <!-- <groupId>com.aliyun</groupId>--> <!-- <artifactId>dysmsapi20170525</artifactId>--> <!-- </dependency>--> <!-- <dependency>--> <!-- <groupId>com.tencentcloudapi</groupId>--> <!-- <artifactId>tencentcloud-sdk-java-sms</artifactId>--> <!-- </dependency>--> </dependencies> ruoyi-modules/ruoyi-demo/src/main/java/org/dromara/demo/controller/SmsController.java
@@ -4,6 +4,7 @@ import org.dromara.common.core.domain.R; import org.dromara.common.core.utils.SpringUtils; import org.dromara.common.sms.config.properties.SmsProperties; import org.dromara.sms4j.api.SmsBlend; import org.dromara.sms4j.api.entity.SmsResponse; import org.dromara.sms4j.core.factory.SmsFactory; import org.dromara.sms4j.provider.enumerate.SupplierType; @@ -27,10 +28,6 @@ @RequestMapping("/demo/sms") public class SmsController { private final SmsProperties smsProperties; // private final SmsTemplate smsTemplate; // 可以使用spring注入 // private final AliyunSmsTemplate smsTemplate; // 也可以注入某个厂家的模板工具 /** * 发送短信Aliyun * @@ -39,15 +36,10 @@ */ @GetMapping("/sendAliyun") public R<Object> sendAliyun(String phones, String templateId) { if (!smsProperties.getEnabled()) { return R.fail("当前系统没有开启短信功能!"); } if (!SpringUtils.containsBean("aliyunSmsTemplate")) { return R.fail("阿里云依赖未引入!"); } LinkedHashMap<String, String> map = new LinkedHashMap<>(1); map.put("code", "1234"); SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.ALIBABA).sendMessage(phones, templateId, map); SmsBlend smsBlend = SmsFactory.createSmsBlend(SupplierType.ALIBABA); SmsResponse smsResponse = smsBlend.sendMessage(phones, templateId, map); return R.ok(smsResponse); } @@ -59,16 +51,11 @@ */ @GetMapping("/sendTencent") public R<Object> sendTencent(String phones, String templateId) { if (!smsProperties.getEnabled()) { return R.fail("当前系统没有开启短信功能!"); } if (!SpringUtils.containsBean("tencentSmsTemplate")) { return R.fail("腾讯云依赖未引入!"); } LinkedHashMap<String, String> map = new LinkedHashMap<>(1); // map.put("2", "测试测试"); map.put("1", "1234"); SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.TENCENT).sendMessage(phones, templateId, map); SmsBlend smsBlend = SmsFactory.createSmsBlend(SupplierType.TENCENT); SmsResponse smsResponse = smsBlend.sendMessage(phones, templateId, map); return R.ok(smsResponse); }