代码拉取完成,页面将自动刷新
'use strict';
const app = require("tcb-admin-node");
exports.main = async (event, context, callback) => {
if (event.httpMethod != 'POST') {
console.log(JSON.stringify(event))
return {
'isBase64Encoded': false,
'statusCode' : 403,
'headers' : {'Content-Type':'text/html; charset=utf-8'},
'body' : 'invalid_request_method'
};
}
// 从 body 中获取数据
var data = null;
try {
data = JSON.parse(event.body);
console.log(JSON.stringify(data))
}catch(e){
console.log(JSON.stringify(event))
return {
'isBase64Encoded': false,
'statusCode' : 403,
'headers' : {'Content-Type':'text/html; charset=utf-8'},
'body' : 'invalid_data_format'
};
}
if (data) {
let json = {
"answer_id":data.payload.answer_id,
"qq":data.payload.qq,
"weixin_openid":data.payload.weixin_openid,
"source":getAnswer(data,0,"q-1-yRh2","text"),
"attachment":getAnswer(data,0,"q-10-NYLq","file_name_src"),
"attachmentSrc":getAnswer(data,0,"q-10-NYLq","file_name_dst"),
"helpSeeker":getAnswer(data,0,"q-2-LUYh","text"),
"phoneOfHelpSeeker":getAnswer(data,0,"q-8-tvM9","text"),
"idOfHelpSeeker":getAnswer(data,0,"q-3-iLje","text"),
"family":getAnswer(data,0,"q-5-Qza9","text"),
"address":getAnswer(data,0,"q-4-4TUk","text"),
"phone":getAnswer(data,0,"q-7-Qq5r","text"),
"status":getAnswer(data,0,"q-9-zh9f","text"),
"datauirements":getAnswer(data,0,"q-6-LEh8","text")
}
// response 200
app.init({env: process.env.ENV})
const db = app.database();
const _ = db.command
let collection = db.collection(process.env.DB);
await collection.add(json);
return {
'isBase64Encoded': false,
'statusCode' : 200,
'headers' : {'Content-Type':'text/html; charset=utf-8'},
'body' : JSON.stringify(json)
};
}else{
console.log(JSON.stringify(event))
return {
'isBase64Encoded': false,
'statusCode' : 403,
'headers' : {'Content-Type':'text/html; charset=utf-8'},
'body' : 'invalid_data_format'
};
}
console.log("异常退出")
console.log(JSON.stringify(event));
};
function getAnswer(data,answerIndex,questionID,property){
var questions = data.payload.answer[answerIndex].questions;
for(var i=0;i<questions.length;i++){
if(questions[i].id==questionID){
return questions[i][property];
}
}
return null
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。