13

Android アプリケーションを開発していますが、アプリケーションの一部の機能を無料で提供したくありません。

アプリ内課金バージョン 3 API を使用することを考えたので、開発者コンソールで「アプリ内製品」を定義しました。

ドキュメントを読んだ後、購入フローを開始するときに、アプリケーションが購入したユーザーを一意に識別するのに役立つ文字列トークンを渡す必要があることがわかりました。

しかし、ユーザーを識別する文字列トークンを取得するにはどうすればよいでしょうか?

ありがとう

4

2 に答える 2

19

開発者ペイロードを使用して、ユーザーを識別し、セキュリティを確保できます。

アプリの請求要件でアプリケーションに従って開発者ペイロードを生成する方法は 2 つあります。

1)管理されていないアイテム(消耗品ではない)を使用している場合は、特定のアプリでユーザーを一意に識別するUserIDを使用できます。開発者ペイロードを UserID として送信できます。

また

ユーザーの電子メール ID がサーバーに保存されている場合は、一意の ID の開発者ペイロードに電子メール アドレスを入れることができます。ユーザーが製品の支払いを行った後に Google Play から応答を取得し、そのユーザー アカウントのサーバー データベースからそれをフェッチすると、開発者のペイロードと一致します。

ローカル データベース (SQLite など):

     UserID
     (Automatecally  
       generated by   product type     userEmailAddress
      Sql database)        


        1            product1            abc@gmail.com
        2            product1            xyz@gmail.com
        3            product1            pqr@gmail.com

ペイロードでユーザーIDとして渡すことができます

--> しばらくすると問題が発生します。サーバーデータベースを使用したくない場合は、開発ペイロードを単に無視して空白文字列にすることができます。コードには影響しません。ニコライエレンコフの回答のこのリンクを確認してください:stackoverflow.com/questions/14553515 /

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

step 1: before on create method declare this:

            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: ペイロードを購入リクエストに渡します。

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

    for more inforamation check this link:
    http://stackoverflow.com/questions/41107/how-to-generate-a-random-alpha-numeric-string

これに注意してください:

セキュリティに関する推奨事項: Google Play から購入応答を受け取ったら、返されたデータの署名、orderId、および Purchase オブジェクトの developerPayload 文字列を確認して、予期した値を取得していることを確認してください。orderId が以前に処理したことのない一意の値であること、および developerPayload 文字列が以前に購入要求で送信したトークンと一致していることを確認する必要があります。セキュリティ上のさらなる予防策として、独自の安全なサーバーで検証を実行する必要があります。

   check this link:
   http://developer.android.com/google/play/billing/billing_integrate.html
for more details check this link:

http://developer.android.com/google/play/billing/billing_best_practices.html

それがあなたを助けることを願っています。

于 2013-06-20T05:34:06.643 に答える
-1

ユーザーごとに UUID を作成しないのはなぜですか?

String uniqueID = UUID.randomUUID().toString();
于 2013-06-19T17:26:25.780 に答える