Пример #1
0
        protected async Task <XDocument> Send(TDispatchMessage message, string command)
        {
            XDocument value      = BuildRequest(message);
            string    CipherText = _crypter.Encrypt(value.Root.ToString(SaveOptions.DisableFormatting), _options.SecretKey);
            string    sign       = Signature(CipherText);
            XDocument Message    = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
            XElement  head       = new XElement("head");

            head.Add(new XElement("version", "2600"));
            head.Add(new XElement("command", command));
            head.Add(new XElement("venderId", message.LdpMerchanerId));
            head.Add(new XElement("messageId", message.LdpOrderId));
            head.Add(new XElement("md", sign));
            XElement body = new XElement("body", CipherText);

            Message.Add(new XElement("message", head, body));
            MemoryStream ms = new MemoryStream();

            Message.WriteTo(ms, SaveOptions.DisableFormatting | SaveOptions.OmitDuplicateNamespaces, false);
            HttpContent         content         = new StreamContent(ms);
            HttpResponseMessage responseMessage = (await _httpClient.PostAsync("", content)).EnsureSuccessStatusCode();

            byte[] bytes = await responseMessage.Content.ReadAsByteArrayAsync();

            string msg = Encoding.UTF8.GetString(bytes);

            return(XDocument.Load(msg));
        }
Пример #2
0
        protected async Task <string> Send(TExecuteMessage message)
        {
            string     value      = BuildRequest(message);
            string     CipherText = _crypter.Encrypt(value, _options.SecretKey);
            string     sign       = Signature(_command, message.LdpMerchanerId, CipherText, out DateTime timestamp);
            ReqContent reqcon     = new ReqContent()
            {
                version   = "1.0",
                apiCode   = _command,
                partnerId = message.LdpMerchanerId,
                messageId = timestamp.ToString("yyyyMMddHHmm"),
                content   = CipherText,
                hmac      = sign.ToLower()
            };
            string              json            = JsonExtensions.ToJsonString(reqcon);
            HttpContent         content         = new StringContent(json, Encoding.UTF8, "application/json");
            HttpResponseMessage responseMessage = (await _httpClient.PostAsync("", content)).EnsureSuccessStatusCode();

            byte[] bytes = await responseMessage.Content.ReadAsByteArrayAsync();

            string msg = Encoding.UTF8.GetString(bytes);

            return(msg);
        }