简体   繁体   中英

Get signature of previously purchased item In App Billing

I'm using Xamarin Android and Xamarin.InAppBilling component to integrate In App Billing functionality in my app. Before providing users with digital content I do server-side signature verification to make sure order is legit. And the only way to get signature is immediately after the purchase in OnProductPurchased event like this:

_serviceConnection.BillingHandler
.OnProductPurchased += (int response, Purchase purchase, string purchaseData, string purchaseSignature) => 
                {
                    // Use purchaseSignature here!
                };

Official Google documentation says that it is possible to get signatures of owned items like this:

Bundle ownedItems = mService.getPurchases(3, getPackageName(), "inapp", null);
ArrayList<String> signatureList =
    ownedItems.getStringArrayList("INAPP_DATA_SIGNATURE_LIST");

The problem is that GetPurchases method in Xamarin component returns IList<Purchase> and not Bundle . That means that if for some reason my app will fail to connect to my server immediately after purchase, there will be no way to verify signature in the future and legit (paid) user won't be able to access content that they paid for.

So is there any way to get signatures of owned (previously purchased) items using Xamarin.InAppBilling component?

That response Bundle will return a list of Product IDs, Order Details for each Purchase, and Signatures of Each Purchase.

https://developer.android.com/google/play/billing/billing_reference.html#getPurchases

Thus you should be able to use the following method to return purchases:

public IList<Purchase> GetPurchases(string itemType)

You will then see inside the decompiled code that it parses the 3 items from the bundle as mentioned above:

IList<string> stringArrayList1;
IList<string> stringArrayList2;
IList<string> stringArrayList3;

stringArrayList1 = bundle.GetStringArrayList("INAPP_PURCHASE_ITEM_LIST");
stringArrayList2 = bundle.GetStringArrayList("INAPP_PURCHASE_DATA_LIST");
stringArrayList3 = bundle.GetStringArrayList("INAPP_DATA_SIGNATURE_LIST");

However the actual method returns a IList<Purchase> which is Deserialized into a Purchase object.

As a small side note, it may be possible to make a small extension library that will parse the bundle like above for the INAPP_DATA_SIGNATURE_LIST and extend the Purchase object to include any further information you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM