2024-10-12 14:35:58 +08:00
|
|
|
|
## 星云SDK
|
|
|
|
|
|
|
|
|
|
|
|
### 1. 安装
|
2024-10-30 14:09:02 +08:00
|
|
|
|
|
2024-10-12 15:23:54 +08:00
|
|
|
|
在需要引用的项目中执行命令
|
2024-10-12 15:26:50 +08:00
|
|
|
|
`git subtree add --prefix=starCloud git@code.star-lock.cn:xhj/starcloud-sdk-uniapp.git master`
|
|
|
|
|
|
更新
|
|
|
|
|
|
`git subtree pull --prefix=starCloud git@code.star-lock.cn:xhj/starcloud-sdk-uniapp.git master`
|
2024-10-30 14:09:02 +08:00
|
|
|
|
|
2024-10-12 14:35:58 +08:00
|
|
|
|
### 2. 需安装的npm包
|
2024-10-30 14:09:02 +08:00
|
|
|
|
|
2024-10-12 14:35:58 +08:00
|
|
|
|
`npm install buffer crc js-md5 pinia sm-crypto`
|
2024-10-12 15:30:25 +08:00
|
|
|
|
|
|
|
|
|
|
pinia是全局状态管理工具,需在main.js中引入
|
2024-10-30 14:09:02 +08:00
|
|
|
|
|
2024-10-12 15:30:25 +08:00
|
|
|
|
```javascript
|
|
|
|
|
|
import * as Pinia from 'pinia'
|
2024-10-30 14:09:02 +08:00
|
|
|
|
|
2024-10-12 15:30:25 +08:00
|
|
|
|
const store = Pinia.createPinia()
|
|
|
|
|
|
app.use(store)
|
|
|
|
|
|
```
|
2024-10-30 14:09:02 +08:00
|
|
|
|
|
2024-10-12 15:23:54 +08:00
|
|
|
|
### 3. 使用
|
2024-10-30 14:09:02 +08:00
|
|
|
|
|
2024-10-12 15:23:54 +08:00
|
|
|
|
```javascript
|
|
|
|
|
|
import { useStarCloudStore } from '@/starCloud/starCloud'
|
2024-10-30 14:09:02 +08:00
|
|
|
|
|
2024-10-12 15:23:54 +08:00
|
|
|
|
const $starCloud = useStarCloudStore()
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 初始化SDK
|
|
|
|
|
|
* @property {String} clientId - 客户端Id
|
|
|
|
|
|
* @property {String} clientSecret - 客户端密码
|
|
|
|
|
|
* @property {String} env - 环境('DEV', 'PRE', 'XHJ', 'SKY)
|
|
|
|
|
|
*/
|
|
|
|
|
|
$starCloud.initStarCloud(clientId, clientSecret, env)
|
|
|
|
|
|
|
|
|
|
|
|
// 注册,后续所有方法调用返回值均为code, data, message
|
|
|
|
|
|
// code对应报错码有三部分组合构成,锁端报错码+星云服务端报错码+自定义报错码
|
|
|
|
|
|
// Result类定义了所有自定义报错码,具体报错码请查看Result类
|
|
|
|
|
|
const { code, data, message } = await $starCloud.register()
|
2024-10-30 14:09:02 +08:00
|
|
|
|
if (code === Result.Success.code) {
|
2024-10-12 15:23:54 +08:00
|
|
|
|
// 逻辑代码
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 错误处理
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 登录
|
|
|
|
|
|
* @property {String} username - 用户名
|
|
|
|
|
|
* @property {String} password - 密码
|
|
|
|
|
|
*/
|
|
|
|
|
|
const { code, data, message } = await $starCloud.login(username, password)
|
|
|
|
|
|
|
2024-10-31 18:41:21 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 退出登录(未做请求,实际上不会失败)
|
|
|
|
|
|
*/
|
|
|
|
|
|
const { code, data, message } = await $starCloud.logout()
|
|
|
|
|
|
|
2024-10-12 15:23:54 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 选择锁
|
|
|
|
|
|
* @property {Number} lockId - 锁Id
|
|
|
|
|
|
*/
|
2024-10-30 14:09:02 +08:00
|
|
|
|
// 所需信息data中会返回,如data中没有可通过$starCloud.lockInfo获取
|
2024-10-12 15:23:54 +08:00
|
|
|
|
const { code, data, message } = await $starCloud.selectLock(lockId)
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 开门
|
|
|
|
|
|
* @property {String} type - 开门或关门类型('open', 'close')
|
|
|
|
|
|
* @property {Boolean} disconnect - 操作完成后是否断开连接
|
|
|
|
|
|
*/
|
|
|
|
|
|
const { code, data, message } = await $starCloud.openDoor(type, disconnect)
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 清理用户
|
|
|
|
|
|
* @property {Boolean} disconnect - 操作完成后是否断开连接
|
|
|
|
|
|
*/
|
|
|
|
|
|
const { code, data, message } = await $starCloud.cleanLockUser(disconnect)
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取离线密码
|
|
|
|
|
|
* 该功能无需蓝牙交互直接请求服务端,详细参数说明请看星云接口文档
|
|
|
|
|
|
* @typedef {Object} password
|
|
|
|
|
|
* @property {String} keyboardPwdName - 密码名称
|
|
|
|
|
|
* @property {Number} keyboardPwdType - 密码类型
|
|
|
|
|
|
* @property {Number} isCoerced - 胁迫 1:胁迫 2:非胁迫
|
|
|
|
|
|
* @property {Number} startDate - 开始时间
|
|
|
|
|
|
* @property {Number} endDate - 结束时间
|
|
|
|
|
|
* @property {Number} hoursStart - 开始小时
|
|
|
|
|
|
* @property {Number} hoursEnd - 结束小时
|
|
|
|
|
|
*/
|
|
|
|
|
|
const data = await $starCloud.getOfflinePassword({
|
|
|
|
|
|
keyboardPwdName: `租客端单次密码${new Date().getTime()}`,
|
|
|
|
|
|
keyboardPwdType: 1,
|
|
|
|
|
|
isCoerced: 2,
|
|
|
|
|
|
startDate: 0,
|
|
|
|
|
|
endDate: 0,
|
|
|
|
|
|
hoursStart: 0,
|
|
|
|
|
|
hoursEnd: 0
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 自定义密码
|
|
|
|
|
|
* @typedef {Object} password
|
|
|
|
|
|
* @property {String} keyboardPwdName - 密码名称
|
|
|
|
|
|
* @property {Number} keyboardPwdType - 密码类型
|
|
|
|
|
|
* @property {Number} isCoerced - 胁迫 1:胁迫 2:非胁迫
|
|
|
|
|
|
* @property {Number} startDate - 开始时间
|
|
|
|
|
|
* @property {Number} endDate - 结束时间
|
|
|
|
|
|
* @property {Number} keyboardPwd - 密码
|
|
|
|
|
|
* @property {Number} addType - 添加方式,当前仅支持1 1:蓝牙 2:网关
|
|
|
|
|
|
* @property {Number} operate - 操作类型,0:注册 1:修改
|
|
|
|
|
|
* @property {Number} pwdRight - 是否是管理员密码,0:否 1:是
|
|
|
|
|
|
*/
|
|
|
|
|
|
const data = await $starCloud.customPassword({
|
|
|
|
|
|
keyboardPwdName: `租客端自定义密码`,
|
|
|
|
|
|
keyboardPwdType: 3,
|
|
|
|
|
|
keyboardPwd: 111111,
|
|
|
|
|
|
addType: 1,
|
|
|
|
|
|
isCoerced: 2,
|
|
|
|
|
|
startDate: 1728698137000,
|
|
|
|
|
|
endDate: 1735574400000,
|
|
|
|
|
|
operate: 0,
|
|
|
|
|
|
pwdRight: 0
|
|
|
|
|
|
}, true)
|
2024-10-30 14:09:02 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 搜索蓝牙设备
|
|
|
|
|
|
*/
|
|
|
|
|
|
await $starCloud.searchDevice(searchDevice)
|
|
|
|
|
|
const searchDevice = async result => {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 停止搜索
|
|
|
|
|
|
*/
|
|
|
|
|
|
await $starCloud.stopSearchDevice()
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 连接蓝牙设备
|
|
|
|
|
|
* @property {String} name - 设备名称
|
|
|
|
|
|
*/
|
|
|
|
|
|
const data = await $starCloud.bindDevice(name)
|
2024-10-12 15:23:54 +08:00
|
|
|
|
```
|