Generate QR code with parameters
Generate QR code with parameters
In order to meet the needs of scenarios such as user channel promotion analysis and user account binding, the public platform provides the ability to generate two-dimensional parameters with parameters. code interface. Using this interface, multiple QR codes with different scene values can be obtained. After the user scans them, the public account can receive event push.
There are currently 2 types of QR codes:
1. Temporary QR code has an expiration time, and can be set to a maximum of 30 days after the QR code is generated ( That is, it will expire after 2,592,000 seconds), but it can generate larger quantities. Temporary QR codes are mainly used in business scenarios such as account binding that do not require permanent storage of QR codes.
2. Permanent QR codes have no expiration time, but the number is small (currently up to 100,000). Permanent QR codes are mainly used in scenarios such as account binding and user source statistics.
When the user scans the QR code with scene value, the following two events may be pushed:
If the user has not followed the official account, the user can follow the official account and follow it on WeChat Attention events with scene values will be pushed to developers.
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 a QR code with parameters includes two steps. First, create a QR code ticket, and then use the ticket to the specified URL to exchange for the QR code.
Create QR code ticket
Every time you create a QR code ticket, you need to provide a parameter (scene_id) set by the developer, and introduce the temporary QR code separately. and the process of creating a permanent QR code ticket.
Temporary QR code request instructions
http request method: POST
URL: https://api.weixin.qq.com/cgi -bin/qrcode/create?access_token=TOKENPOST data format: json
POST data example: {"expire_seconds": 604800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": 123}}}
Permanent QR code request instructions
http request method: POST
URL: https://api.weixin.qq.com/cgi-bin/ qrcode/create?access_token=TOKENPOST data format: json
POST data example: {"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": 123}}}
Or also 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"}}}
Parameter description
Parameter | Description |
---|---|
expire_seconds | The validity time of this QR code is measured in seconds. The maximum value cannot exceed 2592000 (that is, 30 days). If this field is not filled in, the default validity period is 30 seconds. |
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, which is a 32-bit non-0 integer when the temporary QR code is used. The maximum value for permanent QR code is 100000 (currently the parameter only supports 1--100000) |
scene_str | Scene value ID (ID in string form), character String type, the length is limited to 1 to 64, only permanent QR codes support this field |
Return instructions
Correct Json return result:
{"ticket":"gQH47joAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL2taZ2Z3TVRtNzJXV1Brb3ZhYmJJAAIEZ23sUwMEmm
3sUw = =","expire_seconds":60,"url":"http:\/\/weixin.qq.com\/q\/kZgfwMTm72WWPkovabbI"}
Parameter | Description |
---|---|
ticket | obtained QR code ticket, with which you can exchange for QR code within the valid time. |
expire_seconds | The validity time of this QR code, in seconds. The maximum value does not exceed 2,592,000 (i.e. 30 days). |
url | The address after parsing the QR code image. Developers can generate the required QR code image based on this address |
Exchange QR code through ticket
After obtaining the QR code ticket, the developer can exchange the ticket for the QR code image. Please note that this interface can be called without logging in.
Request description
HTTP GET request (please use https protocol) https://mp.weixin.qq.com/cgi-bin/showqrcode? ticket=TICKET Reminder: TICKET remember to perform UrlEncode
Return instructions
ticket In the correct case, the http return code is 200, which is a picture that can be displayed or downloaded directly .
HTTP header (example) is as follows:
Accept-Ranges:bytes
Cache-control:max-age=604800
Connection:keep-alive
Content-Length :28026
Content-Type:image/jpg
Date:Wed, 16 Oct 2013 06:37:10 GMT
Expires:Wed, 23 Oct 2013 14:37:10 0800
Server:nginx /1.4.1
In case of error (such as illegal ticket), HTTP error code 404 is returned.