今天在做第二个发布页面时,想把两个数据库集合放在一个云函数中实现,没有成功,尝试一下第一个发布页面,没有反应,我就删除了一些刚写的代码,还是不行,一直到我把所有新写的代码都删除了,还原了之前的代码,居然还是没有反应,和之前一模一样的代码,怎么就不行了呢?
/**
* 发布事件
*/
onSubmitEvent:function(event){
console.log(event);
const content = event.detail.value.content;
const location=this.data.location;
const author=app.globalData.userInfo;
wx.showLoading({
title:"正在发表中..."
})
// 特3456书yuuo莞6543李zxcz蒜7782法fgnv级
wx.cloud.callFunction({
name:"recruit",
data:{
content:content,
author:author,
location:location,
varchar:event.detail.value.varchar,
firstName:event.detail.value.firstName,
work:event.detail.value.work,
education:event.detail.value.education,
position:""
},
success:res => {
console.log(res);
const _id = res.result._id;
if(_id){
wx.hideLoading();
wx.showToast({
title:"恭喜!发送成功!"
});
setTimeout(function(){
wx.navigateBack({})
},800)
}else{
wx.showToast({
title:res.result.errMsg,
})
}
}
})
},
云函数代码:
if(errcode == 0){
return await db.collection("recruit").add({
data:{
content:content,
author:author,
location:location,
varchar:varchar,
firstName:firstName,
position:position,
work:work,
education:education,
create_time:db.serverDate(),
}
})
}else{
return await {"errcode":1,"errmsg":"您的内容有风险,请修改再发布!"}
};
报错是什么?云函数代码贴全了,不要想当然省略你认为对的部分
// 云函数入口文件
const cloud = require(‘wx-server-sdk’)
cloud.init()
const db = cloud.database();
const got = require(“got“);
const APPID = "wx990cfc380f456732";
const APPSECRET = "16f932f1890ccc67d78a4ad1e327b2cf";
const TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+APPID+”&secret="+APPSECRET
const CHECK_URL = "https://api.weixin.qq.com/wxa/msg_sec_check?access_token="
// 云函数入口函数
exports.main = async (event, context) => {
const content = event.content;
const author = event.author;
const location = event.location;
const varchar = event.varchar;
const firstName = event.firstName;
const position = event.position;
const work = event.work;
const education = event.education;
const tokenResp = await got(TOKEN_URL);
const tokenBody = JSON.parse(tokenResp.body);
const token = tokenBody.access_token;
const chekResp = await got(CHECK_URL+token,{
body:JSON.stringify({
content:content,
})
});
const chekBody = JSON.parse(chekResp.body);
const errcode = chekBody.errcode;
if(errcode == 0){
return await db.collection("recruit").add({
data:{
content:content,
author:author,
location:location,
varchar:varchar,
firstName:firstName,
position:position,
work:work,
education:education,
create_time:db.serverDate(),
}
})
}else{
return await {“errcode”:1“errmsg”:”您的内容有风险,请修改再发布!”}
};
}
if(errcode == 0){
if(collection(“recruit”)){
return await db.collection("recruit”).add({
data:{}
}else if(collection(“release-resume”)){
return await db.collection("recruit”).add({
data:{}
}
尝试过这种方法第二个发表页面会报错
这个是提的一个问题,帮看下,
https://developers.weixin.qq.com/community/develop/doc/00000473b5c7a8d3797e4fbd45b400