微信小程序发送订阅消息sendMessage

微信小程序发送订阅消息sendMessage

请注意订阅消息一次性订阅只只能授权一次接受一条消息多次授权会累加接受次数,wx.requestSubscribeMessage调用授权
目前长期性订阅消息仅向政务民生、医疗、交通、金融、教育等线下公共服务开放

//授权弹框,只弹出第一次第二次不会弹出但是会授权
wx.requestSubscribeMessage({
tmplIds: ['iBTBe39PnfprwrwIIMyo2tT8QYzgCGhKhcZDdO-VZzOeGEI','iBTBe39PrrwwnfpIIMyo2tT8QTnlf3qs2ajNtXPCt6v4UBE','nhAXEn2w537ZPnHTI5ZVOtrrru0B-Jpbu8zo1D37aIWBIM'], //模板id最多添加三条
		 success (res) {
										 console.log(res)
					// uni.showModal({
					// 	content:'已开启(可接收三次消息通知)再次接收需重新点击该按钮',
					// 	showCancel:false
					// })
					console.log('-------------------------------')
					
				},
				fail(err) {
					console.log('errr--------------------------')
					console.log(err)
					
					console.log('errr--------------------------')
				}
})

https://developers.weixin.qq.com/apiExplorer?apiName=sendMessage&plat=miniprogram 微信开放平台调试工具调试会有bug,模板data不支持object必须为字符串但是字符串会报错参数错误,所以要用postman调试
在这里插入图片描述

在这里插入图片描述

第一步获取accesstoken,https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=小程序的appid&secret=小程序的secret

第二部发送订阅消息,https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=获取到的access_token

{
“template_id”: “模板id”,
“page”: “跳转的页面”,
“touser”: “用户appid”,
“data”: {“character_string10”:{“value”:“2024-05-13 11:19:14”},“thing18”:{“value”:“0.02”},“thing3”:{“value”:“1789857908847017984”},“thing8”:{“value”:“无”},“thing16”:{“value”:“无”}},
“miniprogram_state”: “developer”,
“lang”: “zh_CN”
}
在这里插入图片描述

在这里插入图片描述

解决问题中搜索的资料:
https://developers.weixin.qq.com/apiExplorer?apiName=sendMessage&plat=miniprogram

https://mp.weixin.qq.com/wxamp/newtmpl/tmpldetail?type=2&pri_tmpl_id=nhAXEn2w537ZPnHTI5ZVOtu0B-Jpbu8zo1D37aIWBIM&flag=undefined&token=2086707732&lang=zh_CN

https://developers.weixin.qq.com/community/search?query=sendMessage&page=1&block=1&random=1715571518198&type=1

https://developers.weixin.qq.com/community/develop/doc/000a46182a04688e1700ad73a61400?highLine=sendMessage

https://developers.weixin.qq.com/community/develop/doc/000ac6e251825076d09f7c79251000?highLine=sendMessage

  • 10
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

秋叶原的琴音

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值