Example #1
0
        private JdPayDictionary GetEncryptDicContent <T>(IJdPayRequest <T> request, IDictionary <string, string> dic) where T : JdPayResponse
        {
            var signDic = new JdPayDictionary(dic)
            {
                { VERSION, request.GetApiVersion() },
                { MERCHANT, Options.Merchant },
            };

            var sign = JdPaySignature.RSASign(signDic, RSAPrivateParameters);

            var encyptDic = new JdPayDictionary
            {
                { VERSION, request.GetApiVersion() },
                { MERCHANT, Options.Merchant },
                { SIGN, sign }
            };

            foreach (var item in dic)
            {
                if (!string.IsNullOrEmpty(item.Value))
                {
                    encyptDic.Add(item.Key, DES3.EncryptECB(DesKey, item.Value));
                }
            }
            return(encyptDic);
        }
Example #2
0
        public async Task <T> ExecuteAsync <T>(HttpRequest request) where T : JdPayNotifyResponse
        {
            if (request.ContentType == "application/x-www-form-urlencoded")
            {
                var dic = new JdPayDictionary();
                foreach (var item in request.Form)
                {
                    if (!string.IsNullOrEmpty(item.Value))
                    {
                        if (item.Key == "sign")
                        {
                            dic.Add(item.Key, item.Value);
                        }
                        else
                        {
                            dic.Add(item.Key, DES3.DecryptECB(DesKey, item.Value));
                        }
                    }
                }

                var query = HttpClientEx.BuildQuery(dic);
                Logger.LogInformation(1, "Request Content:{query}", query);

                var parser = new JdPayDictionaryParser <T>();
                var rsp    = parser.Parse(dic);

                CheckNotifySign(dic, RSAPrivateParameters);
                return(rsp);
            }
            else
            {
                var body = await new StreamReader(request.Body).ReadToEndAsync();
                Logger.LogInformation(1, "Request Content:{body}", body);

                var rsp = DecryptResponseXml <T>(JdPayUtil.FotmatXmlString(body));
                return(rsp);
            }
        }