// 安卓业务插件桥接,保持与设备初始化页相同的插件入口。
|
let HardwarePlugin = null;
|
if (typeof uni !== 'undefined' && typeof uni.requireNativePlugin === 'function') {
|
HardwarePlugin = uni.requireNativePlugin('business-module');
|
}
|
const getPluginMethod = (methodNames = []) => {
|
if (!HardwarePlugin) {
|
return null;
|
}
|
|
return methodNames.find((methodName) => typeof HardwarePlugin[methodName] === 'function') || null;
|
};
|
|
export const HardwareAPI = {
|
openWebPay(options = {}, callback) {
|
return new Promise((resolve, reject) => {
|
// #ifdef APP-PLUS
|
console.log('[HardwareAPI] openWebPay 准备调用, options:', JSON.stringify(options));
|
console.log('[HardwareAPI] business-module:', HardwarePlugin);
|
const methodName = getPluginMethod(['openWebPay']);
|
if (!methodName) {
|
console.error('[HardwareAPI] openWebPay 方法不存在');
|
reject(new Error('当前插件未提供网页支付能力'));
|
return;
|
}
|
console.log('[HardwareAPI] openWebPay 实际调用方法:', methodName);
|
try {
|
HardwarePlugin[methodName](options, (result) => {
|
console.log('[HardwareAPI] openWebPay 原生回调:', result);
|
if (typeof callback === 'function') {
|
callback(result);
|
}
|
resolve(result);
|
});
|
} catch (error) {
|
console.error('[HardwareAPI] openWebPay 调用异常:', error);
|
reject(error);
|
}
|
// #endif
|
// #ifndef APP-PLUS
|
reject(new Error('当前平台不支持网页支付'));
|
// #endif
|
});
|
},
|
};
|