All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sophon.module.sms.integration.prop.SmsChannelProperties Maven / Gradle / Ivy

The newest version!
package org.sophon.module.sms.integration.prop;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.sophon.commons.util.AssertUtil;
import org.sophon.module.sms.commons.constants.SmsErrorCodeConstants;
import org.sophon.module.sms.commons.enunms.SmsChannelEnum;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * 短信渠道配置类
 * @author moushaokun
 * @since time: 2023-03-13 10:53
 */
@Data
@Accessors(chain = true)
public class SmsChannelProperties {
    /**
     * 渠道配置唯一标识,默认为 {@link SmsChannelEnum#getCode()}
     */
    private String              key;
    /**
     * 渠道 {@link SmsChannelEnum}
     */
    private SmsChannelEnum      channel;
    /**
     * 短信签名
     */
    private String              signature;
    /**
     * 短信API-key
     */
    private String              apiKey;
    /**
     * 短信 API 的密钥
     */
    private String              apiSecret;
    /**
     * 短信发送回调 URL
     */
    private String              callbackUrl;
    /**
     * 短信渠道的额外参数,例如说,微信需要传递 sdkAppId 参数
     */
    private Map channelExtras;

    public SmsChannelProperties addChannelExtra(String key, String value) {
        if (channelExtras == null) {
            channelExtras = new HashMap<>(4);
        }
        channelExtras.put(key, value);
        return this;
    }

    public String getKey(){
        return StringUtils.isNotBlank(key) ? key : channel.getCode();
    }

    public static void check(SmsChannelProperties channelProperties){
        AssertUtil.assertNotNull(channelProperties, SmsErrorCodeConstants.PARAM_INVALID, "短信渠道配置不能为空");
        AssertUtil.assertNotNull(channelProperties.getChannel(), SmsErrorCodeConstants.PARAM_INVALID, "渠道类型不能为空");
        AssertUtil.assertNotBlank(channelProperties.getSignature(), SmsErrorCodeConstants.PARAM_INVALID, "短信签名不能为空");
        AssertUtil.assertNotBlank(channelProperties.getApiKey(), SmsErrorCodeConstants.PARAM_INVALID, "短信API账号不能为空");
        AssertUtil.assertNotBlank(channelProperties.getApiSecret(), SmsErrorCodeConstants.PARAM_INVALID, "短信API密钥不能为空");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy