In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to write a Wechat development to generate a QR code with parameters". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Now please follow the editor's ideas slowly and deeply. Let's study and learn how to develop and generate a QR code with parameters on Wechat.
In the official Wechat platform developers, in the "account management", there is a function to "generate a QR code with parameters". The QR code generated here will automatically push the event to the official account of Wechat as long as it is scanned by Wechat.
Scan the data with Wechat and push it to the developer's website as follows:
1429416610
You can see that it is a data in xmlstk format. SCAN in Event means scanning, EventKey is the value set in json when generating QR code, EventKey can be specified by itself, and the rest are defined internally by Wechat platform. By customizing the EventKey data, you can automatically reply to the specified data.
For example: I want to do a puzzle game, each puzzle has a unique number, this number can be set to the EventKey value, and then when others scan the QR code with parameters, they will pass the riddle number (EventKey), and then automatically reply the answer to the user according to the number. That is, take out a Wechat and scan it and you will know the answer.
For more application scenarios, please feel free to play, such as: scan, receive red packets and other functions can also be achieved.
Official development document of Wechat:
In order to meet the needs of user channel promotion and analysis, the public platform provides an interface for generating QR codes with parameters. Using this interface, multiple QR codes with different scene values can be obtained. After scanning, the official account can receive the event push.
At present, there are two types of QR codes, namely temporary QR codes and permanent QR codes. The former has an expiration time of up to 1800 seconds, but can generate a large number of QR codes, while the latter has no expiration time and has a small number of QR codes. (currently, the parameters only support 1Mel 100000). The two QR codes are suitable for scenarios such as account binding and user source statistics, respectively.
When a user scans a QR code with scene values, the following two events may be pushed:
If the user has not followed the official account, the user can follow the official account. After following, Wechat will push the event with scene value to the developer.
If the user has followed the official account, the user will automatically enter the session after scanning, and Wechat will also push the scanning event with scene value to the developer.
The process of obtaining the QR code with parameters consists of two steps, first creating the QR code ticket, and then exchanging the QR code from ticket to the specified URL.
I looked up the meaning of the word ticket in Baidu Dictionary to show the meaning of "ticket, admission ticket", that is, to exchange the ticket for a QR code.
When you exchange it, you actually add ticket to the end of URL, that is, the form of xxxx.com/xxx.php?ticket=xxxx.
The real effect is as follows:
What follows the ticket=xxx is the obtained ticket value.
The official documents of Wechat are as follows:
Each time you create a QR code ticket, you need to provide a parameter (scene_id) set by the developer. The process of creating a temporary QR code and a permanent QR code ticket is introduced respectively.
The maximum value of scene_id is 100000, the method of request is post, and the requested URL is the same.
POST data format: json
Examples of POST data: {"expire_seconds": 1800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": 123}
Expire_seconds indicates the number of seconds to expire, and if this parameter is included, it represents a temporary QR code, that is, it expires after 3 minutes.
Example of a request for a permanent QR code:
POST data format: json
Example of POST data: {"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": 123}
Alternatively, you can use the following POST data to create QR code parameters in the form of strings:
{"action_name": "QR_LIMIT_STR_SCENE", "action_info": {"scene": {"scene_str": "123"}
Note here that the scene_str table asks for a string, that is, the value of EventKey in the pushed data is a string, the string should be enclosed in double quotes, and English characters can be sent.
If the maximum value of scene_id permanent QR code is 100000, it can only be a number. Do not add double quotation marks.
The request is post, and the data format is json.
Parameter description
The parameter indicates the validity time of the QR code in seconds for expire_seconds. The maximum does not exceed 1800. Action_name QR code type, QR_SCENE is temporary, QR_LIMIT_SCENE is permanent, QR_LIMIT_STR_SCENE is permanent string parameter value action_info QR code details scene_id scene value ID, 32-bit non-0 integer for temporary QR code, maximum value for permanent QR code is 100000 (current parameter only supports 1Mutel 100000) scene_str scene value ID (ID in string form), string type, length is limited to 1 to 64 This field is only supported by permanent QR codes.
Return description
The correct Json returns the result:
{"ticket": "gQH47joAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL2taZ2Z3TVRtNzJXV1Brb3ZhYmJJAAIEZ23sUwMEmm3sUw==", "expire_seconds": 60, "url": "http:\ /\ / weixin.qq.com\ / Q\ / kZgfwMTm72WWPkovabbI"}
The parameter indicates the QR code ticket obtained by ticket, which can be exchanged for the QR code within a valid period of time with this ticket. The valid time of the expire_seconds QR code, in seconds. The maximum does not exceed 1800. Developers can generate the required QR code image based on the address of the parsed address of the url QR code image.
Example of an incorrect Json returned:
{"errcode": 40013, "errmsg": "invalid appid"}
Exchange for QR code through ticket
After obtaining the QR code ticket, developers can exchange ticket for QR code images. Please note that this API can be called without login status.
Reminder: TICKET remember to UrlEncode
Thank you for your reading. The above is the content of "how to write Wechat to develop and generate QR codes with parameters". After the study of this article, I believe you have a deeper understanding of how to write Wechat to develop and generate QR codes with parameters, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.