cshenfu
2023-05-22 b8c19d1e951619a325a3de2f190725ab198b09c6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// 开发文档: https://uniapp.dcloud.net.cn/uniCloud/cloud-obj
//导入验证码公共模块
const uniCaptcha = require('uni-captcha')
//获取数据库对象
const db = uniCloud.database();
//获取数据表opendb-verify-codes对象
const verifyCodes = db.collection('opendb-verify-codes')
module.exports = {
    async getImageCaptcha({
        scene
    }) {
        //获取设备id
        let {
            deviceId,
            platform
        } = this.getClientInfo();
        //根据:设备id、场景值、状态,查找记录是否存在
        let res = await verifyCodes.where({
            scene,
            deviceId,
            state: 0
        }).limit(1).get()
        //如果已存在则调用刷新接口,反之调用插件接口
        let action = res.data.length ? 'refresh' : 'create'
        //执行并返回结果
        //导入配置,配置优先级说明:此处配置 > uni-config-center
        return await uniCaptcha[action]({
            scene, //来源客户端传递,表示:使用场景值,用于防止不同功能的验证码混用
            uniPlatform: platform
        })
    }
}