Generating QR Codes
Back

From WeChat Official Account Admin Platform
Jump to: navigation, search

A QR Code with scene value can be obtained via this QR Code with Parameters API. The official account can receive a pushed event when the user scans this type of QR Code.

There are two types of QR Codes: temporary and permanent. Temporary QR Codes expire after 30 days(2,592,000 seconds) and can be batch generated. There are less permanent codes available to developers but they do not expire; currently up to 100,000 can be generated. Temporary QR Codes are used for linking accounts and permanent QR codes are used for user statistics.

WeChat pushes the following events when a user scans a QR Code with the scene value: 1. Non-followers can follow an official account and then WeChat pushes the followed event with the scene value to the developer. 2. Followers can enter a chat automatically after scanning the corresponding QR Code, and WeChat pushes this scanning event with the scene value to the developer.

To generate a QR Code with parameters, developers need to create a QR Code ticket and then exchange it for a QR Code for the URL specified by the ticket.

Create QR Code Ticket

To create a QR Code ticket, the developer should provide a parameter (scene_id) that they have set.

Temporary QR Code Request Description

HTTP request method: POST
URL: https://api.wechat.com/cgi-bin/qrcode/create?access_token=TOKEN
POST data format: JSON
POST example :{"expire_seconds": 1800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": 123}}}

Permanent QR Code Request Description

HTTP request method: POST
URL: https://api.wechat.com/cgi-bin/qrcode/create?access_token=TOKEN
POST data format: JSON
POST example :{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": 123}}}
Or use the following POST data to create a string-type QR code parameter:
{"action_name": "QR_LIMIT_STR_SCENE", "action_info": {"scene": {"scene_str": "123"}}}

Parameter Description

Parameter Description
expire_seconds QR Code validity time (up to 1,800 seconds)
action_name QR Code type, Temporary: QR_SCENE; Permanent: QR_LIMIT_SCENE
action_info QR Code details
scene_id Scene value, Temporary: 32 bits (integer); Permanent: no more than 1,000
scene_str Scene value; format: string; length: Up to 64 characters

Return Description

An example of a successful JSON response is as follows:

{"ticket":"gQH47joAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL2taZ2Z3TVRtNzJXV1Brb3ZhYmJJAAIEZ23sUwMEmm3sUw==","expire_seconds":1800,"url":"http:\/\/weixin.qq.com\/q\/kZgfwMTm72WWPkovabbI"}
Parameter Description
ticket The obtained QR Code ticket used to exchange the QR Code within the valid period
expire_seconds QR Code validity time (up to 1,800 seconds)
url URL obtained after the QR code is scanned; based on this URL, developers can generate the required QR code

An example of an unsuccessful JSON response is as follows:

{"errcode":40013,"errmsg":"invalid appid"}

Return Codes

Exchange QR Code via Ticket

The developer can call this API without logging in.

Request Description

HTTP request method: GET (Use Https protocol)
https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=TICKET
Note:remember to UrlEncode TICKET

Return Description

The HTTP return code is 200 if the ticket is correct. Users can directly download or check the returned image. An example of an HTTP head is as follows:

Accept-Ranges: bytes
Cache-control: max-age=604800
Connection: keep-alive
Content-Length: 28026
Content-Type: mage/jpg
Date: Wed, 16 Oct 2013 06:37:10 GMT
Expires: Wed, 23 Oct 2013 14:37:10 +0800
Server: nginx/1.4.1

The HTTP error code is 404 if the ticket is incorrect, for example, if it is invalid.

Developer Guide
Custom-defined Menu
WeChat JS-SDK