public Task <T> PageReqDataExecuteAsync <T>(ILianLianPayRequest <T> request) where T : LianLianPayResponse
        {
            // 字典排序
            var txtParams = new LianLianPayDictionary(request.GetParameters())
            {
                { OID_PARTNER, Options.OidPartner },
                { SIGN_TYPE, Options.SignType },
                { BUSI_PARTNER, Options.BusiPartner },
            };

            // 添加签名
            var signContent = LianLianPaySecurity.GetSignContent(txtParams);

            txtParams.Add(SIGN, MD5WithRSA.SignData(signContent, PrivateKey));

            var content = Serialize(txtParams);

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

            var body   = BuildReqDataHtmlRequest(request.GetRequestUrl(), content);
            var parser = new LianLianPayJsonParser <T>();
            var rsp    = parser.Parse(body);

            return(Task.FromResult(rsp));
        }
Exemple #2
0
        public async Task <T> ExecuteAsync <T>(HttpRequest request) where T : LianLianPayNotifyResponse
        {
            if (request.HasFormContentType)
            {
                var parameters = await GetParametersAsync(request);

                var query = HttpClientEx.BuildQuery(parameters);
                Logger.LogInformation(0, "Request:{query}", query);

                var parser = new LianLianPayDictionaryParser <T>();
                var rsp    = parser.Parse(parameters);
                CheckNotifySign(parameters);
                return(rsp);
            }
            else if (request.HasTextJsonContentType())
            {
                var body = await new StreamReader(request.Body).ReadToEndAsync();
                Logger.LogInformation(0, "Request:{body}", body);

                var parser = new LianLianPayJsonParser <T>();
                var rsp    = parser.Parse(body);
                CheckNotifySign(rsp.Parameters);
                return(rsp);
            }
            else
            {
                throw new Exception("sign check fail: check Sign and Data Fail!");
            }
        }
Exemple #3
0
        public async Task <T> ExecuteAsync <T>(ILianLianPayRequest <T> request, string optionsName) where T : LianLianPayResponse
        {
            var options   = string.IsNullOrEmpty(optionsName) ? _optionsSnapshotAccessor.Value : _optionsSnapshotAccessor.Get(optionsName);
            var txtParams = new LianLianPayDictionary(request.GetParameters())
            {
                { OID_PARTNER, options.OidPartner },
                { SIGN_TYPE, options.SignType }
            };

            if (request is LianLianPayCreateBillRequest || request is LianLianPayUnifiedCardBindRequest)
            {
                txtParams.Add(TIME_STAMP, DateTime.Now);
                txtParams.Add(BUSI_PARTNER, options.BusiPartner);
            }

            // 添加签名
            var signContent = LianLianPaySecurity.GetSignContent(txtParams);

            txtParams.Add(SIGN, MD5WithRSA.SignData(signContent, options.PrivateKey));

            var content = string.Empty;

            if (request is LianLianPayPaymentRequest || request is LianLianPayConfirmPaymentRequest)
            {
                var plaintext  = Serialize(txtParams);
                var ciphertext = LianLianPaySecurity.Encrypt(plaintext, options.PublicKey);
                content = $"{{\"pay_load\":\"{ciphertext}\",\"oid_partner\":\"{options.OidPartner}\"}}";
            }
            else
            {
                content = Serialize(txtParams);
            }

            _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 LianLianPayJsonParser <T>();
                var rsp    = parser.Parse(body);

                // 不签名参数
                var excludePara = new List <string>();
                if (request is LianLianPayOrderQueryRequest)
                {
                    excludePara.Add("bank_name");
                    excludePara.Add("card_no");
                }
                else if (request is LianLianPayQueryBankCardBindListRequest)
                {
                    excludePara.Add("agreement_list");
                }

                CheckNotifySign(rsp, excludePara, options);
                return(rsp);
            }
        }
        public async Task <T> ExecuteAsync <T>(HttpRequest request) where T : LianLianPayNotifyResponse
        {
            if (request.HasFormContentType)
            {
                var parameters = await GetParametersAsync(request);

                var query = LianLianPayUtility.BuildQuery(parameters);
                Logger?.LogTrace(0, "Request:{query}", query);

                var parser = new LianLianPayDictionaryParser <T>();
                var rsp    = parser.Parse(parameters);
                CheckNotifySign(parameters);
                return(rsp);
            }
            else if (request.HasTextJsonContentType())
            {
                var body = await new StreamReader(request.Body).ReadToEndAsync();
                Logger?.LogTrace(0, "Request:{body}", body);

                var parser = new LianLianPayJsonParser <T>();
                var rsp    = parser.Parse(body);
                CheckNotifySign(rsp.Parameters);
                return(rsp);
            }
            else
            {
                throw new Exception("content type is not supported");
            }
        }
