@@ -0,0 +1,14 @@ | |||
# Windows | |||
[Dd]esktop.ini | |||
Thumbs.db | |||
$RECYCLE.BIN/ | |||
# macOS | |||
.DS_Store | |||
.fseventsd | |||
.Spotlight-V100 | |||
.TemporaryItems | |||
.Trashes | |||
# Node.js | |||
node_modules/ |
@@ -1,3 +1,9 @@ | |||
# MiniprogramParentWeb | |||
随手精灵小程序,单独为了获取WIFI信息加强围栏告警功能能力 | |||
# 版本管理 | |||
## 2.0.0 | |||
`2022.11.16` | |||
- 重构小程序 | |||
- 重构内容 | |||
1. A增加 获取用户wifi信息功能 | |||
2. A 增加 版本控制 | |||
@@ -0,0 +1,7 @@ | |||
{ | |||
"permissions": { | |||
"openapi": [ | |||
"customerServiceMessage.send" | |||
] | |||
} | |||
} |
@@ -0,0 +1,25 @@ | |||
const cloud = require('wx-server-sdk') | |||
cloud.init({ | |||
// API 调用都保持和云函数当前所在环境一致 | |||
env: cloud.DYNAMIC_CURRENT_ENV | |||
}) | |||
// 云函数入口函数 | |||
exports.main = async (event, context) => { | |||
console.log(event) | |||
const { OPENID } = cloud.getWXContext() | |||
const result = await cloud.openapi.customerServiceMessage.send({ | |||
touser: OPENID, | |||
msgtype: 'text', | |||
text: { | |||
content: `收到:${event.Content}`, | |||
} | |||
}) | |||
console.log(result) | |||
return result | |||
} |
@@ -0,0 +1,14 @@ | |||
{ | |||
"name": "callback", | |||
"version": "1.0.0", | |||
"description": "", | |||
"main": "index.js", | |||
"scripts": { | |||
"test": "echo \"Error: no test specified\" && exit 1" | |||
}, | |||
"author": "", | |||
"license": "ISC", | |||
"dependencies": { | |||
"wx-server-sdk": "~2.5.3" | |||
} | |||
} |
@@ -0,0 +1,5 @@ | |||
{ | |||
"permissions": { | |||
"openapi": [] | |||
} | |||
} |
@@ -0,0 +1,8 @@ | |||
const cloud = require('wx-server-sdk') | |||
exports.main = async (event, context) => { | |||
// event.userInfo 是已废弃的保留字段,在此不做展示 | |||
// 获取 OPENID 等微信上下文请使用 cloud.getWXContext() | |||
delete event.userInfo | |||
return event | |||
} |
@@ -0,0 +1,14 @@ | |||
{ | |||
"name": "echo", | |||
"version": "1.0.0", | |||
"description": "", | |||
"main": "index.js", | |||
"scripts": { | |||
"test": "echo \"Error: no test specified\" && exit 1" | |||
}, | |||
"author": "", | |||
"license": "ISC", | |||
"dependencies": { | |||
"wx-server-sdk": "~2.5.3" | |||
} | |||
} |
@@ -0,0 +1,5 @@ | |||
{ | |||
"permissions": { | |||
"openapi": [] | |||
} | |||
} |
@@ -0,0 +1,36 @@ | |||
// 云函数模板 | |||
// 部署:在 cloud-functions/login 文件夹右击选择 “上传并部署” | |||
const cloud = require('wx-server-sdk') | |||
// 初始化 cloud | |||
cloud.init({ | |||
// API 调用都保持和云函数当前所在环境一致 | |||
env: cloud.DYNAMIC_CURRENT_ENV | |||
}) | |||
/** | |||
* 这个示例将经自动鉴权过的小程序用户 openid 返回给小程序端 | |||
* | |||
* event 参数包含小程序端调用传入的 data | |||
* | |||
*/ | |||
exports.main = async (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, | |||
} | |||
} | |||
@@ -0,0 +1,14 @@ | |||
{ | |||
"name": "login", | |||
"version": "1.0.0", | |||
"description": "", | |||
"main": "index.js", | |||
"scripts": { | |||
"test": "echo \"Error: no test specified\" && exit 1" | |||
}, | |||
"author": "", | |||
"license": "ISC", | |||
"dependencies": { | |||
"wx-server-sdk": "~2.5.3" | |||
} | |||
} |
@@ -0,0 +1,15 @@ | |||
{ | |||
"permissions": { | |||
"openapi": [ | |||
"wxacode.get", | |||
"subscribeMessage.send", | |||
"subscribeMessage.addTemplate", | |||
"templateMessage.send", | |||
"templateMessage.addTemplate", | |||
"templateMessage.deleteTemplate", | |||
"templateMessage.getTemplateList", | |||
"templateMessage.getTemplateLibraryById", | |||
"templateMessage.getTemplateLibraryList" | |||
] | |||
} | |||
} |
@@ -0,0 +1,86 @@ | |||
// 云函数入口文件 | |||
const cloud = require('wx-server-sdk') | |||
cloud.init() | |||
// 云函数入口函数 | |||
exports.main = async (event, context) => { | |||
console.log(event) | |||
switch (event.action) { | |||
case 'requestSubscribeMessage': { | |||
return requestSubscribeMessage(event) | |||
} | |||
case 'sendSubscribeMessage': { | |||
return sendSubscribeMessage(event) | |||
} | |||
case 'getWXACode': { | |||
return getWXACode(event) | |||
} | |||
case 'getOpenData': { | |||
return getOpenData(event) | |||
} | |||
default: { | |||
return | |||
} | |||
} | |||
} | |||
async function requestSubscribeMessage(event) { | |||
// 此处为模板 ID,开发者需要到小程序管理后台 - 订阅消息 - 公共模板库中添加模板, | |||
// 然后在我的模板中找到对应模板的 ID,填入此处 | |||
return '请到管理后台申请模板 ID 然后在此替换' // 如 'N_J6F05_bjhqd6zh2h1LHJ9TAv9IpkCiAJEpSw0PrmQ' | |||
} | |||
async function sendSubscribeMessage(event) { | |||
const { OPENID } = cloud.getWXContext() | |||
const { templateId } = event | |||
const sendResult = await cloud.openapi.subscribeMessage.send({ | |||
touser: OPENID, | |||
templateId, | |||
miniprogram_state: 'developer', | |||
page: 'pages/openapi/openapi', | |||
// 此处字段应修改为所申请模板所要求的字段 | |||
data: { | |||
thing1: { | |||
value: '咖啡', | |||
}, | |||
time3: { | |||
value: '2020-01-01 00:00', | |||
}, | |||
} | |||
}) | |||
return sendResult | |||
} | |||
async function getWXACode(event) { | |||
// 此处将获取永久有效的小程序码,并将其保存在云文件存储中,最后返回云文件 ID 给前端使用 | |||
const wxacodeResult = await cloud.openapi.wxacode.get({ | |||
path: 'pages/openapi/openapi', | |||
}) | |||
const fileExtensionMatches = wxacodeResult.contentType.match(/\/([^/]+)/) | |||
const fileExtension = (fileExtensionMatches && fileExtensionMatches[1]) || 'jpg' | |||
const uploadResult = await cloud.uploadFile({ | |||
// 云文件路径,此处为演示采用一个固定名称 | |||
cloudPath: `wxacode_default_openapi_page.${fileExtension}`, | |||
// 要上传的文件内容可直接传入图片 Buffer | |||
fileContent: wxacodeResult.buffer, | |||
}) | |||
if (!uploadResult.fileID) { | |||
throw new Error(`upload failed with empty fileID and storage server status code ${uploadResult.statusCode}`) | |||
} | |||
return uploadResult.fileID | |||
} | |||
async function getOpenData(event) { | |||
return cloud.getOpenData({ | |||
list: event.openData.list, | |||
}) | |||
} |
@@ -0,0 +1,14 @@ | |||
{ | |||
"name": "openapi", | |||
"version": "1.0.0", | |||
"description": "", | |||
"main": "index.js", | |||
"scripts": { | |||
"test": "echo \"Error: no test specified\" && exit 1" | |||
}, | |||
"author": "", | |||
"license": "ISC", | |||
"dependencies": { | |||
"wx-server-sdk": "~2.5.3" | |||
} | |||
} |
@@ -1,19 +1,2 @@ | |||
//app.js | |||
App({ | |||
onLaunch: function () { | |||
if (!wx.cloud) { | |||
console.error('请使用 2.2.3 或以上的基础库以使用云能力') | |||
} else { | |||
wx.cloud.init({ | |||
// env 参数说明: | |||
// env 参数决定接下来小程序发起的云开发调用(wx.cloud.xxx)会默认请求到哪个云环境的资源 | |||
// 此处请填入环境 ID, 环境 ID 可打开云控制台查看 | |||
// 如不填则使用默认环境(第一个创建的环境) | |||
env: 'cloud1-7g8hw3qu242eeb5f', | |||
traceUser: true, //将用户访问记录到用户管理中 | |||
}) | |||
} | |||
this.globalData = {} | |||
} | |||
}) | |||
App({}) |
@@ -0,0 +1,12 @@ | |||
{ | |||
"dependencies": {}, | |||
"name": "miniprogram-4", | |||
"description": "这是云开发的快速启动指引,其中演示了如何上手使用云开发的三大基础能力:", | |||
"version": "1.0.0", | |||
"main": "index.js", | |||
"scripts": { | |||
"test": "echo \"Error: no test specified\" && exit 1" | |||
}, | |||
"author": "", | |||
"license": "ISC" | |||
} |
@@ -0,0 +1,6 @@ | |||
{ | |||
"setting": { | |||
"compileHotReLoad": true | |||
}, | |||
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html" | |||
} |