(uniapp)海科标准智能SDK使用说明

接入须知

此 SDK 为 uniapp 的 Android 原生语言插件。适用于 uniapp 项目,不适用 uniappx 项目。

接入准备

离线打包接入方式

  1. 将相关 .so.aar 文件放入 Android 离线打包工程项目的 lib 目录下(相关资源见附件)
  2. 复制 dcloud_uniplugins.json 文件到以下目录:在 Android 离线打包工程项目主 module 下的 app/src/main/assets(相关资源见附件)

云打包接入方式

nativeplugins 文件夹直接放入 uniapp 项目根目录下(相关资源见附件)

调用示例

初始化插件实例(全局)

`javascript
var bankcardpay = uni.requireNativePlugin(“Hkrt-bankCardPay”);

在onLoad 中注册回调监听

`javascript
onLoad() {
plus.globalEvent.addEventListener(‘onError’, e => {
console.log(‘onError’ + JSON.stringify(e));
});
plus.globalEvent.addEventListener(‘onInitSuccess’, e => {
console.log(“onInitSuccess”, “收到”);
console.log(‘onInitSuccess’ + JSON.stringify(e));
});
plus.globalEvent.addEventListener(‘onSignInSuccess’, e => {
console.log(“onSignInSuccess”, “收到”);
console.log(‘onSignInSuccess’ + JSON.stringify(e));
// SDK 初始化并签到成功,可以发起交易
});
plus.globalEvent.addEventListener(‘onGetMerchantInfo’, e => {
console.log(‘onGetMerchantInfo’ + JSON.stringify(e));
});
plus.globalEvent.addEventListener(‘onConsumeSuccess’, e => {
console.log(‘onConsumeSuccess’ + JSON.stringify(e));
this.revokeParam.tradeId = e.detail.trade_no;
this.refundParam.tradeId = e.detail.trade_no;
});
plus.globalEvent.addEventListener(‘onRefundSuccess’, e => {
console.log(‘onRefundSuccess’ + JSON.stringify(e));
});
plus.globalEvent.addEventListener(‘onRevokeSuccess’, e => {
console.log(‘onRevokeSuccess’ + JSON.stringify(e));
});
plus.globalEvent.addEventListener(‘onPreLicensingSuccess’, e => {
console.log(‘onPreLicensingSuccess’ + JSON.stringify(e));
this.preAuthFinishParam.tradeId = e.detail.trade_no;
this.preAuthRevokeParam.tradeId = e.detail.trade_no;
});
plus.globalEvent.addEventListener(‘onPreLicensingRevokeSuccess’, e => {
console.log(‘onPreLicensingRevokeSuccess’ + JSON.stringify(e));
});
plus.globalEvent.addEventListener(‘onPreLicensingDoneSuccess’, e => {
console.log(‘onPreLicensingDoneSuccess’ + JSON.stringify(e));
this.preAuthFinishRevokeParam.tradeId = e.detail.trade_no;
});
plus.globalEvent.addEventListener(‘onPreLicensingDoneRevokeSuccess’, e => {
console.log(‘onPreLicensingDoneRevokeSuccess’ + JSON.stringify(e));
});
plus.globalEvent.addEventListener(‘onGetCardPayDetail’, e => {
console.log(‘onGetCardPayDetail’ + JSON.stringify(e));
});
plus.globalEvent.addEventListener(‘onTicketUploadSuccess’, e => {
console.log(‘onTicketUploadSuccess’ + JSON.stringify(e));
});
plus.globalEvent.addEventListener(‘onGetSecretText’, e => {
console.log(‘onGetSecretText’ + JSON.stringify(e));
});
plus.globalEvent.addEventListener(‘onTicketPrintSuccess’, e => {
console.log(‘onTicketPrintSuccess’ + JSON.stringify(e));
});
plus.globalEvent.addEventListener(‘onPrintSuccess’, e => {
console.log(‘onPrintSuccess’ + JSON.stringify(e));
});
}

在 methods 中调用插件中的接口方法

