Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use API to send text messages to Wechat users

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to use API to send text messages to Wechat users". In daily operation, I believe many people have doubts about how to use API to send text messages to Wechat users. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "how to use API to send text messages to Wechat users". Next, please follow the editor to study!

How to find the right Wechat message to send API? Or log in to Wechat developer Center, in the console menu "customer Service message"

Customer service interface-messaging is the API we need to use. Url is as follows: https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=

To use this API, we first need to get the access token that calls API:

The acquisition of Access token is simple, using Appid and secret to replace it.

Call another API, https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid= & secret=. This API returns access token and expiration time.

The appid and secret of your Wechat official account can be found in the console of Wechat developer Center under the tab of the "Test account Management" page.

Now after we get the access token, we can call Wechat text message send API to send text message to the specified Wechat users. Take a look at the invocation in the postman below. The test text message highlighted in red will be sent to my phone via Wechat API:

The test was successful:

Finally, we use the nodejs implementation to send a text message to the specified user through API.

Function sendWCMeaasge (toUser,sMessage) {var options = {url: "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + config.accessToken, method:" POST ", json:true, headers: {" content-type ":" application/json "}, body: {" touser ": toUser," msgtype ":" text " "text": {"content": sMessage} Request (options,function (error,response,data) {});} module.exports = sendWCMeaasge

Consumption Code:

SendMessage (, "this message is sent using nodejs!")

By executing the above code with the node name, you can also successfully receive the text message sent by calling the Wechat message API through the nodejs code on the Wechat app.

At this point, the study on "how to use API to send text messages to Wechat users" is over. I hope I can 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!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report