到底能不能用定时器调用subscribeMessage.send云函数?
定时触发配置文件单独上传了,都不行
需求是每隔一段时间自动触发云函数,但一直报错,要是不支持文档里就写清楚
config.json
{
"permissions": {
"openapi": ["subscribeMessage.send"]
},
"triggers": [
{
"name": "myTrigger",
"type": "timer",
"config": "*/5 * * * * * *"
}
]
}
云函数:
const cloud = require('wx-server-sdk');
cloud.init({
env: "oneyu"
})
// cloud.init({
// env: cloud.DYNAMIC_CURRENT_ENV
// })
exports.main = async (event, context) => {
const sendresult = await sendMsg();
return sendresult;
};
async function sendMsg() {
let thing1 = '标题';
let character_string2 = "1000";
let time3 ="2020-03-12 12:23";
let depth ="23km";
return await cloud.openapi.subscribeMessage.send({
touser: 'touser',
template_id: 'template_id',
page: 'pages/xx/xx',
data: {
thing1: {
value: thing1
},
character_string2: {
value: character_string2
},
character_string4: {
value: depth
}
}
}).then((res) => res).catch((err) => err);
}