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 access WeChat Mini Programs message service

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

Share

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

The knowledge points of this article "how to access WeChat Mini Programs message Service" are not quite understood by most people, so the editor summarizes the following contents for you. The content is detailed, the steps are clear, and it has a certain reference value. I hope you can gain something after reading this article. Let's take a look at this "how to access WeChat Mini Programs message Service" article.

Access Overview

To connect to WeChat Mini Programs's message service, developers need to follow the following steps:

1. Fill in the server configuration

2. Verify the validity of the server address

3. Realize the business logic according to the interface document

These three steps are described in detail below.

Step 1: fill in the server configuration

After logging in to WeChat Mini Programs's official website, on the "Settings-message Server" page of Mini Program's official website, the administrator scans the code to enable the message service, and fill in the server address (URL), Token and EncodingAESKey.

URL is the interface URL that developers use to receive Wechat messages and events. The Token can be entered by the developer as a signature (the Token is compared with the Token contained in the API URL to verify the security). EncodingAESKey is manually filled in or randomly generated by developers and will be used as the encryption and decryption key of the message body.

At the same time, developers can choose message encryption and decryption methods: plaintext mode, compatibility mode and security mode. You can choose the message data format: XML format or JSON format. The default state of encryption is plaintext format, while the default state of data format is XML format.

The mode selection and server configuration will take effect immediately after submission. Please fill in and choose carefully. Switching encryption methods and data formats requires configuring the relevant codes in advance.

Step 2: verify that the message is indeed from the Wechat server

After the developer submits the information, the Wechat server will send a GET request to the server address URL entered. The GET request takes parameters as shown in the table below:

The parameters describe the signature Wechat encryption signature. Signature combines the token parameters entered by the developer with the timestamp parameters and nonce parameters in the request. Timestamp timestamp nonce random number echostr random string

The developer verifies the request by verifying the signature (there is a verification method below). If you confirm that the GET request is from Wechat server and return the echostr parameter content as is, the connection will take effect and become a successful developer, otherwise the connection will fail. The encryption / verification process is as follows: 1. Sort the three parameters token, timestamp and nonce in lexicographic order; 2. Concatenate the three parameter strings into a string for sha1 encryption; 3. The developer can compare the encrypted string with signature to identify that the request originated from Wechat

Verify the PHP sample code for signature:

Private function checkSignature () {$signature = $_ GET ["signature"]; $timestamp = $_ GET ["timestamp"]; $nonce = $_ GET ["nonce"]; $token = TOKEN; $tmpArr = array ($token, $timestamp, $nonce); sort ($tmpArr, SORT_STRING); $tmpStr = implode ($tmpArr); $tmpStr = sha1 ($tmpStr); if ($tmpStr = = $signature) {return true;} else {return false;}

Step 3: implement the business logic according to the interface document

After verifying the validity of URL, the connection takes effect and becomes a developer. At this point, when a user sends a message to Mini Program customer service or enters a session, the server configuration URL entered by the developer will get the messages and events pushed from the Wechat server, and the developer can respond according to his own business logic.

Please also note that the URL filled in by the developer must start with http:// or https:// and support port 80 and port 443, respectively.

The above is the content of this article on "how to access WeChat Mini Programs message Service". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

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