3

私はWindows Phone 8アプリに取り組んでいます。私のアプリにはアプリ内購入が含まれます。領収書の概念を理解しようとしています。私の理解では、誰かが私のアプリ内で商品を購入した後、レシートが生成されます。

<?xml version="1.0"?>
<Receipt Version="1.0" CertificateId="{Identifier1}" xmlns="http://schemas.microsoft.com/windows/2012/store/receipt">
  <ProductReceipt PurchasePrice="${PurchaseAmount}" PurchaseDate="{DateTime}" Id="{Guid1}" AppId="{Guid2}" ProductId="{ProductName}" ProductType="Consumable" PublisherUserId="{Identifier2}" PublisherDeviceId="{Identifier3}" MicrosoftProductId="{Guid3}" />
  <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
    <SignedInfo>
      <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
      <SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" />
      <Reference URI="">
        <Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /></Transforms>
    <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
    <DigestValue>{Identifier4}</DigestValue>
      </Reference>
    </SignedInfo>

    <SignatureValue>{HashedValue}</SignatureValue>
  </Signature>
</Receipt>

すごい!ただし、このレシートが Microsoft のサーバーからのものかどうかはわかりません。誰かがそれを確認する方法を私に説明できますか? 私はこれを見ました: http://code.msdn.microsoft.com/wpapps/In-app-purchase-receipt-c3e0bce4しかし、それは私には意味がありません。例の証明書がわかりません。「IapReceiptProduction.cer」は決まったものですか?それともこのサンプルだけですか?

これがばかげた質問であれば申し訳ありません。

4

1 に答える 1

6

'Receipt' XML 要素の 'CertificateId' 属性は、Windows ストアの領収書の署名に使用された証明書を決定します。CertificateID (サンプルでは「{Identifier1}」) を取得したら、以下のコード サンプルで「certificateUrl」として指定されている URL から必要な証明書をダウンロードできます。プログラムで証明書をダウンロードする方法は次のとおりです。

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」は、コードを介して証明書をダウンロードすることなく、レシート検証がどのように機能するかを示すために、そのサンプルに含まれています。証明書を取得したら、System.Security.Cryptography.Xml.SignedXml API を使用して、リンクしたコード サンプルで示されているように、レシートを確認できます。

于 2013-05-08T14:10:46.967 に答える