validationWindows Phone应用程序内购买收据

我正在开发Windows Phone 8应用程序。 我的应用将包括应用内购买。 我想了解收据的概念。 根据我的理解,在有人在我的应用程序内购买产品后,会生成收据。

          {Identifier4}   {HashedValue}   

大! 我不知道如何判断这张收据是否来自微软的服务器。 有人可以向我解释如何validation吗? 我看到了这个: http : //code.msdn.microsoft.com/wpapps/In-app-purchase-receipt-c3e0bce4然而,这对我来说没有意义。 我不明白示例中的证书。 “IapReceiptProduction.cer”是一套固定的东西吗? 或者只是这个样本?

如果这是一个愚蠢的问题,我很抱歉。

“收据”XML元素中的“CertificateId”属性确定用于对Windowsapp store收据进行签名的证书。 获得CertificateID(样本中的“{Identifier1}”)后,您可以从下面的代码示例中指定的URL下载所需的证书作为“certificateUrl”。 这是您以编程方式下载证书的方式:

 public static X509Certificate2 RetrieveCertificate(string certificateId) { const int MaxCertificateSize = 10000; // We are attempting to retrieve the following url. The getAppReceiptAsync website at // http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.store.currentapp.getappreceiptasync.aspx // lists the following format for the certificate url. String certificateUrl = String.Format("https://go.microsoft.com/fwlink/?LinkId=246509&cid={0}", certificateId); // Make an HTTP GET request for the certificate HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(certificateUrl); request.Method = "GET"; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); // Retrieve the certificate out of the response stream byte[] responseBuffer = new byte[MaxCertificateSize]; Stream resStream = response.GetResponseStream(); int bytesRead = ReadResponseBytes(responseBuffer, resStream); if (bytesRead < 1) { //TODO: Handle error here } return new X509Certificate2(responseBuffer); } 

您可以在此处查看更多此代码示例。 该示例中包含“IapReceiptProduction.cer”,只是为了显示收据validation的工作原理,而无需通过代码下载证书。 获得证书后,您可以使用System.Security.Cryptography.Xml.SignedXml API来validation收据,如您链接的代码示例中所示。