# Generate QR code with parameters
Interface should be called on the server side, not in the front end (Weixin Mini Program, web pages, APP, etc.) directly called, specific reference interface call guide
Interface English name: createQRCode
Create a binary code ticket for generating a binary code with parameters
There are currently 2 types of QR codes:
- Temporary QR codes have an expiration time, and the maximum can be set to expire after 30 days (i.e. 25,92,000 seconds) after the QR code is generated, but a large number can be generated. Temporary QR codes are mainly used in business scenarios such as account binding that do not require the QR codes to be permanently saved.
- Permanent QR codes, which have no expiration date, are small in number (currently a maximum of 100 thousand). The permanent QR code is mainly used for scenarios such as account binding, user source statistics and so on.
When a user scans a QR code with a scene value, the following two events may be pushed:
- If you haven't already followed Official Account, you can follow the Official Account message template, and WeChat will push the event with scene value to the developer.
- If the user is already following Official Account, the user will automatically enter the session after scanning, and WeChat will push the scene scan event to the developer.
# 1. How to call
# HTTPS calls
POST https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=ACCESS_TOKEN
# Cloud Calls
Call method: officialAccount.qrcode.create
The input and exit parameters are the same as the HTTPS call, which can be called in the cloud call documentation
# Third party invocation
This interface supports Third Party Platform generation business call.
The permission set id to which this interface belongs is: 3
When a service provider is authorized by one of the permissions set, it can call on behalf of the merchant by using authorizer_access_token , which can be viewed in the third-party call documentation.
# 2. Request parameters
# Query parametersQuery String parameters
Parameter Name | type | Required to fill in | Introductions |
---|---|---|---|
access_token | string | yes | Interface invocation credentials, using access_token , authorizer_access_token |
# Request BodyRequest Payload
Parameter Name | type | Required to fill in | Example | Introductions |
---|---|---|---|---|
expire_seconds | number | no | 604800 | QR code validity time (seconds), maximum 2592000, only temporary QR code required |
action_name | string | yes | QR_SCENE | Type: QR_SCENE (temporary integer) / QR_STR_SCENE (temporary string) / QR_LIMIT_SCENE (permanent integer) / QR_LIMIT_STR_SCENE (permanent string) |
action_info | object | yes | - | QR code details |
# Body.action_infoObject Payload
QR code details
Parameter Name | type | Required to fill in | Introductions |
---|---|---|---|
scene | object | no | Scenarios Information |
# Body.action_info.sceneObject Payload
Scenarios Information
Parameter Name | type | Required to fill in | Example | Introductions |
---|---|---|---|---|
scene_id | number | no | 123 | Scene value ID, temporary two-dimensional code for the 32-bit non-zero integer, permanent two-dimensional code for the maximum value of 100000 (the current parameters only support 1 - 100000) |
scene_str | string | no | test | Scenario ID (ID in the form of a string), string type, length limited from 1 to 64 |
# 3. Return Parameters
# Response Payload
Parameter Name | type | Introductions |
---|---|---|
ticket | string | Obtain a two-dimensional code ticket, with which you can exchange the two-dimensional code within the valid time. |
expire_seconds | number | The QR code is valid for a period of seconds. The maximum does not exceed 2592000 (i.e. 30 days). |
url | string | After the QR code image is resolved, the developer can generate the required QR code image according to that address |
# 4. Note
Two types of temporary and permanent QR codes are supported:
- Temporary Binary Code is created by QR_SCENE / QR_STR_SCENE and needs to be set to expire_seconds
- Permanent Binary Code created by QR_LIMIT_SCENE / QR_LIMIT_STR_SCENE
# In exchange for tickets.
After obtaining a two-code ticket, the developer can exchange the ticket for a two-code picture. Please note that this interface can be called without a login state.
GET https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=TICKET
Reminder: TICKET Remember to perform UrlEncode
Return content: ticket is correct, http return code is 200, is a picture, you can directly display or download.
The 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 an error (such as an invalid ticket), the HTTP error code 404 is returned.
# 5. Code examples
Example Requests
{
"expire_seconds": 604800,
"action_name": "QR_SCENE",
"action_info": {
"scene": {
"scene_id": 123
}
}
}
Return an example
{
"ticket": "gQH47joAAAAAAAAAASxodHRwOi8vd2VpeGlu...",
"expire_seconds": 60,
"url": "http://weixin.qq.com/q/kZgfwMTm72WWPkovabbI"
}
# 6. Error code
The following is a list of error codes for this interface, other error codes can refer to General error codes
Error code | Error Description | Solutions |
---|---|---|
-1 | system error | The system is busy, so the developer is asked to try again in a few minutes. |
0 | ok | success |
40001 | invalid credential access_token isinvalid or not latest | AppSecret error while getting access_token, or access_token is invalid.Developers should check that AppSecret is correct, or that they are calling interfaces for the appropriate Official Account |
40052 | invalid action name | Incorrect action value |
40053 | invalid action info please checkdocument |
# 7. Scope of application
This interface supports "Service Account (authentication only)" account type calls.None of the other account types can be invoked without special instructions.