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

com.eworkcloud.sms.SmsConfiguration Maven / Gradle / Ivy

There is a newer version: 2.2.1
Show newest version
package com.eworkcloud.sms;

import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;

@Configuration
public class SmsConfiguration implements EnvironmentAware {

    private static Environment environment;
    private static String regionId;
    private static String accessKeyId;
    private static String accessKeySecret;

    @Override
    public void setEnvironment(Environment environment) {
        SmsConfiguration.environment = environment;
    }

    /**
     * 获取区域ID
     *
     * @return 区域ID
     */
    public static String getRegionId() {
        if (StringUtils.hasText(regionId)) {
            return regionId;
        }
        return environment.getProperty("sms.regionId");
    }

    /**
     * 设置区域ID
     *
     * @param regionId 区域ID
     */
    public static void setRegionId(String regionId) {
        SmsConfiguration.regionId = regionId;
    }

    /**
     * 获取访问钥匙
     *
     * @return 访问钥匙
     */
    public static String getAccessKeyId() {
        if (StringUtils.hasText(accessKeyId)) {
            return accessKeyId;
        }
        return environment.getProperty("sms.accessKeyId");
    }

    /**
     * 设置访问钥匙
     *
     * @param accessKeyId 访问钥匙
     */
    public static void setAccessKeyId(String accessKeyId) {
        SmsConfiguration.accessKeyId = accessKeyId;
    }

    /**
     * 获取安全密钥
     *
     * @return 安全密钥
     */
    public static String getAccessKeySecret() {
        if (StringUtils.hasText(accessKeySecret)) {
            return accessKeySecret;
        }
        return environment.getProperty("sms.accessKeySecret");
    }

    /**
     * 设置安全密钥
     *
     * @param accessKeySecret 安全密钥
     */
    public static void setAccessKeySecret(String accessKeySecret) {
        SmsConfiguration.accessKeySecret = accessKeySecret;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy