BillingSecurity.verifyPurchase - 签名数据和签名是什么?

时间:2012-11-24 18:42:33

标签: android

我想检查android inapp计费是否已经进行了购买。我找到了这种方法......

protected static void verifyPurchase(String signedData, String signature) {
    ArrayList<VerifiedPurchase> purchases = BillingSecurity.verifyPurchase(signedData, signature);
    Log.e("IN APP","purchases: " + purchases.toString());
}

然而我无法弄清楚我应该加入signedData和签名吗?尝试过itemid和base64EncodedPublicKey,不起作用......

谢谢!

1 个答案:

答案 0 :(得分:1)

要检查购买结果,您应使用其他类 BillingPurchaseObserver 的方法:

@Override
public void onRequestPurchaseResponse(RequestPurchase request,
        ResponseCode responseCode)
{
    Log.d("TAG", "onRequestPurchaseResponse");
    if (Consts.DEBUG)
    {
        Log.d("TAG", request.mProductId + ": " + responseCode);
    }
    if (responseCode == ResponseCode.RESULT_OK)
    {
        if (Consts.DEBUG)
        {
            Log.i("TAG", "purchase was successfully sent to server");
        }
    }
    else if (responseCode == ResponseCode.RESULT_USER_CANCELED)
    {
        if (Consts.DEBUG)
        {
            Log.i("TAG", "user canceled purchase");
        }
    }
    else
    {
        if (Consts.DEBUG)
        {
            Log.i("TAG", "purchase failed");
        }
    }
}

BillingService中的purchaseStateChanged方法你不应该修改。

/**
     * Verifies that the data was signed with the given signature, and calls
     * {@link ResponseHandler#purchaseResponse(Context, PurchaseState, String, String, long)}
     * for each verified purchase.
     * 
     * @param startId
     *           an identifier for the invocation instance of this service
     * @param signedData
     *           the signed JSON string (signed, not encrypted)
     * @param signature
     *           the signature for the data, signed with the private key
     */
    private void purchaseStateChanged(int startId, String signedData,
            String signature)
    {
            //...
    }