¶Ô±ÈÐÂÎļþ |
| | |
| | | /* |
| | | * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. |
| | | * |
| | | * Redistribution and use in source and binary forms, with or without |
| | | * modification, are permitted provided that the following conditions are met: |
| | | * |
| | | * Redistributions of source code must retain the above copyright notice, |
| | | * this list of conditions and the following disclaimer. |
| | | * Redistributions in binary form must reproduce the above copyright |
| | | * notice, this list of conditions and the following disclaimer in the |
| | | * documentation and/or other materials provided with the distribution. |
| | | * Neither the name of the dreamlu.net developer nor the names of its |
| | | * contributors may be used to endorse or promote products derived from |
| | | * this software without specific prior written permission. |
| | | * Author: Chill åºéª (smallchill@163.com) |
| | | */ |
| | | package org.springblade.core.sms; |
| | | |
| | | import org.springblade.core.sms.model.SmsCode; |
| | | import org.springblade.core.sms.model.SmsData; |
| | | import org.springblade.core.sms.model.SmsInfo; |
| | | import org.springblade.core.sms.model.SmsResponse; |
| | | import org.springblade.core.tool.utils.StringPool; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | |
| | | import static org.springblade.core.sms.constant.SmsConstant.CAPTCHA_KEY; |
| | | |
| | | /** |
| | | * çä¿¡éç¨å°è£
|
| | | * |
| | | * @author Chill |
| | | */ |
| | | public interface SmsTemplate { |
| | | |
| | | /** |
| | | * ç¼åé®å¼ |
| | | * |
| | | * @param phone ææºå· |
| | | * @param id é®å¼ |
| | | * @return ç¼åé®å¼è¿å |
| | | */ |
| | | default String cacheKey(String phone, String id) { |
| | | return CAPTCHA_KEY + phone + StringPool.COLON + id; |
| | | } |
| | | |
| | | /** |
| | | * åéçä¿¡ |
| | | * |
| | | * @param smsInfo çä¿¡ä¿¡æ¯ |
| | | * @return åéè¿å |
| | | */ |
| | | default boolean send(SmsInfo smsInfo) { |
| | | return sendMulti(smsInfo.getSmsData(), smsInfo.getPhones()); |
| | | } |
| | | |
| | | /** |
| | | * åéçä¿¡ |
| | | * |
| | | * @param smsData çä¿¡å
容 |
| | | * @param phone ææºå· |
| | | * @return åéè¿å |
| | | */ |
| | | default boolean sendSingle(SmsData smsData, String phone) { |
| | | if (StringUtils.isEmpty(phone)) { |
| | | return Boolean.FALSE; |
| | | } |
| | | return sendMulti(smsData, Collections.singletonList(phone)); |
| | | } |
| | | |
| | | /** |
| | | * åéçä¿¡ |
| | | * |
| | | * @param smsData çä¿¡å
容 |
| | | * @param phones ææºå·å表 |
| | | * @return åéè¿å |
| | | */ |
| | | default boolean sendMulti(SmsData smsData, Collection<String> phones) { |
| | | SmsResponse response = sendMessage(smsData, phones); |
| | | return response.isSuccess(); |
| | | } |
| | | |
| | | /** |
| | | * åéçä¿¡ |
| | | * |
| | | * @param smsData çä¿¡å
容 |
| | | * @param phones ææºå·å表 |
| | | * @return åéè¿å |
| | | */ |
| | | SmsResponse sendMessage(SmsData smsData, Collection<String> phones); |
| | | |
| | | /** |
| | | * åééªè¯ç |
| | | * |
| | | * @param smsData çä¿¡å
容 |
| | | * @param phone ææºå· |
| | | * @return åéè¿å |
| | | */ |
| | | SmsCode sendValidate(SmsData smsData, String phone); |
| | | |
| | | /** |
| | | * æ ¡éªéªè¯ç |
| | | * |
| | | * @param smsCode éªè¯ç å
容 |
| | | * @return æ¯å¦æ ¡éªæå |
| | | */ |
| | | boolean validateMessage(SmsCode smsCode); |
| | | |
| | | } |