web-dev-qa-db-ja.com

Androidアプリ内課金v3 API)の開発者ペイロードは何ですか?

アプリにアプリ内課金を実装して、プレミアム機能のロックを解除しています。アプリ内課金は正しく設定されています。 「開発者のペイロード」以外はすべて問題ないようです。

サンプルアプリは言う

 /*
     * TODO: verify that the developer payload of the purchase is correct. It will be
     * the same one that you sent when initiating the purchase.
     *
     * WARNING: Locally generating a random string when starting a purchase and
     * verifying it here might seem like a good approach, but this will fail in the
     * case where the user purchases an item on one device and then uses your app on
     * a different device, because on the other device you will not have access to the
     * random string you originally generated.
     *
     * So a good developer payload has these characteristics:
     *
     * 1. If two different users purchase an item, the payload is different between them,
     *    so that one user's purchase can't be replayed to another user.
     *
     * 2. The payload must be such that you can verify it even when the app wasn't the
     *    one who initiated the purchase flow (so that items purchased by the user on
     *    one device work on other devices owned by the user).
     *
     * Using your own server to store and verify developer payloads across app
     * installations is recommended.
     */

サンプルアプリは、開発者のペイロードとして空の文字列を使用します。私の質問は、開発者のペイロードとして使用する文字列ですか?ユーザーのメインのメールIDを使用できますか?

22
Amit Jayant

以下の回答を確認してください。問題が解決する可能性があります。

消費アイテム(管理アイテム)を使用している場合は、ランダムに生成された文字列を使用できます

ステップ1:createメソッドの前にこれを宣言します。

         private static final char[] symbols = new char[36];

                static {
                    for (int idx = 0; idx < 10; ++idx)
                        symbols[idx] = (char) ('0' + idx);
                    for (int idx = 10; idx < 36; ++idx)
                        symbols[idx] = (char) ('a' + idx - 10);
                }

ステップ2:アクティビティにRandomStringとSessionIdentifierGeneratorクラスを設定する

          public class RandomString {

        /*
         * static { for (int idx = 0; idx < 10; ++idx) symbols[idx] = (char)
         * ('0' + idx); for (int idx = 10; idx < 36; ++idx) symbols[idx] =
         * (char) ('a' + idx - 10); }
         */

        private final Random random = new Random();

        private final char[] buf;

        public RandomString(int length) {
            if (length < 1)
                throw new IllegalArgumentException("length < 1: " + length);
            buf = new char[length];
        }

        public String nextString() {
            for (int idx = 0; idx < buf.length; ++idx)
                buf[idx] = symbols[random.nextInt(symbols.length)];
            return new String(buf);
        }

    }

    public final class SessionIdentifierGenerator {

        private SecureRandom random = new SecureRandom();

        public String nextSessionId() {
            return new BigInteger(130, random).toString(32);
        }

    }

ステップ3:ペイロードをpuchaseリクエストに渡す:

RandomString randomString = new RandomString(36);
            System.out.println("RandomString>>>>" + randomString.nextString());
            /* String payload = ""; */
            // bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ
            String payload = randomString.nextString();
            Log.e("Random generated Payload", ">>>>>" + payload);

        Log.d(TAG, "Launching purchase flow for infinite gas subscription.");
            mHelper.launchPurchaseFlow(this, SKU_GAS,
                    IabHelper.ITEM_TYPE_INAPP, RC_REQUEST,
                    mPurchaseFinishedListener, payload);

詳細については、このリンクを確認してください: ユーザーを識別するトークン

それがあなたの問題を解決することを願っています。

1
Maulik

私にとってランダム文字列は最初は役に立たないので、購入したデバイスではなく、購入したユーザーに依存する必要があります。第二に、それは非消耗品なので、空の文字列が適しているかもしれませんが、理想的ではありません。

したがって、私の回避策は、キーに基づいて暗号化されたハッシュを作成することです。購入が行われるたびに、ハッシュが同じであってはならないため、一意に識別できます(これはbcryptなどのハッシュ方式に依存します)。

キーはすべてのデバイスで同じであるため、秘密のメッセージが正しいことを復号化して確認するのは簡単です。

キーを秘密にしておくために、さまざまな文字列操作関数を使用してそれをマスクし、目に見える方法で保存されないようにしました。

テキスト操作の例はここにあります: Androidアプリ内課金:アプリケーションの公開鍵の保護

String Base64EncodedPublicKey key = DecrementEachletter("Bl4kgle") + GetMiddleBit() + ReverseString("D349824");

キーに基づいてハッシュを作成するこの方法では、ペイロードを一意かつ識別可能にすると同時に、適度に安全にすることができます。防弾ではありませんが、クラックが発生しにくくなります。

2
Kc Gibson