# Generate QR code with parameters

Debugging Tools

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:

  1. 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.
  2. 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:

  1. 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.
  2. 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 NametypeRequired to fill inIntroductions
access_tokenstringyesInterface invocation credentials, using access_token , authorizer_access_token

# Request BodyRequest Payload

Parameter NametypeRequired to fill inExampleIntroductions
expire_secondsnumberno604800QR code validity time (seconds), maximum 2592000, only temporary QR code required
action_namestringyesQR_SCENEType: QR_SCENE (temporary integer) / QR_STR_SCENE (temporary string) / QR_LIMIT_SCENE (permanent integer) / QR_LIMIT_STR_SCENE (permanent string)
action_infoobjectyes-QR code details

# Body.action_infoObject Payload

QR code details

Parameter NametypeRequired to fill inIntroductions
sceneobjectnoScenarios Information

# Body.action_info.sceneObject Payload

Scenarios Information

Parameter NametypeRequired to fill inExampleIntroductions
scene_idnumberno123Scene 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_strstringnotestScenario ID (ID in the form of a string), string type, length limited from 1 to 64

# 3. Return Parameters

# Response Payload

Parameter NametypeIntroductions
ticketstringObtain a two-dimensional code ticket, with which you can exchange the two-dimensional code within the valid time.
expire_secondsnumberThe QR code is valid for a period of seconds. The maximum does not exceed 2592000 (i.e. 30 days).
urlstringAfter 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:

  1. Temporary Binary Code is created by QR_SCENE / QR_STR_SCENE and needs to be set to expire_seconds
  2. 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 codeError DescriptionSolutions
-1system errorThe system is busy, so the developer is asked to try again in a few minutes.
0oksuccess
40001invalid credential  access_token isinvalid or not latestAppSecret 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
40052invalid action nameIncorrect action value
40053invalid 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.