Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize WeChat Mini Programs's Service Notification function

Shulou Source: shulou.com Published: 2022-06-01 05:37:50 10月28日 Update

This article mainly introduces "how to realize the WeChat Mini Programs service notification function". In the daily operation, I believe many people have doubts about how to realize the WeChat Mini Programs service notification function. The editor consulted all kinds of materials and sorted out the simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to realize the WeChat Mini Programs service notification function". Next, please follow the editor to study!

The following goes directly to the code:

Wxml:

Submit

Js:

/ / pages/index/index.js

Page ({

Data: {

}

/ *

Wechat public platform tests connection to https://mp.weixin.qq.com/debug/

Global error code description: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433747234

, /

OnLoad: function (options) {

Var that = this

Wx.login ({

Success: function (data) {

Console.log (data.code, data)

/ / obtain openid

Wx.request ({

Url: 'https://api.weixin.qq.com/sns/jscode2session?appid= your own appid&secret=, your own session_key&js_code=' + data.code

Header: {"Content-Type": "application/x-www-form-urlencoded"}

Method: "post"

Success: function (res) {

Console.log (res, "opind")

That.setData ({

Openid: res.data.openid

Session_key: res.data.session_key

})

}

})

}

})

/ / obtain access_token

Wx.request ({

Url: 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid= your own appid&secret=, your own session_key'

Method: "GET"

Success: function (res) {

Console.log (res, "res")

Console.log (res.data.access_token, "access_token")

That.setData ({

Access_token: res.data.access_token

})

}

})

}

/ / Click the execution method

Form: function (e) {

Var that = this

Var fId = e.detail.formId

/ / Network request

Var l = 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=' + that.data.access_token

/ / parameters to be passed

Var d = {

Touser: that.data.openid, / / user's openid

Template_id: 'XX1hceIwI1XiQaUc5Z4qIrZnYQkYEHElSq5m6yIa0M8',// this is the template message id for the application. The location is added and obtained in the Wechat public platform / template message.

Page:'/ pages/index/index', / / Click the page to notify the jump

Form_id: formId for submit event in the scenario of fId, / / form submission

/ / this must be data. Only people can say that value is OK. The bug may have been repaired by the authorities.

Data: {

"keyword1": {

"value": "Hotel

"color": "# 4a4a4a"

}

"keyword2": {

"value": "2018-03-22"

"color": "# 9b9b9b"

}

"keyword3": {

"value": "$300"

"color": "# 9b9b9b"

}

"keyword4": {

"value": "China"

"color": "# 9b9b9b"

}

}

Color:'# ccc'

Emphasis_keyword: 'keyword1.DATA'

}

Wx.request ({

Url: l

Data: d

Method: 'POST', / / No request headers are allowed here

Success: function (res) {

Console.log (res, "push msg")

}

Fail: function (err) {

Console.log (err, "push err")

}

});

}

})

Finally, click submit to initiate the request. Here you can only debug the phone. The formId I printed out with the development tool: "the formId is a mock one" is not a number string. Real machine testing is required to succeed here

At this point, the study on "how to realize the WeChat Mini Programs service notification function" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Functions programs services learning public platforms methods more templates messages help testing utility success next events code location global parameters Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Apple Redmi OPPO Reno Shulou Technology