`javascript
methods: {
initSdk() {
console.log(“initSdk”);
try {
// 第一参数为初始化的设备类型 联通(LANDI)新大陆n910(NEWLAND) 商米(SUMMI)
bankcardpay.initPaySdk(‘NEWLAND’, (result) => {
if (result === ‘Success’) {
uni.showToast({
title: “sdk初始化成功”,
icon: ‘none’
});
this.isInitSuccess = true;
}
});
} catch (e) {
console.log(“catch”);
uni.showToast({
title: ‘调用失败: ‘ + e.message,
icon: ‘none’
});
}
},
getMerchantInfo() {
console.log(“getMerchantInfo”);
if (!this.isInitSuccess) {
uni.showToast({
title: “请先初始化sdk”,
icon: ‘none’
});
return;
}
try {
bankcardpay.getMerchantInfo((result) => {
console.log(“result”, result);
uni.showToast({
title: result.shop_name,
icon: ‘none’
});
});
} catch (e) {
console.log(“catch”);
uni.showToast({
title: ‘调用失败: ‘ + e.message,
icon: ‘none’
});
}
},
consume() {
console.log(“consume”);
if (!this.isInitSuccess) {
uni.showToast({
title: “请先初始化sdk”,
icon: ‘none’
});
return;
}
try {
this.consumeParam.outTradeNo = Date.now().toString() + “OUTTEST”;
bankcardpay.toConsume(this.consumeParam, (result) => {
console.log(result);
uni.showToast({
title: result,
icon: ‘none’
});
});
} catch (e) {
console.log(“catch”);
uni.showToast({
title: ‘调用失败: ‘ + e.message,
icon: ‘none’
});
}
},
revoke() {
console.log(“revoke”);
if (!this.isInitSuccess) {
uni.showToast({
title: “请先初始化sdk”,
icon: ‘none’
});
return;
}
try {
this.revokeParam.outTradeNo = Date.now().toString() + “OUTTESTRevoke”;
bankcardpay.toRevoke(this.revokeParam, (result) => {
console.log(result);
uni.showToast({
title: result,
icon: ‘none’
});
});
} catch (e) {
console.log(“catch”);
uni.showToast({
title: ‘调用失败: ‘ + e.message,
icon: ‘none’
});
}
},
refund() {
console.log(“refund”);
if (!this.isInitSuccess) {
uni.showToast({
title: “请先初始化sdk”,
icon: ‘none’
});
return;
}
try {
this.refundParam.outTradeNo = Date.now().toString() + “OUTTESTRefund”;
bankcardpay.toRefund(this.refundParam, (result) => {
console.log(result);
uni.showToast({
title: result,
icon: ‘none’
});
});
} catch (e) {
console.log(“catch”);
uni.showToast({
title: ‘调用失败: ‘ + e.message,
icon: ‘none’
});
}
},
preAuth() {
console.log(“preAuth”);
if (!this.isInitSuccess) {
uni.showToast({
title: “请先初始化sdk”,
icon: ‘none’
});
return;
}
try {
this.preAuthParam.outTradeNo = Date.now().toString() + “OUTTESTauth”;
bankcardpay.toPreLicensing(this.preAuthParam, (result) => {
console.log(result);
uni.showToast({
title: result,
icon: ‘none’
});
});
} catch (e) {
console.log(“catch”);
uni.showToast({
title: ‘调用失败: ‘ + e.message,
icon: ‘none’
});
}
},
preAuthFinish() {
console.log(“preAuthFinish”);
if (!this.isInitSuccess) {
uni.showToast({
title: “请先初始化sdk”,
icon: ‘none’
});
return;
}
try {
this.preAuthFinishParam.outTradeNo = Date.now().toString() + “OUTTESTpreauthFinish”;
bankcardpay.toPreLicensingDone(this.preAuthFinishParam, (result) => {
console.log(result);
uni.showToast({
title: result,
icon: ‘none’
});
});
} catch (e) {
console.log(“catch”);
uni.showToast({
title: ‘调用失败: ‘ + e.message,
icon: ‘none’
});
}
},
preAuthRevoke() {
console.log(“preAuthRevoke”);
if (!this.isInitSuccess) {
uni.showToast({
title: “请先初始化sdk”,
icon: ‘none’
});
return;
}
try {
this.preAuthRevokeParam.outTradeNo = Date.now().toString() + “OUTTESTpreauthRevoke”;
bankcardpay.toPreLicensingRevoke(this.preAuthRevokeParam, (result) => {
console.log(result);
uni.showToast({
title: result,
icon: ‘none’
});
});
} catch (e) {
console.log(“catch”);
uni.showToast({
title: ‘调用失败: ‘ + e.message,
icon: ‘none’
});
}
},
preAuthFinishRevoke() {
console.log(“preAuthFinishRevoke”);
if (!this.isInitSuccess) {
uni.showToast({
title: “请先初始化sdk”,
icon: ‘none’
});
return;
}
try {
this.preAuthFinishRevokeParam.outTradeNo = Date.now().toString() + “OUTTESTpreauthFinishRevoke”;
bankcardpay.toPreLicensingDoneRevoke(this.preAuthFinishRevokeParam, (result) => {
console.log(result);
uni.showToast({
title: result,
icon: ‘none’
});
});
} catch (e) {
console.log(“catch”);
uni.showToast({
title: ‘调用失败: ‘ + e.message,
icon: ‘none’
});
}
}
}

附件1 :插件调用demo:

附件2:离线打包资源:

附件3:云打包资源:

文档更新时间: 2025-09-30 11:02   作者:admin