请告诉我使用Cordova插件实现应用程序内购买的方式。如何使用Cordova插件实现应用程序内购买?
我正在开发使用Cordova的Android应用程序。 有一些应用内购买插件,但我决定使用Cordova Purchase Plugin。
我沿着README.md In-App Purchase for PhoneGap/Cordova iOS and Android做了一些设置。 因此,我可以使用Demo of the Purchase Plugin for Cordova来调用插件,只需稍作修改即可。 (参见下,它的代码的一部分。)
app.initStore = function() {
if (!window.store) {
log('Store not available');
return;
}
// Enable maximum logging level
store.verbosity = store.DEBUG;
// Enable remote receipt validation
// store.validator = "https://api.fovea.cc:1982/check-purchase";
// Inform the store of your products
log('registerProducts');
store.register({
id: 'myProductA',
alias: 'myProductA',
type: store.CONSUMABLE
});
// When any product gets updated, refresh the HTML.
store.when("product").updated(function (p) {
console.info("app.renderIAP is called");
app.renderIAP(p);
});
// Log all errors
store.error(function(error) {
log('ERROR ' + error.code + ': ' + error.message);
});
// When purchase of an extra life is approved,
// deliver it... by displaying logs in the console.
store.when("myProductA").approved(function (order) {
log("You got a ProductA");
order.finish();
});
// When the store is ready (i.e. all products are loaded and in their "final"
// state), we hide the "loading" indicator.
//
// Note that the "ready" function will be called immediately if the store
// is already ready.
store.ready(function() {
var el = document.getElementById("loading-indicator");
console.info(el + "ready is called")
if (el)
el.style.display = 'none';
});
// When store is ready, activate the "refresh" button;
store.ready(function() {
var el = document.getElementById('refresh-button');
console.info(el + "ready is called and refresh-button show?");
if (el) {
el.style.display = 'block';
el.onclick = function(ev) {
store.refresh();
};
}
});
// Refresh the store.
//
// This will contact the server to check all registered products
// validity and ownership status.
//
// It's fine to do this only at application startup, as it could be
// pretty expensive.
log('refresh');
store.refresh();
};
它并没有表现出“商店不提供”所显示的插件时不可用,显示“registerProducts”和“刷新”。 (*当然我在Google Play开发者控制台中添加'myProductA'到应用内商品。)
但是我注意到下面的函数没有被调用。
store.when("product").updated(function (p)
而且我也不明白参数应填入什么,所以我注释了下面。 (*我做了删除注释出来,但它仍然没有工作。)
store.validator = "https://api.fovea.cc:1982/check-purchase";
我想这些事情使一些错误。 我不知道什么是我的堆栈,所以我的问题并不清楚。 我想要一些线索来解决它......或者我不应该使用Cordova插件实施应用内购买?
请给我你的手。
(我的英语不流利,所以我对任何混乱很抱歉。)
有一些关于验证器函数的文档[这里](https://github.com/j3k0/cordova-plugin-purchase/blob/master/doc/api.md#validator)。目前,科尔多瓦插件的作者似乎提供了一种免费的方式来验证购买的商品,但我们仍不清楚他的服务是否真的有效(根据他的网站的私人测试版的资料)以及此服务访问哪种信息至。 – antogerva 2015-02-19 20:00:54
@antogerva感谢您的评论。我忽略了你提到的链接。它看起来很有帮助,谢谢。无论如何,最后我放弃了使用这个插件,并且在cordova框架中实现了“在app购买”功能。这对我来说太难了.haha – tkhm 2015-02-20 07:22:53
你好每一个人请帮助我。有我的问题请http://stackoverflow.com/questions/38657305/android-in-app-purchase-not-working – 2016-08-01 09:23:33