更新记录
0.0.2(2024-07-31)
更新使用说明
平台兼容性
Android | Android CPU类型 | iOS |
---|---|---|
适用版本区间:5.0 - 14.0 | armeabi-v7a:支持,arm64-v8a:支持,x86:未测试 | × |
原生插件通用使用流程:
- 购买插件,选择该插件绑定的项目。
- 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
- 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
- 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
- 开发完毕后正式云打包
付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios
注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择
Usage
const billingclient = uni.requireNativePlugin('Deskbtm-AndroidBillingClient');
const PurchaseState = {
UNSPECIFIED_STATE: 0,
PURCHASED: 1,
PENDING: 2,
}
const ProductType = {
INAPP: "inapp",
SUBS: "subs",
}
const BillingResponseCode = {
SERVICE_TIMEOUT: 3,
FEATURE_NOT_SUPPORTED: 2,
SERVICE_DISCONNECTED: 1,
OK: 0,
USER_CANCELED: 1,
SERVICE_UNAVAILABLE: 2,
BILLING_UNAVAILABLE: 3,
ITEM_UNAVAILABLE: 4,
DEVELOPER_ERROR: 5,
ERROR: 6,
ITEM_ALREADY_OWNED: 7,
ITEM_NOT_OWNED: 8,
NETWORK_ERROR: 12,
}
const ConnectionState = {
DISCONNECTED: 0,
CONNECTING: 1,
CONNECTED: 2,
CLOSED: 3,
}
export default {
onUnload() {
billingclient.endConnection();
},
onLoad() {
billingclient.initialize({
enableOneTimeProducts: true
});
this.startConnection((res) => {
console.log(res);
}, () => {
});
var globalEvent = uni.requireNativePlugin('globalEvent');
globalEvent.addEventListener('purchasesUpdated', function (res) {
console.log(res);
if (res.responseCode === BillingResponseCode.OK) {
for (const detail of res.purchases) {
if(detail.purchaseState === PurchaseState.PURCHASED){
//这个表达式逻辑要自己实现 billingclient 购买结果中没有提供ProductType
if(detail.products.some(p=>/sub/g.test(p))){
// 用于非消耗品订阅
billingclient.acknowledgePurchase({ purchaseToken: detail.purchaseToken }, (e) => {
console.log(e);
});
}else {
// 用于消耗品
billingclient.consumeAsync({ purchaseToken: detail.purchaseToken }, (e) => {
console.log(e);
});
}
}
}
}
});
},
methods: {
startConnection(setupCallback, disconnectCallback) {
billingclient.startConnection(setupCallback,
() => {
if (!billingclient.isReady()) {
this.startConnection(setupCallback, disconnectCallback);
}
});
},
googleSub(){
if (!billingclient.isReady()) {
return;
}
billingclient.queryProductDetailsAsync([
{
productId: 'test_sub1',
productType: ProductType.SUBS
},
],
(res) => {
billingclient.launchBillingFlow([{ productDetail: res.productDetails[0] }], (res) => {
console.log(res);
})
});
},
googleInapp() {
if (!billingclient.isReady()) {
return;
}
billingclient.queryProductDetailsAsync([
{
productId: 'test_demo3',
productType: ProductType.INAPP
},
],
(res) => {
console.log(res);
billingclient.launchBillingFlow([{ productDetail: res.productDetails[0] }], (res) => {
console.log(res);
})
});
},
}
}