Exemple #5
0
        public async Task <T> ExecuteAsync <T>(HttpRequest request, string optionsName) where T : LianLianPayNotify
        {
            var options = _optionsSnapshotAccessor.Get(optionsName);

            if (request.HasFormContentType)
            {
                var parameters = await GetParametersAsync(request);

                var query = LianLianPayUtility.BuildQuery(parameters);
                _logger.Log(options.LogLevel, "Request:{query}", query);

                var parser = new LianLianPayDictionaryParser <T>();
                var rsp    = parser.Parse(parameters);
                CheckNotifySign(parameters, options);
                return(rsp);
            }

            if (request.HasTextJsonContentType())
            {
                var body = await new StreamReader(request.Body).ReadToEndAsync();
                _logger.Log(options.LogLevel, "Request:{body}", body);

                var parser = new LianLianPayJsonParser <T>();
                var rsp    = parser.Parse(body);
                CheckNotifySign(rsp.Parameters, options);
                return(rsp);
            }

            throw new LianLianPayException("content type is not supported");
        }
Exemple #6
0
        public async Task <T> ExecuteAsync <T>(ILianLianPayRequest <T> request) where T : LianLianPayResponse
        {
            // 字典排序
            var txtParams = new LianLianPayDictionary(request.GetParameters())
            {
                { OID_PARTNER, Options.OidPartner },
                { SIGN_TYPE, Options.SignType },
            };

            // 添加签名
            var signContent = LianLianPaySecurity.GetSignContent(txtParams);

            txtParams.Add(SIGN, MD5WithRSA.SignData(signContent, PrivateKey));

            var content = string.Empty;

            if (request is LianLianPayPaymentRequest || request is LianLianPayConfirmPaymentRequest)
            {
                var plaintext = JsonConvert.SerializeObject(txtParams, new JsonSerializerSettings()
                {
                    NullValueHandling = NullValueHandling.Ignore
                });
                var ciphertext = LianLianPaySecurity.Encrypt(plaintext, PublicKey);
                content = @"{""pay_load"":""" + ciphertext + @""",""oid_partner"":""" + Options.OidPartner + @"""}";
            }
            else
            {
                content = JsonConvert.SerializeObject(txtParams, new JsonSerializerSettings()
                {
                    NullValueHandling = NullValueHandling.Ignore
                });
            }
            Logger.LogInformation(0, "Request:{content}", content);

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

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

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

            // 不签名参数
            var excludePara = new List <string>();

            if (request is LianLianPayOrderQueryRequest)
            {
                excludePara.Add("bank_name");
                excludePara.Add("card_no");
            }
            else if (request is LianLianPayQueryBankCarBindListRequest)
            {
                excludePara.Add("agreement_list");
            }

            CheckNotifySign(rsp.Parameters, excludePara);
            return(rsp);
        }
        public async Task <T> ExecuteAsync <T>(ILianLianPayRequest <T> request) where T : LianLianPayResponse
        {
            // 字典排序
            var txtParams = new LianLianPayDictionary(request.GetParameters())
            {
                { OID_PARTNER, Options.OidPartner },
                { SIGN_TYPE, Options.SignType },
            };

            // 添加签名
            var signContent = LianLianPaySecurity.GetSignContent(txtParams);

            txtParams.Add(SIGN, MD5WithRSA.SignData(signContent, Options.PrivateKey));

            var content = string.Empty;

            if (request is LianLianPayPaymentRequest || request is LianLianPayConfirmPaymentRequest)
            {
                var plaintext  = Serialize(txtParams);
                var ciphertext = LianLianPaySecurity.Encrypt(plaintext, Options.PublicKey);
                content = @"{""pay_load"":""" + ciphertext + @""",""oid_partner"":""" + Options.OidPartner + @"""}";
            }
            else
            {
                content = Serialize(txtParams);
            }
            Logger?.LogTrace(0, "Request:{content}", content);

            using (var client = ClientFactory.CreateClient(LianLianPayOptions.DefaultClientName))
            {
                var body = await HttpClientUtility.DoPostAsync(client, request.GetRequestUrl(), content);

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

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

                // 不签名参数
                var excludePara = new List <string>();
                if (request is LianLianPayOrderQueryRequest)
                {
                    excludePara.Add("bank_name");
                    excludePara.Add("card_no");
                }
                else if (request is LianLianPayQueryBankCarBindListRequest)
                {
                    excludePara.Add("agreement_list");
                }

                CheckNotifySign(rsp.Parameters, excludePara);
                return(rsp);
            }
        }
Exemple #8
0
        public Task <T> PageExecuteAsync <T>(ILianLianPayRequest <T> request, string reqMethod) where T : LianLianPayResponse
        {
            var txtParams = new LianLianPayDictionary(request.GetParameters())
            {
                { OID_PARTNER, Options.OidPartner },
                { SIGN_TYPE, Options.SignType },
                { BUSI_PARTNER, Options.BusiPartner },
                { TIMESTAMP, DateTime.Now },
            };

            // 添加签名
            var signContent = LianLianPaySecurity.GetSignContent(txtParams);

            txtParams.Add(SIGN, MD5WithRSA.SignData(signContent, PrivateKey));

            var body = string.Empty;

            if (reqMethod == "GET")
            {
                //拼接get请求的url
                var tmpUrl = request.GetRequestUrl();
                if (txtParams != null && txtParams.Count > 0)
                {
                    if (tmpUrl.Contains("?"))
                    {
                        tmpUrl = tmpUrl + "&" + HttpClientEx.BuildQuery(txtParams);
                    }
                    else
                    {
                        tmpUrl = tmpUrl + "?" + HttpClientEx.BuildQuery(txtParams);
                    }
                }
                body = tmpUrl;
                Logger.LogInformation(0, "Request Url:{body}", body);
            }
            else
            {
                //输出post表单
                body = BuildHtmlRequest(request.GetRequestUrl(), txtParams);
                Logger.LogInformation(0, "Request Html:{body}", body);
            }

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

            return(Task.FromResult(rsp));
        }
        public async Task <T> ExecuteAsync <T>(HttpRequest request, LianLianPayOptions options) where T : LianLianPayNotify
        {
            if (request.HasFormContentType)
            {
                var parameters = await GetParametersAsync(request);

                var parser = new LianLianPayDictionaryParser <T>();
                var rsp    = parser.Parse(parameters);
                CheckNotifySign(parameters, options);
                return(rsp);
            }

            if (request.HasTextJsonContentType())
            {
                var body = await new StreamReader(request.Body).ReadToEndAsync();

                var parser = new LianLianPayJsonParser <T>();
                var rsp    = parser.Parse(body);
                CheckNotifySign(rsp.Parameters, options);
                return(rsp);
            }

            throw new LianLianPayException("content type is not supported");
        }