Ejemplo n.º 1
0
        public async Task <T> ExecuteAsync <T>(IQPayCertificateRequest <T> request, string certificateName = "Default") 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 = QPayUtility.BuildContent(sortedTxtParams);

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

            using (var client = ClientFactory.CreateClient(QPayOptions.CertificateClientName + "." + certificateName))
            {
                var body = await HttpClientUtility.DoPostAsync(client, request.GetRequestUrl(), content);

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

                var parser = new QPayXmlParser <T>();
                var rsp    = parser.Parse(body);
                CheckResponseSign(rsp);
                return(rsp);
            }
        }
Ejemplo n.º 2
0
        public void PrimaryHandler(QPayOptions options, QPayDictionary sortedTxtParams)
        {
            sortedTxtParams.Add(QPayConsts.NONCE_STR, QPayUtility.GenerateNonceStr());
            sortedTxtParams.Add(QPayConsts.MCH_ID, options.MchId);

            sortedTxtParams.Add(QPayConsts.SIGN, QPaySignature.SignWithKey(sortedTxtParams, options.Key));
        }
Ejemplo n.º 3
0
        public async Task <T> ExecuteAsync <T>(IQPayCertificateRequest <T> request, string optionsName, string certificateName) 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 (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 = string.IsNullOrEmpty(certificateName) ? _clientFactory.CreateClient() : _clientFactory.CreateClient(certificateName))
            {
                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);
            }
        }