Exemplo n.º 1
0
        public async Task <T> ExecuteAsync <T>(IWeChatPayPrivacyPostRequest <T> request, WeChatPayOptions options) where T : WeChatPayResponse
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (string.IsNullOrEmpty(options.MchId))
            {
                throw new WeChatPayException($"options.{nameof(WeChatPayOptions.MchId)} is Empty!");
            }

            if (string.IsNullOrEmpty(options.Certificate))
            {
                throw new WeChatPayException($"options.{nameof(WeChatPayOptions.Certificate)} is Empty!");
            }

            var cert = await _platformCertificateManager.GetCertificateAsync(this, options);

            // 加密敏感信息
            EncryptPrivacyProperty(request.GetBodyModel(), cert.Certificate.GetRSAPublicKey());

            var client = _httpClientFactory.CreateClient(Name);

            var(headers, body, statusCode) = await client.PostAsync(request, options, cert.SerialNo);

            var parser   = new WeChatPayResponseJsonParser <T>();
            var response = parser.Parse(body, statusCode);

            await CheckResponseSignAsync(headers, body, options);

            return(response);
        }
Exemplo n.º 2
0
        public async Task <T> ExecuteAsync <T>(IWeChatPayPostRequest <T> request, WeChatPayOptions options) where T : WeChatPayResponse
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (string.IsNullOrEmpty(options.MchId))
            {
                throw new WeChatPayException($"options.{nameof(WeChatPayOptions.MchId)} is Empty!");
            }

            if (string.IsNullOrEmpty(options.Certificate))
            {
                throw new WeChatPayException($"options.{nameof(WeChatPayOptions.Certificate)} is Empty!");
            }

            var client = _httpClientFactory.CreateClient(Name);

            var(headers, body, statusCode) = await client.PostAsync(request, options);

            var parser   = new WeChatPayResponseJsonParser <T>();
            var response = parser.Parse(body, statusCode);

            await CheckResponseSignAsync(headers, body, options);

            return(response);
        }