Exemplo n.º 1
0
        public async Task <T> ExecuteAsync <T>(IQPayRequest <T> request) where T : QPayResponse
        {
            // 字典排序
            var sortedTxtParams = new QPayDictionary(request.GetParameters())
            {
                { APPID, Options.AppId },
                { MCHID, Options.MchId },
                { NONCE_STR, Guid.NewGuid().ToString("N") }
            };

            sortedTxtParams.Add(SIGN, QPaySignature.SignWithKey(sortedTxtParams, Options.Key));

            var content = HttpClientEx.BuildContent(sortedTxtParams);

            Logger.LogInformation(0, "Request Content:{content}", content);

            var rspContent = await Client.DoPostAsync(request.GetRequestUrl(), content);

            Logger.LogInformation(1, "Response Content:{content}", rspContent);

            var parser = new QPayXmlParser <T>();
            var rsp    = parser.Parse(rspContent);

            CheckResponseSign(rsp);
            return(rsp);
        }
Exemplo n.º 2
0
        public async Task <T> ExecuteAsync <T>(IQPayRequest <T> request) where T : QPayResponse
        {
            // 字典排序
            var sortedTxtParams = new QPayDictionary(request.GetParameters())
            {
                { MCHID, Options.MchId },
                { NONCE_STR, Guid.NewGuid().ToString("N") }
            };

            if (string.IsNullOrEmpty(sortedTxtParams.GetValue(APPID)))
            {
                sortedTxtParams.Add(APPID, Options.AppId);
            }

            sortedTxtParams.Add(SIGN, QPaySignature.SignWithKey(sortedTxtParams, Options.Key));

            var content = HttpClientEx.BuildContent(sortedTxtParams);

            Logger?.LogTrace(0, "Request:{content}", content);

            var body = await Client.DoPostAsync(request.GetRequestUrl(), content);

            Logger?.LogTrace(1, "Response:{body}", body);

            var parser = new QPayXmlParser <T>();
            var rsp    = parser.Parse(body);

            CheckResponseSign(rsp);
            return(rsp);
        }
Exemplo n.º 3
0
        public async Task <T> ExecuteAsync <T>(IQPayRequest <T> request, QPayOptions options) where T : QPayResponse
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (string.IsNullOrEmpty(options.MchId))
            {
                throw new ArgumentNullException(nameof(options.MchId));
            }

            if (string.IsNullOrEmpty(options.Key))
            {
                throw new ArgumentNullException(nameof(options.Key));
            }

            var sortedTxtParams = new QPayDictionary(request.GetParameters());

            request.PrimaryHandler(options, sortedTxtParams);

            var client = _httpClientFactory.CreateClient(nameof(QPayClient));
            var body   = await client.PostAsync(request.GetRequestUrl(), sortedTxtParams);

            var parser = new QPayXmlParser <T>();
            var rsp    = parser.Parse(body);

            if (request.GetNeedCheckSign())
            {
                CheckResponseSign(rsp, options);
            }

            return(rsp);
        }
Exemplo n.º 4
0
        public async Task <T> ExecuteAsync <T>(IQPayRequest <T> request) where T : QPayResponse
        {
            // 字典排序
            var sortedTxtParams = new QPayDictionary(request.GetParameters())
            {
                { APPID, Options.AppId },
                { MCHID, Options.MchId },
                { NONCE_STR, Guid.NewGuid().ToString("N") }
            };

            sortedTxtParams.Add(SIGN, QPaySignature.SignWithKey(sortedTxtParams, Options.Key));

            var rspContent = await Client.DoPostAsync(request.GetRequestUrl(), sortedTxtParams);

            if (string.IsNullOrEmpty(rspContent))
            {
                throw new Exception("rspContent is Empty!");
            }

            var parser = new QPayXmlParser <T>();
            var rsp    = parser.Parse(rspContent);

            CheckResponseSign(rsp);
            return(rsp);
        }
Exemplo n.º 5
0
        public async Task <T> ExecuteAsync <T>(IQPayRequest <T> request, string optionsName) where T : QPayResponse
        {
            var options         = string.IsNullOrEmpty(optionsName) ? _optionsSnapshotAccessor.Value : _optionsSnapshotAccessor.Get(optionsName);
            var sortedTxtParams = new QPayDictionary(request.GetParameters())
            {
                { MCHID, options.MchId },
                { NONCE_STR, Guid.NewGuid().ToString("N") }
            };

            if (request is QPayEPayQueryRequest)
            {
            }
            else if (request is QPayEPayStatementDownRequest)
            {
            }
            else
            {
                if (string.IsNullOrEmpty(sortedTxtParams.GetValue(APPID)))
                {
                    sortedTxtParams.Add(APPID, options.AppId);
                }
            }

            sortedTxtParams.Add(SIGN, QPaySignature.SignWithKey(sortedTxtParams, options.Key));

            var content = QPayUtility.BuildContent(sortedTxtParams);

            _logger.Log(options.LogLevel, "Request:{content}", content);

            using (var client = _clientFactory.CreateClient())
            {
                var body = await client.DoPostAsync(request.GetRequestUrl(), content);

                _logger.Log(options.LogLevel, "Response:{body}", body);

                var parser = new QPayXmlParser <T>();
                var rsp    = parser.Parse(body);

                if (request.IsCheckResponseSign())
                {
                    CheckResponseSign(rsp, options);
                }

                return(rsp);
            }
        }
Exemplo n.º 6
0
        public async Task <T> ExecuteAsync <T>(IQPayRequest <T> request) where T : QPayResponse
        {
            // 字典排序
            var sortedTxtParams = new QPayDictionary(request.GetParameters())
            {
                { APPID, Options.AppId },
                { MCHID, Options.MchId },
                { NONCE_STR, Guid.NewGuid().ToString("N") }
            };

            sortedTxtParams.Add(SIGN, Md5.GetMD5WithKey(sortedTxtParams, Options.Key));

            var body = await Client.DoPostAsync(request.GetRequestUrl(), sortedTxtParams);

            var parser = new QPayXmlParser <T>();
            var rsp    = parser.Parse(body);

            CheckResponseSign(rsp);
            return(rsp);
        }
Exemplo n.º 7
0
 public async Task <T> ExecuteAsync <T>(IQPayRequest <T> request) where T : QPayResponse
 {
     return(await ExecuteAsync(request, null));
 }