定时函数发送模板消息发不出去,错误如下
,定时函数请求id: ff320b0c-4a78-11ea-94f5-525400c7e4d7
调用发送订阅消息函数请求id: ff4c08c9-4a78-11ea-b93a-5254007aa7a1
APPID:wx4452804312df5c38,
注:用定时函数调用发送订阅消息函数的请求参数,手动调用发送订阅消息函数发送成功
定时函数代码片段:
async function dealHelp() {
console.log("dealHelp==")
const noTime = new Date().getTime()
const helpList = await db.collection("help").where({
status: 0,
end_time: command.lte(noTime)
}).get()
console.log("dealHelp==")
if (helpList.data.length > 0) {
for (let i = 0; i < helpList.data.length; i++) {
console.log("准备发送模板消息")
const helpItem = helpList.data[i]
await db.collection("help").where({
status: 0,
_id: helpItem._id,
end_time: command.lte(noTime)
}).update({
data: {
status: 2
}
})
console.log("temp_help_fa data== ",helpItem)
await cloud.callFunction({
name: "send_temple_msg",
data: {
type: "temp_help_fa",
data: helpItem
}
})
}
}
发送订阅消息代码片段:
/**
* 发送助力失败模板消息
*/
async function sendTempHelpFaMsg(helpItem) {
try {
const result = await cloud.openapi.subscribeMessage.send({
touser: helpItem.open_id,
page: 'pages/helpInfo/info?help_id=' + helpItem._id,
data: {
thing1: {
value: helpItem.goods_info.goods_name
},
thing2: {
value: '抱歉,你参与的助力活动因过期而失败!'
}
},
templateId: tempids.tmpid_help_fa
})
return result
} catch (err) {
console.log(err)
return err
发送订阅消息 config.json
{
"permissions": {
"openapi": [
"subscribeMessage.send"
]
}
}
解决方案:
https://developers.weixin.qq.com/community/develop/doc/000a265699494018f459acb705b800
提示说是没权限,下面的配置文件有上传吗