1.Overview
Third-party program plug-in to provide Bluetooth lock door service, users in accordance with the requirements of ginseng, to achieve Bluetooth unlock第三方Mini ProgramPlugin提供自定义PasswordFunction,使用者按照Requirements传参,实现BLEAdd,Edit,RemovePassword。
2.Parameter Description
Small program developers call plug-in for Bluetooth lock door, use the method see the program official API
widget Guide
QR KeyMini Programapp-id:wxbe18a842c8d14445
3.Parameter Description
Required parameters |
Explanation |
accountSid |
The Account SID for the Lock Cabinet Developer Account |
token |
The Auth Token for the Lock Cabinet Developer Account |
mobile |
Mobile |
communityNo |
QR Master community |
cardNo |
Please refer to Generate cards |
areaCode |
Mobile phone area code |
4.Sample
4.1 Add plug-ins in the background of small program management
Small program developers can find the required plug-ins based on the AppID and request to use them in ‘Small Program Management Back-Settings-Third-Party Service-Plug-in Management’.
After the plug-in developer passes within 24 hours, the small program developer can use the plug-in within the small program
4.2 To use a plug-in in a small program code that must declare the plug-in you need in app.json's plugins, please refer to the following code:
<!--app.json-->
{
"plugins": {
"yaoshibang": {
"version": "1.0.4",
"provider": "wxbe18a842c8d14445"
}
}
}
4.3 Use the plug-in in the wxml file on the target page, or customize the component style (so you don't have to copy the code in wxss)
<!--index.wxml-->
<button bindtap="openapi" class="yaoshibang">调用api</button>
<!--index.wxss-->
.yaoshibang{
width:80%;
border-radius: 15rpx;
margin-top: 100rpx;
background-color: #1B82D2;
color:#fff;
font-size: 40rpx;
height: 100rpx;
line-height: 100rpx;
}
4.4 In the js of the target page, the plug-in can be obtained using the plug-in interface, the full call api example is as follows:
<!--index.js-->
<!--Add the first of the js file of the called component-->
let yaoshibang = requirePlugin("yaoshibang");
<!--Add this segment to the onShow function of the js file of the called component to turn off The Code for Bluetooth-->
wx.closeBLEConnection({
deviceId: [],
complete(res) {
wx.closeBluetoothAdapter({
success(res) {
console.log('Disconnect Bluetooth');
}
});
}
});
<!--The following paragraph can be placed in any of the custom function bodies (in this case, the openapi function) to call the api-->
openapi: function(){
let apiParam = {
"accountSid": '98651082ab89c3f1b50f35caf794179f',
"token": 'd7ca4ca93c1e809b96ce30acf0a9a9',
"mobile": '10000000000',
"communityNo": '1316879946',
"cardNo": 'd4JYo5DmvRYApL2l',
"areaCode": '86'
}
let url = 'plugin://yaoshibang/yaoshibang?accountSid=' + apiParam.accountSid + '&token=' + apiParam.token + '&mobile=' + apiParam.mobile + '&communityNo=' + apiParam.communityNo + '&cardNo=' + apiParam.cardNo + '&areaCode=' + apiParam.areaCode;
yaoshibang.getFlag(apiParam).then(res => {
<!--If the info returnvalue is 1, page jump-->
<!--info is 1, the door is unlocked-->
if (res.info === 1) {
wx.navigateTo({
url: url
})
}
<!--If the return value of info is 0, the json data results are displayed, the following res and err junctions are the result of processing, the user can take the next step after obtaining, such as pop-up window display to the user (not demonstrated here)-->
<!--info is 0, the cabinet is unlocked-->
if (res.info === 0) {
let result = yaoshibang.getResult(apiParam);
result.then(res => {
console.log(res)
}).catch(err => {
console.log(err)
})
} else {
<!--info is not 0 or -1, return supramail information directly -->
console.log(res)
}
})
}
BLEPasswordOperation接口
yaoshibang.passwordAdd: (prams:PasswordAddParmas)=>Promise<PasswordAddResult> throw PassworldOperationError
PasswordAddParmas
Required parameters名 | Type | 例 | Explanation |
---|
version | string | 1.0.00 | api Version号 |
accountSid | string | 5621e3c3618de890e48375801ca77e18 | DeveloperAccount唯一标识 |
communityNo | string | 1316880684 | Community No. |
buildNo | string | 001 | Building No. |
floorNo | string | 000 | Floor No. |
roomNo | string | 410 | Room No. |
cipher | string | 123456 | Password |
startTime | string | 202412261200 | Start Time |
endTime | string | 202412271200 | End Time |
token | string | 8732e7bed17b3c0c097bc8af5677df | 令牌 |
holder | string | 车轱辘 | Holder |
callback | (p:ProcessCallback)=>void | | Operation进度回调 |
ProcessCallback
Required parameters名 | Type | 例 | Explanation |
---|
status | number | 0 | 当前OperationStatus |
msg | string | Send数据 | 简短Description |
status | msg |
---|
1 | 请求QR Master |
10 | 分包数据 |
20 | 打开BLE适配器 |
30 | SearchBLE设备 |
40 | 连接锁 |
50 | ObtainBLE service |
60 | ObtainBLE service特征值 |
70 | 向锁写入数据 |
80 | ObtainOperation结果数据 |
90 | 同步数据toQR Master |
PasswordAddResult
Required parameters名 | Type | 例 | Explanation |
---|
cipher | string | 123456 | AddPassword |
power | number | 99 | Electricity 1~100 |
PassworldOperationError
code | message | error | Description |
---|
0 | string | any | 未知错误,message 为简短Description,error 为原始错误对象 |
100 | string | any | ios 用户独有,用户Close了WeChat PaymentBLE权限,需要手动前往系统Setting将WeChat PaymentBLE权限打开 |
101 | string | any | 未授权,用户Close了宿主Mini Program内BLE权限 |
102 | string | any | Mobile系统BLEOff |
103 | | | BLESearch目标锁超时 |
104 | | | Obtain已SearchtoBLE设备Failed |
105 | | | 连接锁Failed |
106 | | | Obtain特征值Failed |
107 | | | 向锁写入数据Failed |
108 | | | 订阅特征值Failed |
109 | | {result:"aabbccdd"} | 锁体Back未知数据,请联系供应商 |
110 | | {code:Number} 声 ringPrompt错误表 | 锁体Back错误 |
111 | string | any | 网络请求错误,请检查你网络 |
112 | any | string | object | QR Master后台业务错误 |
403 | | { status: Number, info:String } | 后台业务错误 |
113 | | any | PasswordOperation succeeded,但同步QR MasterFailed,您需要重新执行PasswordOperation,No则业务将Abnormal |
完整示例
const yaoshibang = requirePlugin("yaoshibang");
async function passwordAdd() {
try {
wx.showLoading();
const result = await yaoshibang.passwordAdd({
version: "1.0.00",
accountSid: "5621e3c3618de890e48375801ca77e18",
communityNo: "1316880684",
buildNo: "001",
floorNo: "000",
roomNo: "410",
cipher: "123456",
startTime: "202412261200",
endTime: "202412271200",
token: "8732e7bed17b3c0c097bc8af5677df",
holder: "车轱辘",
callback: ({ status, msg }) => {
console.log("进度", status, msg);
wx.showLoading({
title: status + ":" + msg,
});
},
});
console.log("Operation succeeded", result);
console.log("Electricity", result.power);
} catch (error) {
if (error instanceof yaoshibang.PassworldOperationError) {
console.error(error.code, error.message, error.error);
} else {
console.error(error);
}
console.log("Operation failed");
} finally {
wx.hideLoading();
}
}
function passwordAdd(){
wx.showLoading();
yaoshibang.passwordAdd({
version: "1.0.00",
accountSid: "5621e3c3618de890e48375801ca77e18",
communityNo: "1316880684",
buildNo: "001",
floorNo: "000",
roomNo: "410",
cipher: "123456",
startTime: "202412261200",
endTime: "202412271200",
token: "8732e7bed17b3c0c097bc8af5677df",
holder: "车轱辘",
callback: ({ status, msg }) => {
console.log("进度", status, msg);
wx.showLoading({
title: status + ":" + msg,
});
},
})
.then((result) => {
console.log("Operation succeeded", result);
console.log("Electricity", result.power);
wx.hideLoading();
})
.catch((error) => {
if (error instanceof yaoshibang.PassworldOperationError) {
console.error(error.code, error.message, error.error);
} else {
console.error(error);
}
console.log("Operation failed");
wx.hideLoading();
});
},
passwordAdd();
yaoshibang.passwordDel: (prams:PasswordDelParmas)=>Promise<PasswordDelResult> throw PassworldOperationError
PasswordDelParmas
Required parameters名 | Type | 例 | Explanation |
---|
version | string | 1.0.00 | api Version号 |
accountSid | string | 5621e3c3618de880e48375801ca77e18 | DeveloperAccount唯一标识 |
communityNo | string | 1316880684 | Community No. |
buildNo | string | 001 | Building No. |
floorNo | string | 000 | Floor No. |
roomNo | string | 410 | Room No. |
cipher | string | 123456 | Password |
token | string | 8732e7bed17b3c1c097bc8af5677df | 令牌 |
callback | (p:ProcessCallback)=>void | | Operation进度回调 |
PasswordAddResult
Required parameters名 | Type | 例 | Explanation |
---|
cipher | string | 123456 | AddPassword |
power | number | 99 | Electricity 1~100 |
yaoshibang.passwordChange: (prams:PasswordChangeParmas)=>Promise<PasswordChangeResult> throw PassworldOperationError
PasswordChangeParmas
Required parameters名 | Type | 例 | Explanation |
---|
version | string | 1.0.00 | api Version号 |
accountSid | string | 5621e3c3618de880e48375801ca77e18 | DeveloperAccount唯一标识 |
communityNo | string | 1316880684 | Community No. |
buildNo | string | 001 | Building No. |
floorNo | string | 000 | Floor No. |
roomNo | string | 410 | Room No. |
oldCipher | string | 123456 | Old password |
newCipher | string | 123456 | New password |
startTime | string | 202412261200 | Start Time |
endTime | string | 202412271200 | End Time |
token | string | 8732e7bed17b3c0c097bc8af5677df | 令牌 |
holder | string | 车轱辘 | Holder |
callback | (p:ProcessCallback)=>void | | Operation进度回调 |
PasswordChangeResult
Required parameters名 | Type | 例 | Explanation |
---|
newCipher | string | 123456 | 新Password |
oldCipher | string | 123456 | 旧Password |
power | number | 99 | Electricity 1~100 |
声 ringPrompt错误表
code | Prompt | 原因,解译 |
---|
1 | Operation succeeded,启动 | LockOperation succeeded,Encrypt、Card Issuer启动, ring声 |
2 | Clearing CardSucceeded | Clear授权信息Succeeded,Recover出厂 |
3 | 密钥不对 | 用户Password错误none效 |
4 | Card type不Normal | Card type出错,or通讯出错,key错误 |
5 | 没StayClients | 五声代表此Room没有客personStay,Checkout Cardnone效 |
6 | Room No.不对 | 房卡Room No.and锁Room No.不同。换Roomor者重新Setting锁 |
7 | Time不对(BLE会Prompt) | 房卡TimeExpireor者Lock记忆时钟不对,重新Obtain cardsor重新setting锁Time |
8 | Batch no.不对(Guest Card) | 该卡被Report the loss,重新generate该Batch no.卡(Guest Card) |
9 | Clearing Cardnone效 | none扭key动作 |
10 | Authorization Card授权码none效 | Lock授权前要拧机械key |
11 | Building Card号none效 | SettingHotel,Building Card不Yes该HotelBuilding Card |
12 | Floor Card号none效 | Setting房号,Floor Card不Yes该FloorFloor Card,重新Setting本Floor楼房号 |
13 | Roomlock the door from the inside | 表示Lock已lock the door from the inside不能打开 |
14 | 电池Electricity低 | 电池Electricity低(锁重启刷房卡也会报 14 声) |
15 | Hotel标示不对 | 刷Authorization Cardor重新发卡不Yes本HotelReception电脑发出来卡片,要inReception电脑上重新发卡 |
16 | 日记collectFailed | 用 IC 卡collect日记时,collect出错锁上报出声音 |
17 | Reading failed | Card IssuerRead出错时发出 ring声 |
18 | 有效Frequencynone效(BLE会Prompt) | Guest Card有效UnlockFrequency用完 |
20 | 品牌号不对 | 非本系统卡 |
21 | Room被封闭中止 | Guest Card、Building、Floor被中止,RoomLock被中止none法Unlock,再刷一下则RecoverNormal |
30 | Agency号不对 | 非本系统卡 |