获取以前购买的项目的签名在应用程序结算中

时间:2016-09-11 12:37:32

标签: c# android xamarin in-app-billing

我正在使用Xamarin Android和Xamarin.InAppBilling组件在我的应用中集成In App Billing功能。 在为用户提供数字内容之前,我会进行服务器端签名验证,以确保订单合法。获得签名的唯一方法是在OnProductPurchased事件中购买之后立即:

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

官方Google documentation表示可以获得这样拥有物品的签名:

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

问题是Xamarin组件中的GetPurchases方法返回IList<Purchase>而不是Bundle。这意味着如果由于某种原因我的应用程序在购买后无法立即连接到我的服务器,将来无法验证签名,合法(付费)用户将无法访问他们付费的内容对

那么有没有办法使用Xamarin.InAppBilling组件获取自有(以前购买过的)商品的签名?

1 个答案:

答案 0 :(得分:1)

该回复Bundle将返回产品ID列表,每次购买的订单明细以及每次购买的签名。

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

因此,您应该能够使用以下方法返回购买:

public IList<Purchase> GetPurchases(string itemType)

然后,您将在反编译代码中看到它正在解析捆绑包中的3个项目,如上所述:

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");

但实际方法会返回IList<Purchase>,并将其反序列化为Purchase对象。

作为一个小旁注,可以创建一个小扩展库,它将像INAPP_DATA_SIGNATURE_LIST一样解析上面的包,并扩展Purchase对象以包含您需要的任何进一步信息。