Esempio n. 1
0
        protected override async Task <object> GetTaskResult(ApiActionContext context)
        {
            var response = context.ResponseMessage;

            var s = await response.Content.ReadAsStringAsync();

            try
            {
                var json = JObject.Parse(s);
                if (json.Property("code") != null)
                {
                    return(json.ToObject <VariableResponseData>());
                }

                return(new ResponseData()
                {
                    Code = "500",
                    ErrorMsg = s
                });
            }
            catch (Exception e)
            {
                ExceptionHandleResolver.ResolveHandler()?.Invoke(e);
            }

            return(new VariableResponseData()
            {
                Code = response.StatusCode.ToString(),
                ErrorMsg = "发送失败",
            });
        }
Esempio n. 2
0
        public RongCloudClient(RongCloudConfig config, Action <Exception> exceptionHandler = null)
        {
            _config      = config ?? throw new ArgumentNullException(nameof(config));
            _rongAccount = config.Account ?? throw new ArgumentNullException(nameof(config.Account));
            _proxy       = HttpApi.Create <IRongCloudSmsApis>();

            var globalHandle = ExceptionHandleResolver.ResolveHandler();

            globalHandle     += exceptionHandler;
            _exceptionHandler = globalHandle;
        }
Esempio n. 3
0
        public SendCloudClient(SendCloudConfig config, Action <Exception> exceptionHandler = null)
        {
            _config           = config ?? throw new ArgumentNullException(nameof(config));
            _sendCloudAccount = config.Account ?? throw new ArgumentNullException(nameof(config.Account));
            _proxy            = HttpApiClient.Create <ISendCloudApi>();

            var globalHandle = ExceptionHandleResolver.ResolveHandler();

            globalHandle     += exceptionHandler;
            _exceptionHandler = globalHandle;
        }
Esempio n. 4
0
        /// <summary>
        /// 初始化一个<see cref="KdniaoClient"/>类型的实例
        /// </summary>
        /// <param name="config">配置</param>
        /// <param name="exceptionHandler">异常处理操作</param>
        public KdniaoClient(KdniaoConfig config, Action <Exception> exceptionHandler = null)
        {
            _config  = config ?? throw new ArgumentNullException(nameof(config));
            _account = config.Account ?? throw new ArgumentNullException(nameof(config.Account));
            _proxy   = HttpApi.Create <IKdniaoApi>();

            var globalHandle = ExceptionHandleResolver.ResolveHandler();

            globalHandle     += exceptionHandler;
            _exceptionHandler = globalHandle;
        }
Esempio n. 5
0
        public YunpianSmsClient(YunpianConfig config, Action <Exception> exceptionHandler = null)
        {
            _config         = config ?? throw new ArgumentNullException(nameof(config));
            _yunpianAccount = config.Account ?? throw new ArgumentNullException(nameof(config.Account));
            _proxy          = new YunpianClient(_yunpianAccount.ApiKey).Init();

            var globalHandle = ExceptionHandleResolver.ResolveHandler();

            globalHandle     += exceptionHandler;
            _exceptionHandler = globalHandle;
        }
Esempio n. 6
0
        public AliyunDysmsClient(AliyunDysmsConfig config, Action <Exception> exceptionHandler = null)
        {
            _config             = config ?? throw new ArgumentNullException(nameof(config));
            _aliyunDysmsAccount = config.Account ?? throw new ArgumentNullException(nameof(config.Account));
            _proxy = WebApiClientCreator.Create(config);

            var globalHandle = ExceptionHandleResolver.ResolveHandler();

            globalHandle     += exceptionHandler;
            _exceptionHandler = globalHandle;
        }
Esempio n. 7
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;
        }
Esempio n. 8
0
        public TencentSmsClient(TencentSmsConfig config, Action <Exception> exceptionHandler = null)
        {
            _config         = config ?? throw new ArgumentNullException(nameof(config));
            _tencentAccount = config.Account ?? throw new ArgumentNullException(nameof(config.Account));

            _proxy = new TencentSmsSenderProxy(_tencentAccount.AppId, _tencentAccount.AppKey);

            var globalHandle = ExceptionHandleResolver.ResolveHandler();

            globalHandle     += exceptionHandler;
            _exceptionHandler = globalHandle;
        }
