2

我想检查 android inapp billing 是否已购买。我找到了这个方法...

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

但是我不知道我应该放入签名数据和签名中吗?试过 itemid 和 base64EncodedPublicKey,不起作用...

谢谢!

4

1 回答 1

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)
    {
            //...
    }
于 2012-11-24T20:24:08.477 回答