parent
f799b86c4d
commit
8c49b413d5
@ -0,0 +1,7 @@
|
||||
package au.com.royalpay.payment.manage.support.sms;
|
||||
|
||||
import org.springframework.core.Ordered;
|
||||
|
||||
public interface SmsSenderChannel extends SmsSender, Ordered {
|
||||
boolean supportNationCode(String nationCode);
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package au.com.royalpay.payment.manage.support.sms;
|
||||
|
||||
import au.com.royalpay.payment.manage.support.sms.msg.AuthCodeMessage;
|
||||
import au.com.royalpay.payment.manage.support.sms.msg.OpenMessage;
|
||||
import au.com.royalpay.payment.manage.support.sms.msg.RefuseMessage;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@Service
|
||||
@Primary
|
||||
public class SmsSenderRoute implements SmsSender{
|
||||
private final List<SmsSenderChannel> channels;
|
||||
|
||||
public SmsSenderRoute(List<SmsSenderChannel> channels) {
|
||||
this.channels = channels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendOpenMessage(String nationCode, String mobile, Locale locale, OpenMessage msg) {
|
||||
channels.stream().filter(channel->channel.supportNationCode(nationCode)).findFirst().ifPresent(channel->channel.sendOpenMessage(nationCode, mobile, locale, msg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendAuthCodeMessage(String nationCode, String mobile, Locale locale, AuthCodeMessage register) {
|
||||
channels.stream().filter(channel->channel.supportNationCode(nationCode)).findFirst().ifPresent(channel->channel.sendAuthCodeMessage(nationCode, mobile, locale, register));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRefuseMessage(String nationCode, String mobile, Locale locale, RefuseMessage refuse) {
|
||||
channels.stream().filter(channel->channel.supportNationCode(nationCode)).findFirst().ifPresent(channel->channel.sendRefuseMessage(nationCode, mobile, locale, refuse));
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package au.com.royalpay.payment.manage.support.sms;
|
||||
|
||||
import au.com.royalpay.payment.manage.support.sms.msg.AuthCodeMessage;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class SmsSenderDaasImplTest {
|
||||
private SmsSender sender;
|
||||
|
||||
@BeforeEach
|
||||
void initService() {
|
||||
sender = new SmsSenderQcloudImpl(1400094878, "43390d81e20c5191c278fbf4cd275be2");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSms() {
|
||||
sender.sendAuthCodeMessage("86", "18913315655", Locale.CHINESE, new AuthCodeMessage("测试", "111", 1));
|
||||
}
|
||||
}
|
Loading…
Reference in new issue