注:我的后端是用django写的,根据本方法一定能实现 第一步 先获取小程序订阅消息模板  注意:此处的模板与你注册小程序时填写的"服务类目"有关系  在模板上选择一个合适的
然后是小程序端的代码: 先上链接:官方文档  代码:
wx.requestSubscribeMessage({
tmplIds: ['此处填写模板ID'],
success(res){
console.log('OK')
}
})
此代码的会弹出一个提示窗,选择是否允许小程序发送通知
django端: 还是老规矩先上链接:服务端发送消息推送 
python后端代码:
appid = ''
secret = ''
url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret
res = requests.get(url).json()
token = res['access_token']
openid = request.POST.get('openid')
time = request.POST.get('time')
place = request.POST.get('place')
url = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token='+token
data = {
'touser': openid,
'template_id': '',
'data': {"thing1": {"value": ''}, "time2": {"value": time},"thing3": { "value": place } },
'access_token': token,
'page':'/pages/my/my',
"lang": "zh_CN"
}
res = requests.post(url=url,data=json.dumps(data)).json()
点击模板详情  严格按照给的参数写,如果是字符串一般是thing+顺序编号,时间一般是time+顺序编号
好了,就先到这吧,有疑问欢迎在向下方评论
|