In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "how to achieve the subscription message function of WeChat Mini Programs". The editor shows you the operation process through an actual case, and the operation method is simple, fast and practical. I hope this article "how to achieve subscription message function by WeChat Mini Programs" can help you solve the problem.
Mini Program template messages are about to be discarded, so there is a new interface wx.requestSubscribeMessage
Subscribe to message documents
Steps:
1. Get the user's openid and access_token
2. Get the template ID
3. Obtain the distribution permission (api)
4. Send subscription message (api)
Template id
Mini Program Code:
Obtain the permission to issue:
/ / login.jsrequestMsg () {return new Promise ((resolve, reject) = > {wx.requestSubscribeMessage ({tmplIds: ["MUtLwsw0xCndRULTgNHiXwGDyHJ-ZwAFL-b3kALcl0c"], success: (res) = > {if (res ['MUtLwsw0xCndRULTgNHiXwGDyHJ-ZwAFL-b3kALcl0c'] =' accept') {wx.showToast ({title: 'subscribe to OK') , duration: 1000, success (data) {/ / successful resolve ()}, fail (err) {/ / failed console.error (err) Reject ()}})} / / index.wxml occurrence subscription message / / index.js / / Click occurrence subscription sendMsg:function (e) {wx.request ({url: 'https://cff.mynatapp.cc/wxXcx/sendMessage', method:' POST', data: {}, header: {'content-type':' application/json' / / default}, success (res) {console.log (res)}
Nodejs (koa2) code:
Send a subscription message:
/ / index.jsconst router = require ('koa-router') () const request = require (' superagent') let AppID = 'xxxxx'let AppSecret =' xxxxx'let access_token = 'xxxxx'let openid =' xxxxx'// Click subscription message router.post ('/ wxXcx/sendMessage', async (ctx, next) = > {let requestData = {"touser": openid, "template_id": "MUtLwsw0xCndRULTgNHiXwGDyHJ-ZwAFL-b3kALcl0c", "page": "index" "data": {"phrase1": {"value": "Wang Xiaoer"}, "date5": {"value": "15:01 on October 1st, 2019"}, "phrase4": {"value": "Miss Wang"}, "thing2": {"value": "ps introduction to mastery"} "character_string6": {"value": "1Pyro 10"} / / 2, send template message let res = await request .post (`Accept',. Send (requestData) .set ('Accept',' application/json') console.log (res) ctx.body = {code: '200, data: null Msg: 'operation succeeded'}})
This is the end of the content about "how to achieve the subscription message function of WeChat Mini Programs". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.