Esempio n. 1
0
        public async Task <T> ExecuteAsync <T>(IJDPayNPP10Request <T> request, JDPayOptions options) where T : JDPayResponse
        {
            var sortedTxtParams = new JDPayDictionary(request.GetParameters())
            {
                { JDPayContants.CUSTOMER_NO, options.CustomerNo },
                { JDPayContants.SIGN_TYPE, options.SignType }
            };

            var isEncrypt = false;

            if (request is JDPayDefrayPayRequest)
            {
                isEncrypt = true;
            }

            var encryptDic = JDPaySecurity.EncryptData(options.PrivateCret, options.Password, options.PublicCert, sortedTxtParams, options.SingKey, options.EncryptType, isEncrypt);

            var content = JDPayUtility.BuildQuery(encryptDic);

            using (var client = _httpClientFactory.CreateClient(nameof(JDPayClient)))
            {
                var body = await client.DoPostAsync(request.GetRequestUrl(), content, "application/x-www-form-urlencoded");

                // 验签
                var dictionary = JsonConvert.DeserializeObject <JDPayDictionary>(body);
                if (!JDPaySecurity.VerifySign(dictionary, options.SingKey))
                {
                    throw new JDPayException("sign check fail: check Sign and Data Fail!");
                }

                var rsp = JsonConvert.DeserializeObject <T>(body);
                rsp.Body = body;
                return(rsp);
            }
        }
Esempio n. 2
0
        public async Task <T> ExecuteAsync <T>(IJDPayNPP10Request <T> request) where T : JDPayResponse
        {
            var sortedTxtParams = new JDPayDictionary(request.GetParameters())
            {
                { Contants.CUSTOMER_NO, Options.CustomerNo },
                { Contants.SIGN_TYPE, Options.SignType }
            };

            var isEncrypt = false;

            if (request is JDPayDefrayPayRequest)
            {
                isEncrypt = true;
            }

            var encryptDic = JDPaySecurity.EncryptData(Options.PrivateCret, Options.Password, Options.PublicCert, sortedTxtParams, Options.SingKey, Options.EncryptType, isEncrypt);

            var content = HttpClientEx.BuildQuery(encryptDic);

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

            var body = await Client.DoPostAsync(request.GetRequestUrl(), content, "application/x-www-form-urlencoded");

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

            var rsp = JsonConvert.DeserializeObject <T>(body);

            // 验签
            var dic = JsonConvert.DeserializeObject <JDPayDictionary>(body);

            if (!JDPaySecurity.VerifySign(dic, Options.SingKey))
            {
                throw new Exception("sign check fail: check Sign and Data Fail!");
            }

            rsp.Body = body;
            return(rsp);
        }