WeChat generates QR code with parameters

In order to meet the needs of user channel promotion analysis and user account binding and other scenarios, 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 the user scans, the official account can receive event pushes.

There are currently 2 types of QR codes:

1. Temporary QR codes have an expiration time. The longest can be set to expire after 30 days (ie 2,592,000 seconds) after the QR code is generated, but a larger number can be generated. Temporary QR codes are mainly used in business scenarios such as account binding that do not require permanent QR codes to be stored

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 a user scans a QR code with a 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. After following the account, WeChat will push the following events with scene values ​​to the developer.

If the user has followed the official account, it will automatically enter the session after the user scans, and WeChat will also push the scan 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 go to the specified URL to exchange for the QR code.

Create a QR code ticket

Each time you create a QR code ticket, you need to provide a parameter (scene_id) set by the developer, and introduce the process of creating a QR code ticket for a temporary QR code and a permanent QR code.

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 you can also use the following POST data to create a QR code parameter as a string:
{"action_name": "QR_LIMIT_STR_SCENE", "action_info": {"scene": {"scene_str": "123"}}}


Back to Instructions


The correct Json returns the result:

{"ticket":"gQH47joAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL2taZ2Z3TVRtNzJXV1Brb3ZhYmJJAAIEZ23sUwMEmm

3sUw==","expire_seconds":60,"url":"http:\/\/weixin.qq.com\/q\/kZgfwMTm72WWPkovabbI"}


Exchange QR code with 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 being logged in.

Request Instructions

HTTP GET request (please use https protocol) https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=TICKET Reminder: TICKET remember to perform UrlEncode

Back to Instructions

If the ticket is correct, the http return code is 200, which is an image that can be displayed or downloaded directly.

HTTP头(示例)如下:
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




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325571678&siteId=291194637