簡體   English   中英

WP8中的應用內購買收據解析

[英]In-App Purchase Receipt Parsing In WP8

我嘗試在應用購買插件中編寫phonegap WP8。 在我的插件中,我想獲取“訂單ID”。 我知道有可能,因此收據具有唯一的ID。

當我嘗試這個

string receipt = await CurrentApp.RequestProductPurchaseAsync(productListing.ProductId, false);

收據字符串是這樣的:

<?xml version="1.0" ?> 
- <Receipt Version="1.0" CertificateId="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" xmlns="http://schemas.microsoft.com/windows/2012/store/receipt">
  <ProductReceipt PurchasePrice="1.0" PurchaseDate="10:32:31 AM" Id="0fba8b37-95ed-4c57-b16a-00f9ac25d696" AppId="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ProductId="img.2" ProductType="Consumable" PublisherUserId="00000000000000000000000000000000000000000000" PublisherDeviceId="00000000-0000-0000-0000-000000000000" MicrosoftProductId="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" /> 
- <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
- <SignedInfo>
  <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-xxxx-00000000" /> 
  <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /> 
- <Reference URI="">
- <Transforms>
  <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /> 
  </Transforms>
  <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /> 
  <DigestValue>whocares</DigestValue> 
  </Reference>
  </SignedInfo>
  <SignatureValue>whocares</SignatureValue> 
  </Signature>
  </Receipt>

如何從此字符串獲取ID(它是ProductReceipt元素的屬性)? 該鏈接和任何其他類似的鏈接對我不起作用。

檢查您的收據,其中不包含“ order-id”,但在“ Productreceipt”中具有“ Id”。 我認為您需要該ID。

這是我為我的項目實施的解析xml收據的方法。 它會提供Dictionary作為響應,您可以在字典中輕松找到ID。

private string ParseReceiptData(string xmlReceipt)
    {
        Dictionary AttributeDict = new Dictionary();
        var xd = XDocument.Parse(xmlReceipt).Descendants();
        foreach (var node in xd)
        {
            if (node.Name.LocalName.Equals("ProductReceipt"))
            {
                var attribute = node.Attributes();
                foreach (var attrib in attribute)
                {
                    AttributeDict.Add(attrib.Name.LocalName, attrib.Value);
                }
            }
        }
        var purchaseDate = Convert.ToDateTime(AttributeDict["PurchaseDate"]);
        var Expdate = purchaseDate.Add(TimeSpan.FromDays(30)).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
        AttributeDict.Add("ExpiryDate", Expdate);
        return JsonConvert.SerializeObject(AttributeDict);
    }

我找到了。 實際上,這非常容易。

XDocument xml = XDocument.Parse(receipt);
XElement productReceipt = xml.Root.Elements().FirstOrDefault();
string orderId = productReceipt.Attribute("Id").Value;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM