#小程序云开发挑战赛#-实验室管理小程序-Rick&Morty
预览链接

原文地址
https://wiki.lifeisgg.online/archives/MyProject-AttendanceMiniprogram/
应用场景
在如今物联网和移动端越来越成熟的形势下,"实验室管理小程序”是一款结合管理实验室出入,记录出入日志,活跃度查看的小程序。用户出入实验室时,与线下的指纹人脸识别等硬件结合,能随时掌握自己出入实验室日志,时长,进入申请等。而管理员可以随时查看管理实验室情况,实验室成员管理,实验室开放关闭等。通过硬件和移动端小程序的结合,能做到高效,透明,规范化实验室管理。
目标用户
高校或其它有实验室机构的组织
实现思路
- 使用云开发构建项目,部署了云函数来获取用户openid,发送实验室进出的服务消息,以及调用腾讯云的云短信服务
- 前端方面,使用了colorUi作为css组件库,搭配uView组件库完成组件开发和页面开发
- 后台方面,将主要业务增删查改使用云开发的数据库存储,部分业务放到自己搭建的后台
- 硬件方面:指纹识别和人脸识别目前正在测试中,所以小程序端只是模拟进出实验室
架构图
功能代码展示
Github:https://github.com/LifeAlsoIsGG/MyProject-AttendanceMiniprogram-2.0
云函数
获取用户openid
// 云函数模板
// 部署:在 cloud-functions/login 文件夹右击选择 “上传并部署”
const cloud = require('wx-server-sdk')
// 初始化 cloud
cloud.init({
// API 调用都保持和云函数当前所在环境一致
env: cloud.DYNAMIC_CURRENT_ENV
})
/**
* 这个示例将经自动鉴权过的小程序用户 openid 返回给小程序端
*
* event 参数包含小程序端调用传入的 data
*
*/
exports.main = (event, context) => {
console.log(event)
console.log(context)
// 可执行其他自定义逻辑
// console.log 的内容可以在云开发云函数调用日志查看
// 获取 WX Context (微信调用上下文),包括 OPENID、APPID、及 UNIONID(需满足 UNIONID 获取条件)等信息
const wxContext = cloud.getWXContext()
return {
event,
openid: wxContext.OPENID,
appid: wxContext.APPID,
unionid: wxContext.UNIONID,
env: wxContext.ENV,
}
}
订阅消息/服务消息
const cloud = require('wx-server-sdk')
cloud.init()
// 云函数入口函数
exports.main = async (event, context) => {
// var formId = event.formId
// console.log('formId=' + formId)
try {
const sendResult = await cloud.openapi.subscribeMessage.send({
touser: cloud.getWXContext().OPENID,
templateId: 'demo',
page: 'pages/home/home',
data: {
thing1: {
value: event.info.user,
},
phrase2: {
value: event.info.status,
},
time3: {
value: event.info.date,
},
thing4: {
value: event.info.rname,
},
thing5: {
value: event.info.address,
}
// event.info.title
// event.info.date
// event.info.address
}
})
console.log(sendResult)
return "sendResult"
} catch (err) {
console.log(err)
return err
}
}
调用腾讯云云短信服务
// 云函数入口文件
cloud.init()
const sms = require("qcloudsms_js")
// 云函数入口函数
exports.main = async (event, context) => new Promise((resolve,reject)=> {
let SmsSdkAppid = 'demo'
let appkey="demo"
let templateId="demo"
let smsSign="实验室出入管理小程序"
let sender=sms(SmsSdkAppid,appkey).SmsSingleSender()
sender.sendWithParam(
86,
event.phone,
templateId,
[event.code],
smsSign,
'','',
(err,res,resData)=>{
if(err){
reject({err})
}else{
resolve({
res:res.req,
resData
})
}
}
)
})
效果截图














