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 APIwidget 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名TypeExplanation
versionstring1.0.00api Version号
accountSidstring5621e3c3618de890e48375801ca77e18DeveloperAccount唯一标识
communityNostring1316880684Community No.
buildNostring001Building No.
floorNostring000Floor No.
roomNostring410Room No.
cipherstring123456Password
startTimestring202412261200Start Time
endTimestring202412271200End Time
tokenstring8732e7bed17b3c0c097bc8af5677df令牌
holderstring车轱辘Holder
callback(p:ProcessCallback)=>voidOperation进度回调

ProcessCallback

Required parameters名TypeExplanation
statusnumber0当前OperationStatus
msgstringSend数据简短Description
statusmsg
1请求QR Master
10分包数据
20打开BLE适配器
30SearchBLE设备
40连接锁
50ObtainBLE service
60ObtainBLE service特征值
70向锁写入数据
80ObtainOperation结果数据
90同步数据toQR Master

PasswordAddResult

Required parameters名TypeExplanation
cipherstring123456AddPassword
powernumber99Electricity 1~100

PassworldOperationError

codemessageerrorDescription
0stringany未知错误,message 为简短Description,error 为原始错误对象
100stringanyios 用户独有,用户Close了WeChat PaymentBLE权限,需要手动前往系统Setting将WeChat PaymentBLE权限打开
101stringany未授权,用户Close了宿主Mini Program内BLE权限
102stringanyMobile系统BLEOff
103BLESearch目标锁超时
104Obtain已SearchtoBLE设备Failed
105连接锁Failed
106Obtain特征值Failed
107向锁写入数据Failed
108订阅特征值Failed
109{result:"aabbccdd"}锁体Back未知数据,请联系供应商
110{code:Number} 声 ringPrompt错误表锁体Back错误
111stringany网络请求错误,请检查你网络
112anystring | objectQR Master后台业务错误
403{
   status: Number,
   info:String
}
后台业务错误
113anyPasswordOperation 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();
                    }
                  }
                
                  //Promise风格
                  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名TypeExplanation
versionstring1.0.00api Version号
accountSidstring5621e3c3618de880e48375801ca77e18DeveloperAccount唯一标识
communityNostring1316880684Community No.
buildNostring001Building No.
floorNostring000Floor No.
roomNostring410Room No.
cipherstring123456Password
tokenstring8732e7bed17b3c1c097bc8af5677df令牌
callback(p:ProcessCallback)=>voidOperation进度回调

PasswordAddResult

Required parameters名TypeExplanation
cipherstring123456AddPassword
powernumber99Electricity 1~100

yaoshibang.passwordChange: (prams:PasswordChangeParmas)=>Promise<PasswordChangeResult> throw PassworldOperationError

PasswordChangeParmas

Required parameters名TypeExplanation
versionstring1.0.00api Version号
accountSidstring5621e3c3618de880e48375801ca77e18DeveloperAccount唯一标识
communityNostring1316880684Community No.
buildNostring001Building No.
floorNostring000Floor No.
roomNostring410Room No.
oldCipherstring123456Old password
newCipherstring123456New password
startTimestring202412261200Start Time
endTimestring202412271200End Time
tokenstring8732e7bed17b3c0c097bc8af5677df令牌
holderstring车轱辘Holder
callback(p:ProcessCallback)=>voidOperation进度回调

PasswordChangeResult

Required parameters名TypeExplanation
newCipherstring123456新Password
oldCipherstring123456旧Password
powernumber99Electricity 1~100

声 ringPrompt错误表

codePrompt原因,解译
1Operation succeeded,启动LockOperation succeeded,Encrypt、Card Issuer启动, ring声
2Clearing CardSucceededClear授权信息Succeeded,Recover出厂
3密钥不对用户Password错误none效
4Card type不NormalCard type出错,or通讯出错,key错误
5没StayClients五声代表此Room没有客personStay,Checkout Cardnone效
6Room No.不对房卡Room No.and锁Room No.不同。换Roomor者重新Setting锁
7Time不对(BLE会Prompt)房卡TimeExpireor者Lock记忆时钟不对,重新Obtain cardsor重新setting锁Time
8Batch no.不对(Guest Card)该卡被Report the loss,重新generate该Batch no.卡(Guest Card)
9Clearing Cardnone效none扭key动作
10Authorization Card授权码none效Lock授权前要拧机械key
11Building Card号none效SettingHotel,Building Card不Yes该HotelBuilding Card
12Floor Card号none效Setting房号,Floor Card不Yes该FloorFloor Card,重新Setting本Floor楼房号
13Roomlock the door from the inside表示Lock已lock the door from the inside不能打开
14电池Electricity低电池Electricity低(锁重启刷房卡也会报 14 声)
15Hotel标示不对刷Authorization Cardor重新发卡不Yes本HotelReception电脑发出来卡片,要inReception电脑上重新发卡
16日记collectFailed用 IC 卡collect日记时,collect出错锁上报出声音
17Reading failedCard IssuerRead出错时发出 ring声
18有效Frequencynone效(BLE会Prompt)Guest Card有效UnlockFrequency用完
20品牌号不对非本系统卡
21Room被封闭中止Guest Card、Building、Floor被中止,RoomLock被中止none法Unlock,再刷一下则RecoverNormal
30Agency号不对非本系统卡