1.Overview
Third-party program plug-in to provide Bluetooth lock door service, users in accordance with the requirements of ginseng, to achieve Bluetooth unlockThe third party small program plug-in provides a custom password function, and users can pass parameters according to the requirements to achieve Bluetooth add, modify and delete the password.
2. Integration Instructions
Small program developers call plug-in for Bluetooth lock door, use the method see the program official APIwidget Guide
QR Key Mini Program app-id: wxbe18a842c8d14445
III. 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 Code
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">Call 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 interface

yaoshibang.passwordAdd: (prams:PasswordAddParmas)=>Promise<PasswordAddResult> throw PassworldOperationError

PasswordAddParmas

Parameter Name Type example Explanation
version string 1.0.00 api version
accountSid string 5621e3c3618de890e48375801ca77e18 Unique identification of developer account
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 token
holder string UCLBRT Holder
callback (p:ProcessCallback)=>void Operation progress callback

ProcessCallback

Parameter Name Type example Explanation
status number 0 Current operating state
msg string Send data Short description
status msg
1 Request QR Master
10 Subcontracting data
20 Turn on Bluetooth adapter
30 Search Bluetooth devices
40 Connecting lock
50 Get Bluetooth services
60 Get the Bluetooth service feature value
70 Writes data to the lock
80 Obtain operation result data
90 Synchronize data to QR Master

PasswordAddResult

Parameter Name Type example Explanation
cipher string 123456 Added password
power number 99 Battery level 1~100

PassworldOperationError

code message error Description
0 string any Unknown error,message is a short description, error is the original error object
100 string any Unique to ios users, the user has turned off the wechat Bluetooth permission, and needs to manually go to the system Settings to turn on the wechat Bluetooth permission
101 string any The user has disabled the Bluetooth permission in the host applet without authorization
102 string any The Bluetooth of the mobile phone system is disabled
103 string Bluetooth search target lock timed out
104 string Failed to obtain the searched Bluetooth device Procedure
105 string Connection lock failure
106 string Failed to obtain the eigenvalue Procedure
107 string Failed to write data to the lock
108 string Failed to subscribe to the feature value
109 string {result:"aabbccdd"} Lock body returns unknown data, please contact the supplier
110 string {code:Number} Beep Error Reference Lock body return error
111 string any Network request error, please check your network
112 any string | object The background service of the QR Master is incorrect
403 string {
   status: Number,
   info:String
}
Back office service error
113 string any The password operation succeeded, but failed to synchronize the QR Master. You need to perform the password operation again; otherwise, the service will be abnormal

Complete Example

  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: "UCLBRT",
                        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: "UCLBRT",
                        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

Parameter Name Type example Explanation
version string 1.0.00 api version
accountSid string 5621e3c3618de880e48375801ca77e18 Unique identification of developer account
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 token
callback (p:ProcessCallback)=>void Operation progress callback

PasswordDelResult

Parameter Name Type example Explanation
cipher string 123456 Deleted password
mac string 1234567A1234 MAC address
power number 99 Battery level 1~100

yaoshibang.passwordsDel: (prams:PasswordDelParmas)=>Promise<PasswordDelResult> throw PassworldOperationError

PasswordsDelParmas

Parameter Name Type example Explanation
version string 1.0.00 api version
accountSid string 5621e3c3618de880e48375801ca77e18 Unique identification of developer account
communityNo string 1316880684 Community No.
buildNo string 001 Building No.
floorNo string 000 Floor No.
roomNo string 410 Room No.
ciphers array ['123456', '234567'] Password (up to 10 deleted)
token string 8732e7bed17b3c1c097bc8af5677df token
callback (p:ProcessCallback)=>void Operation progress callback

PasswordsDelResult

Parameter Name Type example Explanation
cipher array ['123456','234567'] Deleted password
mac string 1234567A1234 MAC address
power number 99 Battery level 1~100

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

PasswordChangeParmas

Parameter Name Type example Explanation
version string 1.0.00 api version
accountSid string 5621e3c3618de880e48375801ca77e18 Unique identification of developer account
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 token
holder string UCLBRT Holder
callback (p:ProcessCallback)=>void Operation progress callback

PasswordChangeResult

Parameter Name Type example Explanation
newCipher string 123456 New password
oldCipher string 123456 Old password
power number 99 Battery level 1~100

Beep Error Reference

code Prompt Cause and explanation
1 Operation successful; startup Sounds when a lock operation succeeds, encryption is performed, or the card issuer starts
2 Clear card processed successfully Authorization information cleared; factory settings restored
3 Key mismatch User password is incorrect or invalid
4 Invalid card type Card type, communication, or key error
5 No guest checked in Five beeps indicate no guest is checked into this room; the checkout card is invalid
6 Room number mismatch The room number on the card differs from the lock. Change rooms or reconfigure the lock
7 Time mismatch (reported over Bluetooth) The card has expired or the lock clock is incorrect. Obtain a new card or reset the lock time
8 Batch number mismatch (guest card) This card was reported lost. Reissue a card with the same batch number (guest card)
9 Invalid clear card The key has not been turned
10 Invalid authorization code on the authorization card Turn the mechanical key before authorizing the lock
11 Invalid building card number The building card used to configure the hotel belongs to a different hotel
12 Invalid floor card number The floor card used to set the room number belongs to a different floor. Reset the room numbers for this floor
13 Room deadbolted The lock is deadbolted and cannot be opened
14 Low battery Low battery (presenting a card after the lock restarts also produces 14 beeps)
15 Hotel identifier mismatch The authorization or reissued card was not issued on this hotel's front desk computer. Reissue it on that computer
16 Log collection failed Sound emitted by the lock when log collection with an IC card fails
17 Reading failed Sound emitted when the card issuer fails to read a card
18 Invalid usage count (reported over Bluetooth) The guest card has used all its allowed unlocks
20 Brand number mismatch Card belongs to a different system
21 Room access suspended The guest card, building, or floor is suspended, preventing the room lock from opening. Present the card again to restore normal operation
30 Distributor number mismatch Card belongs to a different system