feat: 小程序初始化
This commit is contained in:
parent
cbf8505bae
commit
464f57925b
99
README.md
99
README.md
@ -1,6 +1,103 @@
|
||||
## 星云SDK
|
||||
|
||||
### 1. 安装
|
||||
|
||||
在需要引用的项目中执行命令
|
||||
`git fetch git@code.star-lock.cn:xhj/starcloud-sdk-uniapp.git master`
|
||||
### 2. 需安装的npm包
|
||||
`npm install buffer crc js-md5 pinia sm-crypto`
|
||||
### 3. 使用
|
||||
```javascript
|
||||
import { useStarCloudStore } from '@/starCloud/starCloud'
|
||||
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()
|
||||
if(code === Result.Success.code) {
|
||||
// 逻辑代码
|
||||
} else {
|
||||
// 错误处理
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录
|
||||
* @property {String} username - 用户名
|
||||
* @property {String} password - 密码
|
||||
*/
|
||||
const { code, data, message } = await $starCloud.login(username, password)
|
||||
|
||||
/**
|
||||
* 选择锁
|
||||
* @property {Number} lockId - 锁Id
|
||||
*/
|
||||
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)
|
||||
```
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user