本周开发了订阅消息功能,为了方便下一次使用,所以写在了这里。
主要的流程是,调用起小程序微信开放文档中的wx.requestSubscribeMessage,当他成功(accept)的时候,向后台发送要推送的消息,后台向微信服务起请求,这样就成功的发送订阅消息了,
我这里写的是支付成功之后调起推送消息
let tmpIds = [
"",
//这里写的是订阅消息的id,最多只能写3个
];
wx.requestSubscribeMessage ({
tmplIds: tmpIds,
success (res) {
console.log(res)
let acceptTmpList = [];
//for循环啊
for(var i=0;i<tmpIds.length;i++){
let tmpId = tmpIds[i];
if(res[tmpId] == "accept"){
//当它是res[tmpId] == "accept" 之后给后台发送消息
}else if(res[tmpId] == "reject"){
}
}
console.log(acceptTmpList)
}
})