console.log('发送消息:'+id);
this.db=uniCloud.databaseForJQL({ // 获取JQL database引用,此处需要传入云对象的clientInfo
clientInfo: this.getClientInfo()
})
// this.time= uniCloud.importObject('timer')
//------------------
let dbok=true;
let dlist=[];
let num = 0;
while(dbok){
let res = await this.db.collection('uni-id-users').where(targettimes=='${id}'&&wx_openid!=null
).field('wx_openid,yes').skip(100*num).limit(100).get()
res=res.data
console.log(res.length);
// console.log(res);
dlist = dlist.concat(res)
num++;
if(res.length<100){
dbok=false
}
}
res=dlist
console.log(res.length);
//---------------------
let num1 = 0;
try{
let token = await tools.gettoken()
for(let i in res){
if(res[i].wx_openid!=null){
num1++;
console.log(res[i].wx_openid['h5']);
await tools.sendmsg(res[i].wx_openid['h5'],'[愉快]暂停一下,来记六时书吧~\nV 美德\n+ 做的好事(要为自己高兴哦[庆祝])\n- 不好的事(只记录,不评判,用四力量)\n= 即将要做的事',token)
}
}
console.log(num1);
} catch(e){
console.log(e);
}
return 'ok';
tools.js
/**
-
发客公众号消息
*/
async sendmsg(openid, con, token) {
try {
await setTimeout(()=>{},100)
let content = con
let res = await uniCloud.httpclient.request(
'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' + token, {
contentType: 'json',
dataType: "json",
timeout:600000,
method: "POST",
data: {
"touser": openid,
"msgtype": "text",
"text": {
"content": content
}
}
})
return res;
} catch (e) {
//TODO handle the exception
console.log('发送消息报错');
console.log(e);
}},
2 个回复
姜同学 (作者) - demo
没人看下吗,都耽误正常运营了
DCloud_uniCloud_WYQ
现在还有这个报错吗?阿里那边排查到是你这个云函数的某个实例出现了问题,现在已经自动恢复了。阿里下次发版会修正这个问题
姜同学 (作者)
有的还是报错,Response timeout for 300000ms, POST https://api-inner.next.bspapp.com/server -1 还是超时
2023-08-08 20:29
姜同学 (作者)
回复 8***@qq.com: 应该是设置的600000ms一半时间就超时了
2023-08-08 20:34
姜同学 (作者)
[timer/ac1cc3061691503100965170205/375750ms/ERROR] (node:4) UnhandledPromiseRejectionWarning: Error: Response timeout for 300000ms, POST https://api-inner.next.bspapp.com/server -1 (connected: true, keepalive socket: false, socketHandledRequests: 1, socketHandledResponses: 0)
headers: {}
at e.$scope.function.invoke.then.catch.e (/tmp/function/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:95698)
at <anonymous>
2023-08-08 22:09
DCloud_uniCloud_WYQ
回复 8***@qq.com: 你被调用的云函数是干什么的?一定会运行超过30秒吗?
2023-08-09 11:00
姜同学 (作者)
回复 DCloud_uniCloud_WYQ: 对的是批量发送公众号客服消息,有1000多条
2023-08-10 19:40
姜同学 (作者)
回复 8***@qq.com: 总会超时,引入云函本身,想分批发送。也会报错 https://api.next.bspapp.com/server 504或者-1报错
2023-08-10 19:42
DCloud_uniCloud_WYQ
回复 8***@qq.com:
引入云函本身,想分批发送。也会报错 https://api.next.bspapp.com/server 504或者-1报错
这个能私聊发我一下服务空间id、云函数名、requestId和日志内容吗2023-08-11 11:17
姜同学 (作者)
回复 DCloud_uniCloud_WYQ: 你好发过去了,辛苦了
2023-08-11 20:22