update sms4j 2.2.0 => 3.1.1 大升级 支持自定义配置key 可用于多厂商多租户等

This commit is contained in:
疯狂的狮子Li
2024-01-18 18:33:47 +08:00
parent 928e418f3f
commit b628c9b027
8 changed files with 185 additions and 71 deletions

View File

@ -1,11 +1,11 @@
package org.dromara.demo.controller;
import cn.dev33.satoken.annotation.SaIgnore;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
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;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -20,12 +20,12 @@ import java.util.LinkedHashMap;
* @author Lion Li
* @version 4.2.0
*/
@SaIgnore
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/demo/sms")
public class SmsController {
/**
* 发送短信Aliyun
*
@ -36,7 +36,7 @@ public class SmsController {
public R<Object> sendAliyun(String phones, String templateId) {
LinkedHashMap<String, String> map = new LinkedHashMap<>(1);
map.put("code", "1234");
SmsBlend smsBlend = SmsFactory.createSmsBlend(SupplierType.ALIBABA);
SmsBlend smsBlend = SmsFactory.getSmsBlend("config1");
SmsResponse smsResponse = smsBlend.sendMessage(phones, templateId, map);
return R.ok(smsResponse);
}
@ -52,9 +52,33 @@ public class SmsController {
LinkedHashMap<String, String> map = new LinkedHashMap<>(1);
// map.put("2", "测试测试");
map.put("1", "1234");
SmsBlend smsBlend = SmsFactory.createSmsBlend(SupplierType.TENCENT);
SmsBlend smsBlend = SmsFactory.getSmsBlend("config2");
SmsResponse smsResponse = smsBlend.sendMessage(phones, templateId, map);
return R.ok(smsResponse);
}
/**
* 添加黑名单
*
* @param phone 手机号
*/
@GetMapping("/addBlacklist")
public R<Object> addBlacklist(String phone){
SmsBlend smsBlend = SmsFactory.getSmsBlend("config1");
smsBlend.joinInBlacklist(phone);
return R.ok();
}
/**
* 移除黑名单
*
* @param phone 手机号
*/
@GetMapping("/removeBlacklist")
public R<Object> removeBlacklist(String phone){
SmsBlend smsBlend = SmsFactory.getSmsBlend("config1");
smsBlend.removeFromBlacklist(phone);
return R.ok();
}
}