Examples of QR codes with parameters and Wechat parameter instances developed by WeChat

Source: Internet
Author: User

Develop and generate instances with two-dimensional codes and parameter instances

How to generate a QR code with Parameters

In the "Account Management" area of the public account platform developer, a function is to "generate a QR code with Parameters". After scanning the QR code, events are automatically pushed to the public account.

The data pushed to the developer's website through a scan is as follows:

<xml><ToUserName><![CDATA[gh_452****b0f2]]></ToUserName><FromUserName><![CDATA[oz1fVs4d****7FmFrCbc57o]]></FromUserName><CreateTime>1429416610</CreateTime><MsgType><![CDATA[event]]></MsgType><Event><![CDATA[SCAN]]></Event><EventKey><![CDATA[155120hzw]]></EventKey><Ticket><![CDATA[gQH17zoAAAAAAAAAASxodHR****S9xL28waUNrM1BsV1ZJZ0VJcE8tbUFMAAIEcCozVQMEAAAAAA==]]></Ticket></xml>

It can be seen that the data is in xmlstk format. SCAN in Event indicates scanning. EventKey indicates the value set in json when the QR code is generated, and EventKey can be specified by itself, others are determined by the platform... You can automatically reply to specified data by customizing EventKey data.

For example, I want to play a game with a riddle. Each riddle has a unique ID, which can be set to the EventKey value. When someone else scans the QR code with parameters, will pass the Riddle number (EventKey), and then automatically reply the answer to the user according to the number .... That is to say, scan to find out the answer.

More application scenarios can be used freely, such as scanning and receiving red packets.

Official development documentation:

To meet the needs of user channel promotion analysis, the public platform provides an interface for generating a QR code with parameters. You can use this interface to obtain multiple QR codes with different scenario values. After a user scans, the public account can receive event push.

Currently, there are two types of QR codes: temporary and permanent. The former has an expiration time, up to 1800 seconds, but can generate a large number. The latter has no expiration time, the number is small (currently only 1-parameters are supported ). The two QR codes are applicable to account binding, user source statistics, and other scenarios.

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 public account, the user can follow the public account, after which the event with the scene value will be pushed to the developer.
If the user has followed the public account, the user will automatically enter the session after scanning, and the event with the scene value will be pushed to the developer.
The process of obtaining a QR code with parameters involves two steps. First, create a two-dimensional code ticket, and then exchange the two-dimensional code with the specified URL ticket.

The meaning of the word "ticket" I checked the Baidu dictionary to show the meaning of "tickets, admission tickets", that is, the two-dimensional code is exchanged through admission tickets.

In exchange, the ticket is actually added to the end of the URL, that is, xxxx.com/xxx.php? Ticket = xxxx format

The actual results are as follows:

Here, ticket = xxx is followed by the obtained ticket value.

The official documentation is as follows:

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

The maximum value of scene_id is 0.1 million. The request method is post. The requested URLs are the same.

POST Data Format: json
Example of POST data: {"expire_seconds": 1800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": 123 }}}

Expire_seconds indicates the number of seconds after expiration. If this parameter is included, it indicates a temporary QR code, that is, it expires three minutes later.

Permanent QR code request example:


POST Data Format: json
Example of POST data: {"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": 123 }}}
Alternatively, you can use the following POST data to create string-type QR code parameters:
{"Action_name": "QR_LIMIT_STR_SCENE", "action_info": {"scene": {"scene_str": "123 "}}}

Note that in the scene_str table, the EventKey value in the pushed data is a string. The string must be enclosed in double quotation marks and can contain English characters.

If the maximum permanent QR code value of scene_id is 0.1 million, it can only be a number. Do not add double quotation marks.

Also, the request is post, and the data format is json.

Parameter description

Parameters Description
Expire_seconds The valid time of the QR code, in seconds. The maximum value is 1800.
Action_name QR code type. The value of QR_SCENE is temporary, the value of QR_LIMIT_SCENE is permanent, and the value of QR_LIMIT_STR_SCENE is permanent.
Action_info QR code details
Scene_id Scenario value ID. The value of the temporary QR code is 32-bit non-0 Integer type, and the maximum value of the permanent QR code is 100000 (currently, the parameter only supports 1--100000)
Scene_str Scenario value ID (string type ID), string type, length limit: 1 to 64, only permanent QR code supports this field

Return description

Correct Json return results:

{"Ticket": "Expiration =", "expire_seconds": 60, "url": "http: \/weixin.qq.com \/q \/kZgfwMTm72WWPkovabbI "}

Parameters Description
Ticket The obtained two-dimensional code ticket, with which the two-dimensional code can be exchanged within the validity period.
Expire_seconds The valid time of the QR code, in seconds. The maximum value is 1800.
Url The address after the QR code image is parsed. The developer can generate the desired QR code Image Based on the address.

Example of returned error Json:

{& Quot; errcode & quot;: 40013, & quot; errmsg & quot;: & quot; invalid appid & quot "}

Exchange two-dimensional codes with ticket

After obtaining the QR code ticket, the developer can exchange the ticket for the QR code image. Note that this interface can be called without logon.

Reminder: TICKET remembers to perform UrlEncode

Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.