index.obj.js 1.3 KB
Newer Older
study夏羽's avatar
update  
study夏羽 已提交
1
// 开发文档: https://uniapp.dcloud.net.cn/uniCloud/cloud-obj
2
//导入验证码公共模块
study夏羽's avatar
update  
study夏羽 已提交
3
const uniCaptcha = require('uni-captcha')
4
//获取数据库对象
study夏羽's avatar
update  
study夏羽 已提交
5
const db = uniCloud.database();
6
//获取数据表opendb-verify-codes对象
study夏羽's avatar
update  
study夏羽 已提交
7
const verifyCodes = db.collection('opendb-verify-codes')
study夏羽's avatar
study夏羽 已提交
8 9 10 11 12 13 14 15 16


const createConfig = require('uni-config-center')
const captchaConfig = createConfig({ // 获取配置实例
    pluginId: 'captcha-config' // common/uni-config-center下的插件配置目录名
})
const Config = captchaConfig.config() // 获取common/uni-config-center/share-config/config.json的内容

console.log(Config,"15----------");
study夏羽's avatar
update  
study夏羽 已提交
17
module.exports = {
study夏羽's avatar
study夏羽 已提交
18
	
19 20 21 22 23 24 25 26 27 28
	async getImageCaptcha({
		scene
	}) {
		//获取设备id
		let {
			deviceId,
			platform
		} = this.getClientInfo();
		//根据:设备id、场景值、状态,查找记录是否存在
		let res = await verifyCodes.where({
29
			scene,
30 31 32 33 34 35 36
			deviceId,
			state: 0
		}).limit(1).get()
		//如果已存在则调用刷新接口,反之调用插件接口
		let action = res.data.length ? 'refresh' : 'create'
		//执行并返回结果
		//导入配置,配置优先级说明:此处配置 > uni-config-center
37
		return await uniCaptcha[action]({
study夏羽's avatar
study夏羽 已提交
38
			text: Config.text,
39 40 41
			scene, //来源客户端传递,表示:使用场景值,用于防止不同功能的验证码混用
			uniPlatform: platform
		})
study夏羽's avatar
update  
study夏羽 已提交
42 43
	}
}