Exemple #1
0
        private static string GetHttpPrefix(BaiduYunConfig config)
        {
            if (config == null || !config.Security)
            {
                return("http");
            }

            return("https");
        }
Exemple #2
0
        private static string GetApiServerUrl(BaiduYunConfig config)
        {
            if (config == null || string.Compare(config.Region, "Beijing", StringComparison.OrdinalIgnoreCase) == 0)
            {
                return(BaiduYunApiUrls.BeijingService);
            }

            return(BaiduYunApiUrls.GuangzhouService);
        }
Exemple #3
0
        public BaiduYunSmsClient(BaiduYunConfig config, Action <Exception> exceptionHandler = null)
        {
            _config       = config ?? throw new ArgumentNullException(nameof(config));
            _account      = _config.Account ?? throw new ArgumentNullException(nameof(_config.Account));
            _apiServerUrl = $"{GetHttpPrefix(config)}://{GetApiServerUrl(config)}";
            _proxy        = HttpApiClient.Create <IBaiduYunSmsApis>(_apiServerUrl);

            var globalHandle = ExceptionHandleResolver.ResolveHandler();

            globalHandle     += exceptionHandler;
            _exceptionHandler = globalHandle;
        }
Exemple #4
0
        public BaiduYunSmsClient(BaiduYunConfig config, Action <Exception> exceptionHandler = null)
        {
            _config       = config ?? throw new ArgumentNullException(nameof(config));
            _account      = _config.Account ?? throw new ArgumentNullException(nameof(_config.Account));
            _apiServerUrl = ApiAddressHelper.Get(config);
            _proxy        = WebApiClientCreator.Create(_apiServerUrl, _config.TimeOut);

            var globalHandle = ExceptionHandleResolver.ResolveHandler();

            globalHandle     += exceptionHandler;
            _exceptionHandler = globalHandle;
        }
Exemple #5
0
        public BaiduYunTests()
        {
            var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json", false, true)
                                .Build();

            _config = configuration.GetSection("SMS:BaiduYun").Get <BaiduYunConfig>();

            SMS.Exceptions.ExceptionHandleResolver.SetHandler(e => {
                var sb = new StringBuilder();
                sb.AppendLine(e.Message);
                sb.AppendLine(e.Source);
                sb.AppendLine(e.StackTrace);
                _messageIfError += sb.ToString();
            });

            _client = new BaiduYunSmsClient(_config, SMS.Exceptions.ExceptionHandleResolver.ResolveHandler());
        }
Exemple #6
0
 public object ToSendObject(BaiduYunConfig config)
 {
     if (Vars != null && Vars.Any())
     {
         return(new {
             invokeId = config.InvokeId,
             phoneNumber = PhoneNumber,
             templateCode = TemplateCode,
             contentVar = Vars
         });
     }
     else
     {
         return(new {
             invokeId = config.InvokeId,
             phoneNumber = PhoneNumber,
             templateCode = TemplateCode
         });
     }
 }
Exemple #7
0
 public BceObjectWrapper(BceObject bce, BaiduYunMessage message, BaiduYunConfig config)
 {
     BceObject = bce;
     Message   = message;
     Config    = config;
 }
Exemple #8
0
 public BceObject(BaiduYunConfig config)
 {
     _config = config ?? throw new ArgumentNullException(nameof(config));
 }
Exemple #9
0
 public static string Get(BaiduYunConfig config)
 {
     return($"{GetHttpPrefix(config)}://{GetApiServerUrl(config)}");
 }