Compare commits
82 Commits
wangyuhang
...
master
Author | SHA1 | Date |
---|---|---|
|
a60134437a | 2 years ago |
|
d8a681bbc7 | 2 years ago |
|
bbddcfa9db | 2 years ago |
|
9288d10d38 | 2 years ago |
|
dbc8dea9df | 2 years ago |
|
1b0bdcf27e | 2 years ago |
|
78d1d8c247 | 2 years ago |
|
cdcc21bc72 | 2 years ago |
|
27ee2e6871 | 2 years ago |
|
b5786cd580 | 2 years ago |
|
da7f53c554 | 2 years ago |
|
8ef89e26a9 | 2 years ago |
|
e5478db4de | 2 years ago |
|
f0a3712530 | 2 years ago |
|
28bd0c455e | 2 years ago |
|
e649f769f3 | 2 years ago |
|
e59bd68d97 | 2 years ago |
|
cbd067b010 | 2 years ago |
|
e5f0e9ec2e | 2 years ago |
|
909bc5573c | 2 years ago |
|
45fda71950 | 2 years ago |
|
ee10fad031 | 2 years ago |
|
1fb735ebcd | 2 years ago |
|
197b30a141 | 2 years ago |
|
80ee48d8ba | 2 years ago |
|
3b82cb9c2f | 2 years ago |
|
6ffd16b692 | 2 years ago |
|
dc8ab695c5 | 2 years ago |
|
0df4d216a9 | 2 years ago |
|
dde67b878b | 2 years ago |
|
bbb5919bb8 | 2 years ago |
|
97e10672a9 | 2 years ago |
|
fc8a36472c | 2 years ago |
|
732b7d2b4f | 2 years ago |
|
02adbd9c27 | 2 years ago |
|
7fdc64367a | 2 years ago |
|
b82317c981 | 2 years ago |
|
0c9380cf10 | 2 years ago |
|
55820b258f | 2 years ago |
|
ed5644edcf | 2 years ago |
|
41ee8a4f0e | 2 years ago |
|
d9523c5a1d | 2 years ago |
|
e41319be09 | 2 years ago |
|
9265819916 | 2 years ago |
|
b8d89aac7e | 2 years ago |
|
b0508e3050 | 2 years ago |
|
6015f30e13 | 2 years ago |
|
c9b59f17aa | 2 years ago |
|
eb14b5cbf4 | 2 years ago |
|
fa481b2f20 | 2 years ago |
|
ea08ac4594 | 2 years ago |
|
664bde5164 | 2 years ago |
|
a37ea6826e | 2 years ago |
|
1544e42e85 | 2 years ago |
|
31e0335543 | 2 years ago |
|
3467a7e094 | 2 years ago |
|
88e2d69994 | 2 years ago |
|
2cb6fab085 | 2 years ago |
|
8a117b9dcb | 2 years ago |
|
18209c20bf | 2 years ago |
|
58fb8864f1 | 2 years ago |
|
daf026ea81 | 2 years ago |
|
048f8d3bbd | 2 years ago |
|
9789cecedc | 2 years ago |
|
9840e962bc | 2 years ago |
|
01885408a7 | 2 years ago |
|
4519fa4e9c | 2 years ago |
|
0fc5b102ef | 2 years ago |
|
2ca5a78def | 2 years ago |
|
3349b398a9 | 2 years ago |
|
83808ff572 | 2 years ago |
|
3ff9ac998a | 2 years ago |
|
6aaa95e611 | 2 years ago |
|
1988418b9f | 2 years ago |
|
3b7cbf79c5 | 2 years ago |
|
5a8afb942b | 2 years ago |
|
4465b65288 | 2 years ago |
|
ca15ec421c | 2 years ago |
|
530c5169c3 | 2 years ago |
|
c1cecb73dd | 2 years ago |
|
d2a320a82f | 2 years ago |
|
a7a8c0d094 | 2 years ago |
After Width: | Height: | Size: 61 KiB |
After Width: | Height: | Size: 58 KiB |
After Width: | Height: | Size: 56 KiB |
After Width: | Height: | Size: 62 KiB |
After Width: | Height: | Size: 106 KiB |
After Width: | Height: | Size: 60 KiB |
After Width: | Height: | Size: 122 KiB |
After Width: | Height: | Size: 630 KiB |
After Width: | Height: | Size: 1.3 MiB |
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Eslint config file
|
||||||
|
* Documentation: https://eslint.org/docs/user-guide/configuring/
|
||||||
|
* Install the Eslint extension before using this feature.
|
||||||
|
*/
|
||||||
|
module.exports = {
|
||||||
|
env: {
|
||||||
|
es6: true,
|
||||||
|
browser: true,
|
||||||
|
node: true,
|
||||||
|
},
|
||||||
|
ecmaFeatures: {
|
||||||
|
modules: true,
|
||||||
|
},
|
||||||
|
parserOptions: {
|
||||||
|
ecmaVersion: 2018,
|
||||||
|
sourceType: 'module',
|
||||||
|
},
|
||||||
|
globals: {
|
||||||
|
wx: true,
|
||||||
|
App: true,
|
||||||
|
Page: true,
|
||||||
|
getCurrentPages: true,
|
||||||
|
getApp: true,
|
||||||
|
Component: true,
|
||||||
|
requirePlugin: true,
|
||||||
|
requireMiniProgram: true,
|
||||||
|
},
|
||||||
|
// extends: 'eslint:recommended',
|
||||||
|
rules: {},
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
# Windows
|
||||||
|
[Dd]esktop.ini
|
||||||
|
Thumbs.db
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# macOS
|
||||||
|
.DS_Store
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
|
||||||
|
# Node.js
|
||||||
|
node_modules/
|
@ -0,0 +1,12 @@
|
|||||||
|
# 云开发 quickstart
|
||||||
|
|
||||||
|
这是云开发的快速启动指引,其中演示了如何上手使用云开发的三大基础能力:
|
||||||
|
|
||||||
|
- 数据库:一个既可在小程序前端操作,也能在云函数中读写的 JSON 文档型数据库
|
||||||
|
- 文件存储:在小程序前端直接上传/下载云端文件,在云开发控制台可视化管理
|
||||||
|
- 云函数:在云端运行的代码,微信私有协议天然鉴权,开发者只需编写业务逻辑代码
|
||||||
|
|
||||||
|
## 参考文档
|
||||||
|
|
||||||
|
- [云开发文档](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/getting-started.html)
|
||||||
|
|
@ -0,0 +1,23 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
const path = require('path')
|
||||||
|
const yargs = require('yargs')
|
||||||
|
|
||||||
|
yargs
|
||||||
|
.usage('Usage: $0 -c [config] -o [output]')
|
||||||
|
.example('$0 -c ./svrkit.config.js -o ./svrkit-utils.js')
|
||||||
|
.alias('c', 'config')
|
||||||
|
.describe('c', 'svrkit config js file path')
|
||||||
|
.alias('o', 'output')
|
||||||
|
.describe('o', 'svrkit-utils output file path, defaults to svrkit-utils.js under the same folder of svrkit config file')
|
||||||
|
.describe('--keep-case', 'keeps field casing instead of converting to camcel case')
|
||||||
|
.demandOption(['c'])
|
||||||
|
.help('h')
|
||||||
|
.alias('h', 'help')
|
||||||
|
.argv
|
||||||
|
|
||||||
|
const cli = require(path.join(__dirname, '../cli/svrkit-utils.js'))
|
||||||
|
const ret = cli.main(process.argv.slice(2))
|
||||||
|
|
||||||
|
if (typeof ret === 'number') {
|
||||||
|
process.exit(ret)
|
||||||
|
}
|
@ -0,0 +1,114 @@
|
|||||||
|
|
||||||
|
function generate(options) {
|
||||||
|
if (!options) {
|
||||||
|
throw new Error('options must be provided')
|
||||||
|
}
|
||||||
|
|
||||||
|
const { serviceName, funcName, data } = options
|
||||||
|
|
||||||
|
const serviceConfig = config.find(c => c.serviceName === serviceName)
|
||||||
|
if (!serviceConfig) {
|
||||||
|
throw new Error('service not found')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!serviceConfig.functions[funcName]) {
|
||||||
|
throw new Error('function not found')
|
||||||
|
}
|
||||||
|
|
||||||
|
const reqProtoName = serviceConfig.functions[funcName].req
|
||||||
|
const reqProto = proto[reqProtoName]
|
||||||
|
|
||||||
|
if (!reqProto) {
|
||||||
|
throw new Error('request proto not found')
|
||||||
|
}
|
||||||
|
|
||||||
|
const resProtoName = serviceConfig.functions[funcName].res
|
||||||
|
const resProto = resProtoName && proto[resProtoName]
|
||||||
|
|
||||||
|
const reqProtoVerifyErr = reqProto.verify(data)
|
||||||
|
if (reqProtoVerifyErr) {
|
||||||
|
throw new Error(`verify proto data error: ${reqProtoVerifyErr}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const reqProtoJSON = protoJSON.nested[reqProtoName]
|
||||||
|
|
||||||
|
if (reqProtoJSON && reqProtoJSON.fields) {
|
||||||
|
if (Object.prototype.toString.call(data).slice(8, -1) === 'Object') {
|
||||||
|
for (const key in data) {
|
||||||
|
if (!reqProtoJSON.fields[key]) {
|
||||||
|
throw new Error(`'${key}' doesn't exist in '${reqProtoName}' proto, valid keys are ${Object.keys(reqProtoJSON.fields)}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error('data must be object')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: {
|
||||||
|
serviceName,
|
||||||
|
funcName,
|
||||||
|
magic: serviceConfig.magic,
|
||||||
|
cmdid: serviceConfig.functions[funcName].cmdid,
|
||||||
|
existResp: Boolean(resProto),
|
||||||
|
reqBodyBuffer: reqProto.encode(data).finish(),
|
||||||
|
},
|
||||||
|
reqProto,
|
||||||
|
resProto,
|
||||||
|
decode: buf => resProto && resProto.decode(buf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateV2(options) {
|
||||||
|
if (!options) {
|
||||||
|
throw new Error('options must be provided')
|
||||||
|
}
|
||||||
|
|
||||||
|
const { apiName, data } = options
|
||||||
|
|
||||||
|
const apiConfig = config.find(c => c.apiName === apiName)
|
||||||
|
|
||||||
|
const reqProtoName = apiConfig.req
|
||||||
|
const reqProto = proto[reqProtoName]
|
||||||
|
|
||||||
|
if (!reqProto) {
|
||||||
|
throw new Error('request proto not found')
|
||||||
|
}
|
||||||
|
|
||||||
|
const resProtoName = apiConfig.res
|
||||||
|
const resProto = proto[resProtoName]
|
||||||
|
|
||||||
|
const reqProtoVerifyErr = reqProto.verify(data)
|
||||||
|
if (reqProtoVerifyErr) {
|
||||||
|
throw new Error(`verify proto data error: ${reqProtoVerifyErr}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const reqProtoJSON = protoJSON.nested[reqProtoName]
|
||||||
|
|
||||||
|
if (reqProtoJSON && reqProtoJSON.fields) {
|
||||||
|
if (Object.prototype.toString.call(data).slice(8, -1) === 'Object') {
|
||||||
|
for (const key in data) {
|
||||||
|
if (!reqProtoJSON.fields[key]) {
|
||||||
|
throw new Error(`'${key}' doesn't exist in '${reqProtoName}' proto, valid keys are ${Object.keys(reqProtoJSON.fields)}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error('data must be object')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: {
|
||||||
|
apiName,
|
||||||
|
reqBodyBuffer: reqProto.encode(data).finish(),
|
||||||
|
},
|
||||||
|
reqProto,
|
||||||
|
resProto,
|
||||||
|
decode: buf => resProto && resProto.decode(buf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
generate,
|
||||||
|
generateV2,
|
||||||
|
}
|
@ -0,0 +1,98 @@
|
|||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
const yargs = require('yargs')
|
||||||
|
const chalk = require('chalk')
|
||||||
|
const debug = require('debug')('cli')
|
||||||
|
const pbjs = require("protobufjs/cli/pbjs")
|
||||||
|
|
||||||
|
const log = (...msg) => {
|
||||||
|
console.log(chalk.blue('svrkit-utils'), ...msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
function main() {
|
||||||
|
debug('process.cwd', process.cwd())
|
||||||
|
debug('yargs.argv', yargs.argv)
|
||||||
|
|
||||||
|
if (yargs.argv.config) {
|
||||||
|
const configPath = path.resolve(process.cwd(), yargs.argv.config)
|
||||||
|
const config = require(configPath)
|
||||||
|
|
||||||
|
const protos = config.map(c => path.resolve(path.dirname(configPath), c.proto))
|
||||||
|
|
||||||
|
if (yargs.argv.output) {
|
||||||
|
if (!yargs.argv.output.endsWith('.js')) {
|
||||||
|
throw new Error('output file name must ends with .js')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const outputDest = yargs.argv.output || path.resolve(path.dirname(configPath), 'svrkit-utils.js')
|
||||||
|
const outputFileName = path.basename(outputDest)
|
||||||
|
const outputFilePath = path.resolve(process.cwd(), outputDest)
|
||||||
|
|
||||||
|
debug('outputDest', outputDest)
|
||||||
|
debug('outputFilePath', outputFilePath)
|
||||||
|
|
||||||
|
const staticModuleFileName = `${outputFileName.slice(0, -3)}.static.js`
|
||||||
|
const staticModuleFilePath = path.resolve(path.dirname(outputFilePath), staticModuleFileName)
|
||||||
|
|
||||||
|
const staticJsonFileName = `${outputFileName.slice(0, -3)}.static.json`
|
||||||
|
const staticJsonFilePath = path.resolve(path.dirname(outputFilePath), staticJsonFileName)
|
||||||
|
|
||||||
|
log('generating static module')
|
||||||
|
const pbjsArgs = ['-t', 'static-module', '-w', 'commonjs', '-l', 'eslint-disable', '-o', staticModuleFilePath, ...protos]
|
||||||
|
|
||||||
|
if (yargs.argv.keepCase) {
|
||||||
|
pbjsArgs.unshift('--keep-case')
|
||||||
|
}
|
||||||
|
|
||||||
|
pbjs.main(pbjsArgs, (err, out) => {
|
||||||
|
if (err) {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
|
||||||
|
let staticModuleContent = fs.readFileSync(staticModuleFilePath, 'utf8')
|
||||||
|
fs.writeFileSync(staticModuleFilePath, `// #lizard forgives
|
||||||
|
${staticModuleContent}`, 'utf8')
|
||||||
|
|
||||||
|
log('static module generated')
|
||||||
|
|
||||||
|
log('generating json descriptors')
|
||||||
|
pbjs.main(['-t', 'json', '-o', staticJsonFilePath, ...protos], (err, out) => {
|
||||||
|
if (err) {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
|
||||||
|
log('json descriptors generated')
|
||||||
|
|
||||||
|
try {
|
||||||
|
const protoUtils = fs.readFileSync(path.join(__dirname, './svrkit-utils-template.js'), 'utf8')
|
||||||
|
|
||||||
|
let svrkitConfigRelativePath = path.relative(path.dirname(outputDest), configPath)
|
||||||
|
if (!svrkitConfigRelativePath.startsWith('.')) {
|
||||||
|
svrkitConfigRelativePath = `./${svrkitConfigRelativePath}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const output = `
|
||||||
|
const config = require('${svrkitConfigRelativePath}')
|
||||||
|
const proto = require('./${staticModuleFileName}')
|
||||||
|
const protoJSON = require('./${staticJsonFileName}')
|
||||||
|
${protoUtils}
|
||||||
|
`
|
||||||
|
|
||||||
|
fs.writeFileSync(outputFilePath, output, 'utf8')
|
||||||
|
|
||||||
|
log(`${outputFileName} generated`)
|
||||||
|
} catch (err) {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
throw new Error('config file must be provided')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
main,
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"name": "@tencent/cloud-functions-tools",
|
||||||
|
"version": "1.5.1",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "alankldeng",
|
||||||
|
"license": "ISC",
|
||||||
|
"bin": {
|
||||||
|
"svrkit-utils": "bin/svrkit-utils"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^2.4.1",
|
||||||
|
"debug": "^4.1.0",
|
||||||
|
"protobufjs": "^6.8.8",
|
||||||
|
"yargs": "^12.0.5"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
const config = require('./svrkit.config.js')
|
||||||
|
const proto = require('./bundle.js')
|
||||||
|
|
||||||
|
function generate(options) {
|
||||||
|
if (!options) {
|
||||||
|
throw new Error('options must be provided')
|
||||||
|
}
|
||||||
|
|
||||||
|
const { serviceName, funcName, data } = options
|
||||||
|
|
||||||
|
const serviceConfig = config.find(c => c.serviceName === serviceName)
|
||||||
|
if (!serviceConfig) {
|
||||||
|
throw new Error('service not found')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!serviceConfig.functions[funcName]) {
|
||||||
|
throw new Error('function not found')
|
||||||
|
}
|
||||||
|
|
||||||
|
const reqProto = proto[serviceConfig.functions[funcName].req]
|
||||||
|
const resProto = proto[serviceConfig.functions[funcName].res]
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: {
|
||||||
|
serviceName,
|
||||||
|
funcName,
|
||||||
|
magic: serviceConfig.magic,
|
||||||
|
cmdid: serviceConfig.functions[funcName].cmdid,
|
||||||
|
existResp: serviceConfig.functions[funcName].existResp,
|
||||||
|
reqBodyBuffer: reqProto.encode(data),
|
||||||
|
},
|
||||||
|
decode: buf => resProto.decode(resProto)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
generate,
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
message ApiDemoReq
|
||||||
|
{
|
||||||
|
optional string str = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ApiDemoResp
|
||||||
|
{
|
||||||
|
optional string str = 2;
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
message GetWeAppMemberByUserReq
|
||||||
|
{
|
||||||
|
optional uint32 useruin = 1;
|
||||||
|
optional uint32 type = 2; //1:管理员 2:运营者 3:开发人员 4:体验者
|
||||||
|
optional uint32 status = 3; //SAFECENTER_WEAPP_STATUS_XXX
|
||||||
|
}
|
||||||
|
message WeAppMemberInfo
|
||||||
|
{
|
||||||
|
optional uint32 type = 1;
|
||||||
|
optional uint32 weappuin = 2;
|
||||||
|
optional uint32 useruin = 3;
|
||||||
|
optional uint32 status = 4;
|
||||||
|
optional uint32 createtime = 5;
|
||||||
|
optional uint32 updatetime = 6;
|
||||||
|
optional string ticket = 7;
|
||||||
|
}
|
||||||
|
message WeAppMemberInfoList
|
||||||
|
{
|
||||||
|
repeated WeAppMemberInfo infos = 1;
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
message GenWxaCloudTmpCodeReq
|
||||||
|
{
|
||||||
|
optional uint32 CloudPlatform = 1;
|
||||||
|
optional uint32 AppUin = 2;
|
||||||
|
optional uint32 UserUin = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GenWxaCloudTmpCodeResp
|
||||||
|
{
|
||||||
|
optional string TmpCode = 1;
|
||||||
|
}
|
@ -0,0 +1,119 @@
|
|||||||
|
|
||||||
|
const config = require('./svrkit.config.js')
|
||||||
|
const proto = require('./svrkit-utils.static.js')
|
||||||
|
const protoJSON = require('./svrkit-utils.static.json')
|
||||||
|
|
||||||
|
function generate(options) {
|
||||||
|
if (!options) {
|
||||||
|
throw new Error('options must be provided')
|
||||||
|
}
|
||||||
|
|
||||||
|
const { serviceName, funcName, data } = options
|
||||||
|
|
||||||
|
const serviceConfig = config.find(c => c.serviceName === serviceName)
|
||||||
|
if (!serviceConfig) {
|
||||||
|
throw new Error('service not found')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!serviceConfig.functions[funcName]) {
|
||||||
|
throw new Error('function not found')
|
||||||
|
}
|
||||||
|
|
||||||
|
const reqProtoName = serviceConfig.functions[funcName].req
|
||||||
|
const reqProto = proto[reqProtoName]
|
||||||
|
|
||||||
|
if (!reqProto) {
|
||||||
|
throw new Error('request proto not found')
|
||||||
|
}
|
||||||
|
|
||||||
|
const resProtoName = serviceConfig.functions[funcName].res
|
||||||
|
const resProto = resProtoName && proto[resProtoName]
|
||||||
|
|
||||||
|
const reqProtoVerifyErr = reqProto.verify(data)
|
||||||
|
if (reqProtoVerifyErr) {
|
||||||
|
throw new Error(`verify proto data error: ${reqProtoVerifyErr}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const reqProtoJSON = protoJSON.nested[reqProtoName]
|
||||||
|
|
||||||
|
if (reqProtoJSON && reqProtoJSON.fields) {
|
||||||
|
if (Object.prototype.toString.call(data).slice(8, -1) === 'Object') {
|
||||||
|
for (const key in data) {
|
||||||
|
if (!reqProtoJSON.fields[key]) {
|
||||||
|
throw new Error(`'${key}' doesn't exist in '${reqProtoName}' proto, valid keys are ${Object.keys(reqProtoJSON.fields)}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error('data must be object')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: {
|
||||||
|
serviceName,
|
||||||
|
funcName,
|
||||||
|
magic: serviceConfig.magic,
|
||||||
|
cmdid: serviceConfig.functions[funcName].cmdid,
|
||||||
|
existResp: Boolean(resProto),
|
||||||
|
reqBodyBuffer: reqProto.encode(data).finish(),
|
||||||
|
},
|
||||||
|
reqProto,
|
||||||
|
resProto,
|
||||||
|
decode: buf => resProto && resProto.decode(buf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateV2(options) {
|
||||||
|
if (!options) {
|
||||||
|
throw new Error('options must be provided')
|
||||||
|
}
|
||||||
|
|
||||||
|
const { apiName, data } = options
|
||||||
|
|
||||||
|
const apiConfig = config.find(c => c.apiName === apiName)
|
||||||
|
|
||||||
|
const reqProtoName = apiConfig.req
|
||||||
|
const reqProto = proto[reqProtoName]
|
||||||
|
|
||||||
|
if (!reqProto) {
|
||||||
|
throw new Error('request proto not found')
|
||||||
|
}
|
||||||
|
|
||||||
|
const resProtoName = apiConfig.res
|
||||||
|
const resProto = proto[resProtoName]
|
||||||
|
|
||||||
|
const reqProtoVerifyErr = reqProto.verify(data)
|
||||||
|
if (reqProtoVerifyErr) {
|
||||||
|
throw new Error(`verify proto data error: ${reqProtoVerifyErr}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const reqProtoJSON = protoJSON.nested[reqProtoName]
|
||||||
|
|
||||||
|
if (reqProtoJSON && reqProtoJSON.fields) {
|
||||||
|
if (Object.prototype.toString.call(data).slice(8, -1) === 'Object') {
|
||||||
|
for (const key in data) {
|
||||||
|
if (!reqProtoJSON.fields[key]) {
|
||||||
|
throw new Error(`'${key}' doesn't exist in '${reqProtoName}' proto, valid keys are ${Object.keys(reqProtoJSON.fields)}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error('data must be object')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: {
|
||||||
|
apiName,
|
||||||
|
reqBodyBuffer: reqProto.encode(data).finish(),
|
||||||
|
},
|
||||||
|
reqProto,
|
||||||
|
resProto,
|
||||||
|
decode: buf => resProto && resProto.decode(buf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
generate,
|
||||||
|
generateV2,
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,101 @@
|
|||||||
|
{
|
||||||
|
"nested": {
|
||||||
|
"ApiDemoReq": {
|
||||||
|
"fields": {
|
||||||
|
"str": {
|
||||||
|
"type": "string",
|
||||||
|
"id": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ApiDemoResp": {
|
||||||
|
"fields": {
|
||||||
|
"str": {
|
||||||
|
"type": "string",
|
||||||
|
"id": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"GenWxaCloudTmpCodeReq": {
|
||||||
|
"fields": {
|
||||||
|
"CloudPlatform": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 1
|
||||||
|
},
|
||||||
|
"AppUin": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 2
|
||||||
|
},
|
||||||
|
"UserUin": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"GenWxaCloudTmpCodeResp": {
|
||||||
|
"fields": {
|
||||||
|
"TmpCode": {
|
||||||
|
"type": "string",
|
||||||
|
"id": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"GetWeAppMemberByUserReq": {
|
||||||
|
"fields": {
|
||||||
|
"useruin": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 1
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 2
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"WeAppMemberInfo": {
|
||||||
|
"fields": {
|
||||||
|
"type": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 1
|
||||||
|
},
|
||||||
|
"weappuin": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 2
|
||||||
|
},
|
||||||
|
"useruin": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 3
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 4
|
||||||
|
},
|
||||||
|
"createtime": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 5
|
||||||
|
},
|
||||||
|
"updatetime": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 6
|
||||||
|
},
|
||||||
|
"ticket": {
|
||||||
|
"type": "string",
|
||||||
|
"id": 7
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"WeAppMemberInfoList": {
|
||||||
|
"fields": {
|
||||||
|
"infos": {
|
||||||
|
"rule": "repeated",
|
||||||
|
"type": "WeAppMemberInfo",
|
||||||
|
"id": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
module.exports = [
|
||||||
|
{
|
||||||
|
proto: './proto/demo.proto',
|
||||||
|
apiName: 'demo',
|
||||||
|
req: 'ApiDemoReq',
|
||||||
|
res: 'ApiDemoResp'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
proto: './proto/mmbizwxatmpcode.proto',
|
||||||
|
serviceName: 'MMBizWxaCloud',
|
||||||
|
magic: 13299,
|
||||||
|
functions: {
|
||||||
|
GenWxaCloudTmpCode: {
|
||||||
|
cmdid: 3,
|
||||||
|
req: 'GenWxaCloudTmpCodeReq',
|
||||||
|
res: 'GenWxaCloudTmpCodeResp',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
proto: './proto/mmbizsafecenter.proto',
|
||||||
|
serviceName: 'mmbizsafecenter',
|
||||||
|
magic: 12085,
|
||||||
|
functions: {
|
||||||
|
GetWeAppMemberByUser: {
|
||||||
|
cmdid: 73,
|
||||||
|
req: 'GetWeAppMemberByUserReq',
|
||||||
|
res: 'WeAppMemberInfoList',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"permissions": {
|
||||||
|
"openapi": [
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
// 云函数入口文件
|
||||||
|
const cloud = require('wx-server-sdk')
|
||||||
|
const wxgService = require('./wx-server-sdk-wxg-service')
|
||||||
|
const svrkitUtils = require('./svrkit-utils.js')
|
||||||
|
|
||||||
|
cloud.registerService(wxgService)
|
||||||
|
cloud.init()
|
||||||
|
|
||||||
|
// 云函数入口函数
|
||||||
|
exports.main = async (event, context) => {
|
||||||
|
const wxContext = cloud.getWXContext()
|
||||||
|
const bizuin = wxContext.APPUIN
|
||||||
|
switch (event.type) {
|
||||||
|
case "GenerateARModel":
|
||||||
|
return await cloud.callWXSvrkit({
|
||||||
|
pbInstance: svrkitUtils.generate({
|
||||||
|
serviceName: "Mmbizwxaintpar",
|
||||||
|
funcName: "GenerateARModel",
|
||||||
|
data: {
|
||||||
|
bizuin: bizuin,
|
||||||
|
name: event.name,
|
||||||
|
url: event.url,
|
||||||
|
algoType: event.algoType,
|
||||||
|
getmesh: event.getMesh,
|
||||||
|
gettexture: event.getTexture
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
timeout: 30000,
|
||||||
|
});
|
||||||
|
case "GetARModel":
|
||||||
|
return await cloud.callWXSvrkit({
|
||||||
|
pbInstance: svrkitUtils.generate({
|
||||||
|
serviceName: "Mmbizwxaintpar",
|
||||||
|
funcName: "GetARModel",
|
||||||
|
data: {
|
||||||
|
bizuin: bizuin,
|
||||||
|
cosid: event.cosid,
|
||||||
|
modelType: event.modelType,
|
||||||
|
needData: event.needData,
|
||||||
|
useIntranet: event.useIntranet,
|
||||||
|
expireTime: event.expireTime
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
timeout: 30000,
|
||||||
|
});
|
||||||
|
// GetARModelList 废弃,完全依赖本地缓存
|
||||||
|
// case "GetARModelList":
|
||||||
|
// return await cloud.callWXSvrkit({
|
||||||
|
// pbInstance: svrkitUtils.generate({
|
||||||
|
// serviceName: "Mmbizwxaintpar",
|
||||||
|
// funcName: "GetARModelList",
|
||||||
|
// data: {
|
||||||
|
// bizuin: bizuin,
|
||||||
|
// modelStatus: event.modelStatus,
|
||||||
|
// algoType: event.algoType
|
||||||
|
// },
|
||||||
|
// }),
|
||||||
|
// timeout: 30000,
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"name": "ARDemo",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
|
"svrkit": "svrkit-utils --config ./svrkit.config.js --output ./svrkit-utils.js"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"wx-server-sdk": "^2.6.3"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@tencent/cloud-functions-tools": "^1.7.0"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,115 @@
|
|||||||
|
enum enARModelStatus
|
||||||
|
{
|
||||||
|
ARModel_Status_Default = 0;
|
||||||
|
ARModel_Status_Init = 1;
|
||||||
|
ARModel_Status_Sparse_Finished = 2;
|
||||||
|
ARModel_Status_3d_Finished = 3;
|
||||||
|
ARModel_Status_Object_Finished = 4;
|
||||||
|
ARModel_Status_Marker_Finished = 5;
|
||||||
|
ARModel_Status_Fail = 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum enARAlgorithmType
|
||||||
|
{
|
||||||
|
Algorithm_Type_3D_Object = 1;
|
||||||
|
Algorithm_Type_3D_Marker = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum enARModelType
|
||||||
|
{
|
||||||
|
ARModel_Type_Sparse = 1;
|
||||||
|
ARModel_Type_3D = 2;
|
||||||
|
ARModel_Type_Marker = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ModelCos
|
||||||
|
{
|
||||||
|
message ModelCosId
|
||||||
|
{
|
||||||
|
optional enARModelType model_type = 1;
|
||||||
|
optional string model_cosid = 2;
|
||||||
|
optional string errmsg = 3;
|
||||||
|
}
|
||||||
|
repeated ModelCosId model_list = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ARModel
|
||||||
|
{
|
||||||
|
//option(mmbizintpkv.KvTableID) = 493;
|
||||||
|
option(mmbizintpkv.KvTableTestID) = 916;
|
||||||
|
optional string cosid = 1; // 原始文件的cosid
|
||||||
|
optional uint32 bizuin = 2;
|
||||||
|
optional string name = 3; // 原始文件的名称
|
||||||
|
optional uint32 upload_time = 4;
|
||||||
|
optional enARModelStatus model_status = 5;
|
||||||
|
optional enARAlgorithmType algo_type = 6;
|
||||||
|
optional ModelCos model_cos = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetARModelListReq
|
||||||
|
{
|
||||||
|
optional uint32 bizuin = 1;
|
||||||
|
optional uint32 model_status = 2; // enARModelStatus
|
||||||
|
optional uint32 start_time = 3;
|
||||||
|
optional uint32 end_time = 4;
|
||||||
|
optional uint32 offset = 5;
|
||||||
|
optional uint32 limit = 6;
|
||||||
|
optional uint32 algo_type = 7; // enARAlgorithmType
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetARModelListResp
|
||||||
|
{
|
||||||
|
repeated ARModel model_list = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
message GenerateARModelReq
|
||||||
|
{
|
||||||
|
optional uint32 bizuin = 1;
|
||||||
|
optional string name = 2;
|
||||||
|
optional bytes buffer = 3;
|
||||||
|
optional string url = 4;
|
||||||
|
optional enARAlgorithmType algo_type = 5;
|
||||||
|
optional uint32 lod = 6[default=0]; // 重建模型精度, 最高精度为0, 取1,2,3时精度依次下降
|
||||||
|
optional bool getmesh = 7[default=false];
|
||||||
|
optional bool gettexture = 8[default=false];
|
||||||
|
}
|
||||||
|
|
||||||
|
message GenerateARModelResp
|
||||||
|
{
|
||||||
|
optional string url = 1;
|
||||||
|
optional string host = 2;
|
||||||
|
optional string cosid = 3;
|
||||||
|
optional uint32 lod = 4[default=0];
|
||||||
|
optional bool getmesh = 5[default=false];
|
||||||
|
optional bool gettexture = 6[default=false];
|
||||||
|
}
|
||||||
|
|
||||||
|
message ARModelData
|
||||||
|
{
|
||||||
|
optional bytes mesh_model = 1; // 文本(点面信息)
|
||||||
|
optional bytes texture_model = 2; // 图像png
|
||||||
|
optional bytes preview = 3;
|
||||||
|
optional bytes mesh_blob = 4; // obj二进制, getmesh = true时返回
|
||||||
|
optional bytes texture_blob = 5; // 纹理二进制, gettexture = true时返回
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetARModelReq
|
||||||
|
{
|
||||||
|
optional uint32 bizuin = 1;
|
||||||
|
optional string cosid = 2;
|
||||||
|
optional uint32 model_type = 3; // 1:稀疏点云 2:3d模型
|
||||||
|
optional uint32 need_data = 4[default=1]; // 0:不需要数据 1:需要数据
|
||||||
|
optional uint32 use_intranet = 5[default=0]; // 当need_data为0时生效 0:生成外网链接 1:内网链接
|
||||||
|
optional uint32 expire_time = 6; // url过期时间,默认5分钟,单位为秒
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetARModelResp
|
||||||
|
{
|
||||||
|
optional ARModelData model_data = 1;
|
||||||
|
optional string url = 2;
|
||||||
|
optional string host = 3;
|
||||||
|
optional string errMsg = 4;
|
||||||
|
optional uint32 expire_time = 5;
|
||||||
|
optional uint32 status = 6; // 0 创建中 1 成功 2 失败
|
||||||
|
}
|
@ -0,0 +1,136 @@
|
|||||||
|
|
||||||
|
const config = require('./svrkit.config.js')
|
||||||
|
const proto = require('./svrkit-utils.static.js')
|
||||||
|
const protoJSON = require('./svrkit-utils.static.json')
|
||||||
|
function getProto(proto, serviceName, protoName) {
|
||||||
|
if (proto[protoName]) {
|
||||||
|
return proto[protoName];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (proto[serviceName] && proto[serviceName][protoName]) {
|
||||||
|
return proto[serviceName][protoName];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 处理 mmpayolcirclemodel.QueryActivityReq 的形式*/
|
||||||
|
const [realServiceName, realProtoName] = protoName.split('.')
|
||||||
|
if (proto[realServiceName]) {
|
||||||
|
return proto[realServiceName][realProtoName]
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function generate(options) {
|
||||||
|
if (!options) {
|
||||||
|
throw new Error('options must be provided')
|
||||||
|
}
|
||||||
|
|
||||||
|
const { serviceName, funcName, data } = options
|
||||||
|
|
||||||
|
const serviceConfig = config.find(c => c.serviceName === serviceName)
|
||||||
|
if (!serviceConfig) {
|
||||||
|
throw new Error('service not found')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!serviceConfig.functions[funcName]) {
|
||||||
|
throw new Error('function not found')
|
||||||
|
}
|
||||||
|
|
||||||
|
const reqProtoName = serviceConfig.functions[funcName].req
|
||||||
|
const reqProto = getProto(proto, serviceName, reqProtoName);
|
||||||
|
|
||||||
|
if (!reqProto) {
|
||||||
|
throw new Error('request proto not found')
|
||||||
|
}
|
||||||
|
|
||||||
|
const resProtoName = serviceConfig.functions[funcName].res
|
||||||
|
const resProto = resProtoName && getProto(proto, serviceName, resProtoName);
|
||||||
|
|
||||||
|
const reqProtoVerifyErr = reqProto.verify(data)
|
||||||
|
if (reqProtoVerifyErr) {
|
||||||
|
throw new Error(`verify proto data error: ${reqProtoVerifyErr}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const reqProtoJSON = protoJSON.nested[reqProtoName]
|
||||||
|
|
||||||
|
if (reqProtoJSON && reqProtoJSON.fields) {
|
||||||
|
if (Object.prototype.toString.call(data).slice(8, -1) === 'Object') {
|
||||||
|
for (const key in data) {
|
||||||
|
if (!reqProtoJSON.fields[key]) {
|
||||||
|
throw new Error(`'${key}' doesn't exist in '${reqProtoName}' proto, valid keys are ${Object.keys(reqProtoJSON.fields)}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error('data must be object')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: {
|
||||||
|
serviceName,
|
||||||
|
funcName,
|
||||||
|
magic: serviceConfig.magic,
|
||||||
|
cmdid: serviceConfig.functions[funcName].cmdid,
|
||||||
|
existResp: Boolean(resProto),
|
||||||
|
reqBodyBuffer: reqProto.encode(data).finish(),
|
||||||
|
},
|
||||||
|
reqProto,
|
||||||
|
resProto,
|
||||||
|
decode: buf => resProto && resProto.decode(buf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateV2(options) {
|
||||||
|
if (!options) {
|
||||||
|
throw new Error('options must be provided')
|
||||||
|
}
|
||||||
|
|
||||||
|
const { apiName, data } = options
|
||||||
|
|
||||||
|
const apiConfig = config.find(c => c.apiName === apiName)
|
||||||
|
|
||||||
|
const reqProtoName = apiConfig.req
|
||||||
|
const reqProto = proto[reqProtoName]
|
||||||
|
|
||||||
|
if (!reqProto) {
|
||||||
|
throw new Error('request proto not found')
|
||||||
|
}
|
||||||
|
|
||||||
|
const resProtoName = apiConfig.res
|
||||||
|
const resProto = proto[resProtoName]
|
||||||
|
|
||||||
|
const reqProtoVerifyErr = reqProto.verify(data)
|
||||||
|
if (reqProtoVerifyErr) {
|
||||||
|
throw new Error(`verify proto data error: ${reqProtoVerifyErr}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const reqProtoJSON = protoJSON.nested[reqProtoName]
|
||||||
|
|
||||||
|
if (reqProtoJSON && reqProtoJSON.fields) {
|
||||||
|
if (Object.prototype.toString.call(data).slice(8, -1) === 'Object') {
|
||||||
|
for (const key in data) {
|
||||||
|
if (!reqProtoJSON.fields[key]) {
|
||||||
|
throw new Error(`'${key}' doesn't exist in '${reqProtoName}' proto, valid keys are ${Object.keys(reqProtoJSON.fields)}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error('data must be object')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: {
|
||||||
|
apiName,
|
||||||
|
reqBodyBuffer: reqProto.encode(data).finish(),
|
||||||
|
},
|
||||||
|
reqProto,
|
||||||
|
resProto,
|
||||||
|
decode: buf => resProto && resProto.decode(buf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
generate,
|
||||||
|
generateV2,
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,299 @@
|
|||||||
|
{
|
||||||
|
"nested": {
|
||||||
|
"enARModelStatus": {
|
||||||
|
"values": {
|
||||||
|
"ARModel_Status_Default": 0,
|
||||||
|
"ARModel_Status_Init": 1,
|
||||||
|
"ARModel_Status_Sparse_Finished": 2,
|
||||||
|
"ARModel_Status_3d_Finished": 3,
|
||||||
|
"ARModel_Status_Object_Finished": 4,
|
||||||
|
"ARModel_Status_Marker_Finished": 5,
|
||||||
|
"ARModel_Status_Fail": 100
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"enARAlgorithmType": {
|
||||||
|
"values": {
|
||||||
|
"Algorithm_Type_3D_Object": 1,
|
||||||
|
"Algorithm_Type_3D_Marker": 2
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"enARModelType": {
|
||||||
|
"values": {
|
||||||
|
"ARModel_Type_Sparse": 1,
|
||||||
|
"ARModel_Type_3D": 2,
|
||||||
|
"ARModel_Type_Marker": 3
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ModelCos": {
|
||||||
|
"fields": {
|
||||||
|
"modelList": {
|
||||||
|
"rule": "repeated",
|
||||||
|
"type": "ModelCosId",
|
||||||
|
"id": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nested": {
|
||||||
|
"ModelCosId": {
|
||||||
|
"fields": {
|
||||||
|
"modelType": {
|
||||||
|
"type": "enARModelType",
|
||||||
|
"id": 1
|
||||||
|
},
|
||||||
|
"modelCosid": {
|
||||||
|
"type": "string",
|
||||||
|
"id": 2
|
||||||
|
},
|
||||||
|
"errmsg": {
|
||||||
|
"type": "string",
|
||||||
|
"id": 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ARModel": {
|
||||||
|
"options": {
|
||||||
|
"(mmbizintpkv.KvTableTestID)": 916
|
||||||
|
},
|
||||||
|
"fields": {
|
||||||
|
"cosid": {
|
||||||
|
"type": "string",
|
||||||
|
"id": 1
|
||||||
|
},
|
||||||
|
"bizuin": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 2
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string",
|
||||||
|
"id": 3
|
||||||
|
},
|
||||||
|
"uploadTime": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 4
|
||||||
|
},
|
||||||
|
"modelStatus": {
|
||||||
|
"type": "enARModelStatus",
|
||||||
|
"id": 5
|
||||||
|
},
|
||||||
|
"algoType": {
|
||||||
|
"type": "enARAlgorithmType",
|
||||||
|
"id": 6
|
||||||
|
},
|
||||||
|
"modelCos": {
|
||||||
|
"type": "ModelCos",
|
||||||
|
"id": 7
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"GetARModelListReq": {
|
||||||
|
"fields": {
|
||||||
|
"bizuin": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 1
|
||||||
|
},
|
||||||
|
"modelStatus": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 2
|
||||||
|
},
|
||||||
|
"startTime": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 3
|
||||||
|
},
|
||||||
|
"endTime": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 4
|
||||||
|
},
|
||||||
|
"offset": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 5
|
||||||
|
},
|
||||||
|
"limit": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 6
|
||||||
|
},
|
||||||
|
"algoType": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 7
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"GetARModelListResp": {
|
||||||
|
"fields": {
|
||||||
|
"modelList": {
|
||||||
|
"rule": "repeated",
|
||||||
|
"type": "ARModel",
|
||||||
|
"id": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"GenerateARModelReq": {
|
||||||
|
"fields": {
|
||||||
|
"bizuin": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 1
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string",
|
||||||
|
"id": 2
|
||||||
|
},
|
||||||
|
"buffer": {
|
||||||
|
"type": "bytes",
|
||||||
|
"id": 3
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"type": "string",
|
||||||
|
"id": 4
|
||||||
|
},
|
||||||
|
"algoType": {
|
||||||
|
"type": "enARAlgorithmType",
|
||||||
|
"id": 5
|
||||||
|
},
|
||||||
|
"lod": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 6,
|
||||||
|
"options": {
|
||||||
|
"default": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"getmesh": {
|
||||||
|
"type": "bool",
|
||||||
|
"id": 7,
|
||||||
|
"options": {
|
||||||
|
"default": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"gettexture": {
|
||||||
|
"type": "bool",
|
||||||
|
"id": 8,
|
||||||
|
"options": {
|
||||||
|
"default": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"GenerateARModelResp": {
|
||||||
|
"fields": {
|
||||||
|
"url": {
|
||||||
|
"type": "string",
|
||||||
|
"id": 1
|
||||||
|
},
|
||||||
|
"host": {
|
||||||
|
"type": "string",
|
||||||
|
"id": 2
|
||||||
|
},
|
||||||
|
"cosid": {
|
||||||
|
"type": "string",
|
||||||
|
"id": 3
|
||||||
|
},
|
||||||
|
"lod": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 4,
|
||||||
|
"options": {
|
||||||
|
"default": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"getmesh": {
|
||||||
|
"type": "bool",
|
||||||
|
"id": 5,
|
||||||
|
"options": {
|
||||||
|
"default": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"gettexture": {
|
||||||
|
"type": "bool",
|
||||||
|
"id": 6,
|
||||||
|
"options": {
|
||||||
|
"default": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ARModelData": {
|
||||||
|
"fields": {
|
||||||
|
"meshModel": {
|
||||||
|
"type": "bytes",
|
||||||
|
"id": 1
|
||||||
|
},
|
||||||
|
"textureModel": {
|
||||||
|
"type": "bytes",
|
||||||
|
"id": 2
|
||||||
|
},
|
||||||
|
"preview": {
|
||||||
|
"type": "bytes",
|
||||||
|
"id": 3
|
||||||
|
},
|
||||||
|
"meshBlob": {
|
||||||
|
"type": "bytes",
|
||||||
|
"id": 4
|
||||||
|
},
|
||||||
|
"textureBlob": {
|
||||||
|
"type": "bytes",
|
||||||
|
"id": 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"GetARModelReq": {
|
||||||
|
"fields": {
|
||||||
|
"bizuin": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 1
|
||||||
|
},
|
||||||
|
"cosid": {
|
||||||
|
"type": "string",
|
||||||
|
"id": 2
|
||||||
|
},
|
||||||
|
"modelType": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 3
|
||||||
|
},
|
||||||
|
"needData": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 4,
|
||||||
|
"options": {
|
||||||
|
"default": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"useIntranet": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 5,
|
||||||
|
"options": {
|
||||||
|
"default": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"expireTime": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 6
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"GetARModelResp": {
|
||||||
|
"fields": {
|
||||||
|
"modelData": {
|
||||||
|
"type": "ARModelData",
|
||||||
|
"id": 1
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"type": "string",
|
||||||
|
"id": 2
|
||||||
|
},
|
||||||
|
"host": {
|
||||||
|
"type": "string",
|
||||||
|
"id": 3
|
||||||
|
},
|
||||||
|
"errMsg": {
|
||||||
|
"type": "string",
|
||||||
|
"id": 4
|
||||||
|
},
|
||||||
|
"expireTime": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 5
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"type": "uint32",
|
||||||
|
"id": 6
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
// 模块导出一个数组,每个元素是一个模块配置项
|
||||||
|
module.exports = [
|
||||||
|
{
|
||||||
|
// 模块对应的 proto 文件相对于该文件的路径
|
||||||
|
proto: './proto/mmbizwxaintparDemo.proto',
|
||||||
|
// 模块 service name
|
||||||
|
serviceName: 'Mmbizwxaintpar',
|
||||||
|
// 模块 magic 数字
|
||||||
|
magic: 11081,
|
||||||
|
// 模块导出的接口方法
|
||||||
|
functions: {
|
||||||
|
// 接口名字及其对应的接口调用信息
|
||||||
|
GenerateARModel: {
|
||||||
|
// 接口的 cmdid
|
||||||
|
cmdid: 1,
|
||||||
|
// 接口的 request 对应的 protobuf message 名字,需在 proto 文件中定义
|
||||||
|
req: 'GenerateARModelReq',
|
||||||
|
// 接口的 response 对应的 protobuf message 名字,需在 proto 文件中定义
|
||||||
|
res: 'GenerateARModelResp',
|
||||||
|
},
|
||||||
|
// 接口的名字及其对应的接口调用信息
|
||||||
|
GetARModelList: {
|
||||||
|
cmdid: 3,
|
||||||
|
req: 'GetARModelListReq',
|
||||||
|
res: 'GetARModelListResp',
|
||||||
|
},
|
||||||
|
GetARModel: {
|
||||||
|
cmdid: 4,
|
||||||
|
req: 'GetARModelReq',
|
||||||
|
res: 'GetARModelResp',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
@ -0,0 +1,12 @@
|
|||||||
|
## 0.6.0
|
||||||
|
|
||||||
|
1. `A` 新增 `callWXSvrkit` 支持传入 `headuin` 和 `routeMethod`
|
||||||
|
|
||||||
|
## 0.2.0
|
||||||
|
|
||||||
|
1. `A` 新增 `callTencentInnerAPI` 内部接口
|
||||||
|
|
||||||
|
## 0.1.0
|
||||||
|
|
||||||
|
1. `A` 新增 `callWXSvrkit` 内部接口
|
||||||
|
2. `A` 新增 `callWXInnerAPI` 内部接口
|
@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2018 wechat-miniprogram
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "@tencent/wx-server-sdk-wxg-service",
|
||||||
|
"version": "0.7.0",
|
||||||
|
"description": "wxg service plugin for mini program cloud server sdk",
|
||||||
|
"main": "index.js",
|
||||||
|
"author": "wechat mini program team",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"tslib": "^1.9.3"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"permissions": {
|
||||||
|
"openapi": [
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
const saveProfile = require('./saveProfile/index')
|
||||||
|
|
||||||
|
// 云函数入口函数
|
||||||
|
exports.main = async (event, context) => {
|
||||||
|
switch (event.type) {
|
||||||
|
case 'saveProfile':
|
||||||
|
return await getProfile.main(event, context);
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "db",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"wx-server-sdk": "latest"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
// 云函数入口文件
|
||||||
|
const cloud = require('wx-server-sdk')
|
||||||
|
|
||||||
|
// 云函数入口函数
|
||||||
|
exports.main = async () => {
|
||||||
|
cloud.init({
|
||||||
|
env: process.env.TCB_ENV,
|
||||||
|
})
|
||||||
|
const db = cloud.database()
|
||||||
|
return db.collection('perm4').where({
|
||||||
|
_openid: 'server'
|
||||||
|
}).limit(1).get()
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "getServerDataDemo",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"wx-server-sdk": "latest"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
// 云函数入口文件
|
||||||
|
const cloud = require('wx-server-sdk')
|
||||||
|
|
||||||
|
// 云函数入口函数
|
||||||
|
exports.main = async (event) => {
|
||||||
|
cloud.init({
|
||||||
|
env: process.env.TCB_ENV,
|
||||||
|
})
|
||||||
|
const fileList = event.fileIdList
|
||||||
|
const result = await cloud.getTempFileURL({
|
||||||
|
fileList,
|
||||||
|
})
|
||||||
|
return result.fileList
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "getTempFileURL",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"wx-server-sdk": "latest"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
exports.main = (event) => ({
|
||||||
|
openid: event.userInfo.openId,
|
||||||
|
})
|
@ -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": "latest"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
// 云函数入口文件
|
||||||
|
const cloud = require('wx-server-sdk')
|
||||||
|
|
||||||
|
|
||||||
|
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境
|
||||||
|
|
||||||
|
// 云函数入口函数
|
||||||
|
exports.main = async (event, context) => {
|
||||||
|
const wxContext = cloud.getWXContext()
|
||||||
|
|
||||||
|
if (event.op == "")
|
||||||
|
|
||||||
|
return {
|
||||||
|
event,
|
||||||
|
openid: wxContext.OPENID,
|
||||||
|
appid: wxContext.APPID,
|
||||||
|
unionid: wxContext.UNIONID,
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"permissions": {
|
||||||
|
"openapi": [
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
// 云函数入口文件
|
||||||
|
const cloud = require('wx-server-sdk')
|
||||||
|
|
||||||
|
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境
|
||||||
|
const db = wx.cloud.database().collection("orders")
|
||||||
|
const wxContext = cloud.getWXContext()
|
||||||
|
|
||||||
|
// 云函数入口函数
|
||||||
|
exports.main = async () => {
|
||||||
|
|
||||||
|
const result;
|
||||||
|
db.where({
|
||||||
|
_openid: wxContext.OPENID
|
||||||
|
}).get({
|
||||||
|
success: function (res) {
|
||||||
|
result = res
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
// 云函数入口文件
|
||||||
|
// const cloud = require('wx-server-sdk')
|
||||||
|
const get = require("./get")
|
||||||
|
const add = require("./add")
|
||||||
|
|
||||||
|
// cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境
|
||||||
|
|
||||||
|
// 云函数入口函数
|
||||||
|
exports.main = async (event, context) => {
|
||||||
|
// const wxContext = cloud.getWXContext()
|
||||||
|
|
||||||
|
if (event.op == "get") {
|
||||||
|
return await get.main();
|
||||||
|
} else if(event.op == "add") {
|
||||||
|
add()
|
||||||
|
//TODO add paramas
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "orders",
|
||||||
|
"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.6.3"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"permissions": {
|
||||||
|
"openapi": [
|
||||||
|
"wxacode.get"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
const cloud = require('wx-server-sdk');
|
||||||
|
|
||||||
|
cloud.init({
|
||||||
|
env: cloud.DYNAMIC_CURRENT_ENV
|
||||||
|
});
|
||||||
|
|
||||||
|
// 获取小程序二维码云函数入口函数
|
||||||
|
exports.main = async (event, context) => {
|
||||||
|
// 获取小程序二维码的buffer
|
||||||
|
const resp = await cloud.openapi.wxacode.get({
|
||||||
|
path: 'pages/index/index'
|
||||||
|
});
|
||||||
|
const { buffer } = resp;
|
||||||
|
// 将图片上传云存储空间
|
||||||
|
const upload = await cloud.uploadFile({
|
||||||
|
cloudPath: 'code.png',
|
||||||
|
fileContent: buffer
|
||||||
|
});
|
||||||
|
return upload.fileID;
|
||||||
|
};
|
@ -0,0 +1,17 @@
|
|||||||
|
const cloud = require('wx-server-sdk');
|
||||||
|
|
||||||
|
cloud.init({
|
||||||
|
env: cloud.DYNAMIC_CURRENT_ENV
|
||||||
|
});
|
||||||
|
|
||||||
|
// 获取openId云函数入口函数
|
||||||
|
exports.main = async (event, context) => {
|
||||||
|
// 获取基础信息
|
||||||
|
const wxContext = cloud.getWXContext();
|
||||||
|
|
||||||
|
return {
|
||||||
|
openid: wxContext.OPENID,
|
||||||
|
appid: wxContext.APPID,
|
||||||
|
unionid: wxContext.UNIONID,
|
||||||
|
};
|
||||||
|
};
|
@ -0,0 +1,25 @@
|
|||||||
|
const getOpenId = require('./getOpenId/index');
|
||||||
|
const getMiniProgramCode = require('./getMiniProgramCode/index');
|
||||||
|
const createCollection = require('./createCollection/index');
|
||||||
|
const selectRecord = require('./selectRecord/index');
|
||||||
|
const updateRecord = require('./updateRecord/index');
|
||||||
|
const sumRecord = require('./sumRecord/index');
|
||||||
|
|
||||||
|
|
||||||
|
// 云函数入口函数
|
||||||
|
exports.main = async (event, context) => {
|
||||||
|
switch (event.type) {
|
||||||
|
case 'getOpenId':
|
||||||
|
return await getOpenId.main(event, context);
|
||||||
|
case 'getMiniProgramCode':
|
||||||
|
return await getMiniProgramCode.main(event, context);
|
||||||
|
case 'createCollection':
|
||||||
|
return await createCollection.main(event, context);
|
||||||
|
case 'selectRecord':
|
||||||
|
return await selectRecord.main(event, context);
|
||||||
|
case 'updateRecord':
|
||||||
|
return await updateRecord.main(event, context);
|
||||||
|
case 'sumRecord':
|
||||||
|
return await sumRecord.main(event, context);
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "quickstartFunctions",
|
||||||
|
"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.4.0"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
const cloud = require('wx-server-sdk');
|
||||||
|
|
||||||
|
cloud.init({
|
||||||
|
env: cloud.DYNAMIC_CURRENT_ENV
|
||||||
|
});
|
||||||
|
const db = cloud.database();
|
||||||
|
|
||||||
|
// 查询数据库集合云函数入口函数
|
||||||
|
exports.main = async (event, context) => {
|
||||||
|
// 返回数据库查询结果
|
||||||
|
return await db.collection('sales').get();
|
||||||
|
};
|
@ -0,0 +1,18 @@
|
|||||||
|
const cloud = require('wx-server-sdk');
|
||||||
|
|
||||||
|
cloud.init({
|
||||||
|
env: cloud.DYNAMIC_CURRENT_ENV
|
||||||
|
});
|
||||||
|
const db = cloud.database();
|
||||||
|
const $ = db.command.aggregate;
|
||||||
|
|
||||||
|
// 聚合记录云函数入口函数
|
||||||
|
exports.main = async (event, context) => {
|
||||||
|
// 返回数据库聚合结果
|
||||||
|
return db.collection('sales').aggregate()
|
||||||
|
.group({
|
||||||
|
_id: '$region',
|
||||||
|
sum: $.sum('$sales')
|
||||||
|
})
|
||||||
|
.end();
|
||||||
|
};
|
@ -0,0 +1,32 @@
|
|||||||
|
const cloud = require('wx-server-sdk');
|
||||||
|
|
||||||
|
cloud.init({
|
||||||
|
env: cloud.DYNAMIC_CURRENT_ENV
|
||||||
|
});
|
||||||
|
const db = cloud.database();
|
||||||
|
|
||||||
|
// 修改数据库信息云函数入口函数
|
||||||
|
exports.main = async (event, context) => {
|
||||||
|
try {
|
||||||
|
// 遍历修改数据库信息
|
||||||
|
for (let i = 0; i < event.data.length; i++) {
|
||||||
|
await db.collection('sales').where({
|
||||||
|
_id: event.data[i]._id
|
||||||
|
})
|
||||||
|
.update({
|
||||||
|
data: {
|
||||||
|
sales: event.data[i].sales
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
data: event.data
|
||||||
|
};
|
||||||
|
} catch (e) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
errMsg: e
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|