朋友可以用不同的插件解决这个问题:
插入:
Cordova plugin add cordova-plugin-inapppurchase
清单.json
{ "play_store_key": "YOUR PLAY STORE KEY" }
LoadProducts 函数
var productIds=['com.company.app.product1','com.company.app.product2'];
inAppPurchase
.getProducts(productIds)
.then(function (products) {
//products ok
})
.catch(function (err) {
console.log(err);
});
购买功能
var productId='com.company.app.product1';
inAppPurchase
.buy(productId)
.then(function (data) {
console.log(JSON.stringify(data));
// The consume() function should only be called after purchasing consumable products
// otherwise, you should skip this step
return inAppPurchase.consume(data.type, data.receipt, data.signature);
})
.then(function () {
console.log('consume done!');
//purchase ok
})
.catch(function (err) {
console.log(err);
});