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

            return("https");
        }
Exemplo n.º 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);
        }
Exemplo n.º 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;
        }
Exemplo n.º 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;
        }
Exemplo n.º 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());
        }
Exemplo n.º 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
         });
     }
 }
Exemplo n.º 7
0
 public BceObjectWrapper(BceObject bce, BaiduYunMessage message, BaiduYunConfig config)
 {
     BceObject = bce;
     Message   = message;
     Config    = config;
 }
Exemplo n.º 8
0
 public BceObject(BaiduYunConfig config)
 {
     _config = config ?? throw new ArgumentNullException(nameof(config));
 }
Exemplo n.º 9
0
 public static string Get(BaiduYunConfig config)
 {
     return($"{GetHttpPrefix(config)}://{GetApiServerUrl(config)}");
 }