提交 4826be2d authored 作者: renjiancai's avatar renjiancai

--no commit message

上级 1d264c8d
...@@ -24,6 +24,11 @@ ...@@ -24,6 +24,11 @@
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
<version>2.1.1.RELEASE</version> <version>2.1.1.RELEASE</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
<dependency> <dependency>
<groupId>javax.servlet</groupId> <groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId> <artifactId>javax.servlet-api</artifactId>
......
package com.zrqx.core.components.message;
import com.zrqx.core.components.message.form.PhoneMessageForm;
import com.zrqx.core.exception.BaseException;
/**
* 接口响应统一结果处理
* 接口响应失败抛出异常
* @author lpf
* @date 2020-06-22
*/
public interface MessageService{
/**
* 手机发送短信,发送失败处理抛出异常
* @param form
* @throws BaseException
*/
void sendPhone(PhoneMessageForm form) throws BaseException;
/**
* 手机发送短信验证码,发送失败处理抛出异常
* @param form
* @return
* @throws BaseException
*/
String sendPhoneCaptcha(PhoneMessageForm form) throws BaseException;
}
package com.zrqx.core.components.message.service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.zrqx.core.components.message.MessageService;
import com.zrqx.core.components.message.form.PhoneMessageForm;
import com.zrqx.core.exception.BaseException;
import com.zrqx.core.message.MessageClient;
import com.zrqx.core.util.response.CallBack;
/**
* @author lpf
* @date 2020-06-22
*/
@Component
public class MessageServiceImpl implements MessageService {
private final Logger log = LoggerFactory.getLogger(MessageServiceImpl.class);
@Autowired
private MessageClient client;
@Override
public void sendPhone(PhoneMessageForm form) throws BaseException {
CallBack<?> callBack = client.sendPhone(form);
if (callBack.isStatus()) {
return ;
}
throw new BaseException("手机发送短信失败,失败原因:" + callBack.getMsg() + ";");
}
@Override
public String sendPhoneCaptcha(PhoneMessageForm form) throws BaseException {
CallBack<String> callBack = client.sendPhoneCaptcha(form);
if (callBack.hasEntity()) {
return callBack.getData();
}
throw new BaseException("手机发送短信验证码失败,失败原因:" + callBack.getMsg() + ";");
}
}
package com.zrqx.core.enums.message;
import java.util.HashMap;
import java.util.stream.Stream;
/**
* @author lpf
* @date 2020-06-22
*/
public enum MessageBusinessTypeEnum {
/** */
REGISTER_CAPTCHA("captcha_reg", "注册验证码"),
LOGIN_CAPTCHA("captcha_login", "登录验证码"),
RESET_PASSWORD_CAPTCHA("captcha_reset_password", "找回密码验证码");
private final String code;
private final String name;
private static final HashMap<String,String> MAP = new HashMap<String,String>();
static {
stream().forEach(e -> {
MAP.put(e.code, e.name);
});
}
public static Stream<MessageBusinessTypeEnum> stream(){
return Stream.of(values());
}
private MessageBusinessTypeEnum(String code, String name) {
this.code = code;
this.name = name;
}
public static boolean isExist(String code) {
return stream().anyMatch(e -> e.code.equals(code));
}
public static String getName(String code) {
return stream().filter(e -> e.code.equals(code)).findFirst().map(e -> e.name).orElse(null);
}
public String getCode() {
return code;
}
public String getName() {
return name;
}
public static HashMap<String, String> getMap() {
return MAP;
}
}
package com.zrqx.core.enums.message;
import com.zrqx.core.enums.captcha.CaptchaBusinessTypeEnum;
import com.zrqx.core.enums.interfaces.EnumsInterface;
import java.util.HashMap;
import java.util.stream.Stream;
/**
* @author lpf
* @date 2020-06-19
*/
public enum PhoneTypeEnum implements EnumsInterface<String> {
/** */
ALi("ali","阿里云短信"),
HUAWEI("huawei","华为云短信服务"),
MANDAO("mandao", "漫道科技短信服务");
private final String code;
private final String name;
private static final HashMap<String,String> MAP = new HashMap<String,String>();
static {
stream().forEach(e -> {
MAP.put(e.code, e.name);
});
}
public static Stream<PhoneTypeEnum> stream(){
return Stream.of(values());
}
private PhoneTypeEnum(String code, String name) {
this.code = code;
this.name = name;
}
public static boolean isExist(String code) {
return stream().anyMatch(e -> e.code.equals(code));
}
public static String getName(String code) {
return stream().filter(e -> e.code.equals(code)).findFirst().map(e -> e.name).orElse(null);
}
@Override
public String getCode() {
return code;
}
@Override
public String getName() {
return name;
}
public static HashMap<String, String> getMap() {
return MAP;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论