Esempio n. 9
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;
        }
Esempio n. 10
0
        public YuntongxunSmsClient(YuntongxunSmsConfig config, Action <Exception> exceptionHandler = null)
        {
            _config            = config ?? throw new ArgumentNullException(nameof(config));
            _yuntongxunAccount = config.Account ?? throw new ArgumentNullException(nameof(config.Account));

            _proxy = _config.Production
                ? HttpApiClient.Create <ICloopenApis>("https://app.cloopen.com:8883")
                : HttpApiClient.Create <ICloopenApis>("https://sandboxapp.cloopen.com:8883");

            var globalHandle = ExceptionHandleResolver.ResolveHandler();

            globalHandle     += exceptionHandler;
            _exceptionHandler = globalHandle;
        }
Esempio n. 11
0
        public WeimiSmsClient(WeimiSmsConfig config, Action <Exception> exceptionHandler = null)
        {
            _config          = config ?? throw new ArgumentNullException(nameof(config));
            _weimiSmsAccount = config.Account ?? throw new ArgumentNullException(nameof(config.Account));

            _proxy = config.Security
                ? HttpApi.Create <IWeimiSmsApi>("https://api.weimi.cc")
                : HttpApi.Create <IWeimiSmsApi>("http://api.weimi.cc");

            var globalHandle = ExceptionHandleResolver.ResolveHandler();

            globalHandle     += exceptionHandler;
            _exceptionHandler = globalHandle;
        }
Esempio n. 12
0
        public AliyunDysmsClient(AliyunDysmsConfig config, Action <Exception> exceptionHandler = null)
        {
            _config             = config ?? throw new ArgumentNullException(nameof(config));
            _aliyunDysmsAccount = config.Account ?? throw new ArgumentNullException(nameof(config.Account));

            _proxy = config.Security
                ? HttpApiClient.Create <IAliyunDysmsApi>("https://dysmsapi.aliyuncs.com")
                : HttpApiClient.Create <IAliyunDysmsApi>("http://dysmsapi.aliyuncs.com");

            var globalHandle = ExceptionHandleResolver.ResolveHandler();

            globalHandle     += exceptionHandler;
            _exceptionHandler = globalHandle;
        }
Esempio n. 13
0
        public ChuangLanClient(ChuangLanConfig config, Action <Exception> exceptionHandler = null)
        {
            _config = config ?? throw new ArgumentNullException(nameof(config));
            _chuangLanCodeAccount = config.CodeAccount ?? throw new ArgumentNullException(nameof(config.CodeAccount));
            if (config.UseMarketingSms)
            {
                _chuangLanMarketingAccount = config.MarketingAccount ??
                                             throw new ArgumentNullException(nameof(config.MarketingAccount));
            }
            _proxy = HttpApiClient.Create <IChuangLanApi>();

            var globalHandle = ExceptionHandleResolver.ResolveHandler();

            globalHandle     += exceptionHandler;
            _exceptionHandler = globalHandle;
        }
Esempio n. 14
0
        public JdCloudSmsClient(JdCloudSmsConfig config, Action <Exception> exceptionHandler = null)
        {
            _config         = config ?? throw new ArgumentNullException(nameof(config));
            _jdcloudAccount = config.Account ?? throw new ArgumentNullException(nameof(config.Account));

            CredentialsProvider credentialsProvider = new StaticCredentialsProvider(_jdcloudAccount.AccessKey, _jdcloudAccount.SecretKey);

            _client = new SmsClient.DefaultBuilder()
                      .CredentialsProvider(credentialsProvider)
                      .HttpRequestConfig(new HttpRequestConfig(_config.Security ? Protocol.HTTPS : Protocol.HTTP, _config.RequestTimeout))
                      .Build();

            var globalHandle = ExceptionHandleResolver.ResolveHandler();

            globalHandle     += exceptionHandler;
            _exceptionHandler = globalHandle;
        }