3

所以事情就是这样——我有一个用于我的 Android 应用程序的 node.js 后端服务器。我正在使用 Google Play 计费库,并按照 google Docs 的建议使用后端验证购买。

现在,关于这个错误的所有其他答案似乎都指的是一个一致的问题。

我的后端有时会进行验证,有时会将此作为错误返回,这表明实际上我的服务帐户已链接(如我的控制台中所示)。

我尝试了两个不同的 3rd 方库,但我遇到了同样的问题。有时一个会回复验证成功,而另一个会说我的帐户未关联。有时它们都是消极的,有时它们都是积极的。

似乎不一致。

var platform = 'google';
        var payment = {
            receipt: purchaseToken, // always required  ... this is google play purchaseToken
            productId: subID,  // my subscription sku id
            packageName: 'com.xxxxxx', // my package name
            keyObject: key,  // my JSON file
            subscription: true, // optional, if google play subscription

        };



   var promise2 = iap.verifyPayment(platform, payment, function (error, response) {
        /* your code */
        if (error) {
            console.log('error with iap, ' , error);
            return true;
        } else {
            console.log('success with iap, response is: ', response);
            return true;
        }
    });

我还尝试了不同的库,得到了相同的结果:

var receipt = {
            packageName: "com.xxxx",
            productId: subID,  // sku subscription id
            purchaseToken: purchaseToken // my purchase token
            };

            var promise = verifier.verifySub(receipt, function cb(err, response) {
                if (err) {
                    console.log('within err, was there a response? : ', response); 
                console.log('there was an error validating the subscription: ', err);
                //console.log(err);
                return true;
                } else {
                console.log('sucessfully validated the subscription');
                // More Subscription info available in “response”
                console.log('response is: ', response    );
                return true;
                }
               });


// return promises later.

还有其他人遇到这个问题吗?

4

1 回答 1

12

TLDR;创建一个新的产品 ID。

我终于找到了答案。问题不在于我的代码,也不在于 Google Developer Console 或 Google Play Console 中的权限。除了一件事,一切都设置正确。

以前,在 Google Play Console 中设置测试许可证帐户之前,我在我的 productID“X”上用真钱进行了实际的订阅购买。

然后,在添加购买订阅的同一个谷歌帐户作为测试用户后,我继续在同一个订阅产品ID“X”上测试结果。

即使我取消了真正的购买,实际的到期日期也不是一个月。

因此,我相信有时 Google 在我购买/取消购买时会感到困惑——将测试订阅与实际订阅混淆。

创建一个新的产品 ID,并且只使用它,解决了我的问题,并且购买得到了一致的验证。

于 2018-09-12T18:40:50.563 回答