WeChat public platform development (83) generates a QR code with Parameters

Source: Internet
Author: User

This article describes how to use advanced interfaces on the public platform to develop the function of generating a QR code with parameters.

 

I. Scenario QR code

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.

 

2. Create a QR code Ticket

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.

Description of temporary QR code request

Http request URL

Https://api.weixin.qq.com/cgi-bin/qrcode/create? Access_token = TOKEN

POST Data Format

      "expire_seconds": 1800     "action_name": "QR_SCENE"     "action_info"         "scene"             "scene_id": 100000   }

Return format:

"ticket": "gQFK8DoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL3kweXE0T3JscWY3UTltc3ZPMklvAAIEG9jUUgMECAcAAA==""expire_seconds": 1800

Http request URL

Https://api.weixin.qq.com/cgi-bin/qrcode/create? Access_token = TOKEN

POST Data Format

"action_name": "QR_LIMIT_SCENE""action_info""scene""scene_id": 1000

"ticket": "gQHi8DoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL0UweTNxNi1sdlA3RklyRnNKbUFvAAIELdnUUgMEAAAAAA=="

Response parameters

Program Implementation

  = " xDx0pD_ZvXkHM3oeu5oGjDt1_9HxlA-9g0vtR6MZ-v4r7MpvZYC4ee4OxN97Lr4irkPKE94tzBUhpZG_OvqAC3D3XaWJIGIn0eeIZnfaofO1C3LNzGphd_rEv3pIimsW9lO-4FOw6D44T3sNsQ5yXQ"     = '{"expire_seconds": 1800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": 10000}}}'   = '{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": 1000}}}'    = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token="  = https_post(,  = json_decode(,   = ["ticket"    https_post(,  =       =     curl_setopt(, CURLOPT_URL,      curl_setopt(, CURLOPT_SSL_VERIFYPEER,      curl_setopt(, CURLOPT_SSL_VERIFYHOST,       (!(         curl_setopt(, CURLOPT_POST, 1         curl_setopt(, CURLOPT_POSTFIELDS,       curl_setopt(, CURLOPT_RETURNTRANSFER, 1      = curl_exec(     curl_close(       }

 

3. Pass Ticket In exchange for QR code

After obtaining the QR code ticket, the developer can exchange the ticket for the QR code image. You do not need to log on.

Https get request description (UrlEncode required for TICKET)

Https://mp.weixin.qq.com/cgi-bin/showqrcode? Ticket = TICKET

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

HTTP header example:

      "url": "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQHi8DoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL0UweTNxNi1sdlA3RklyRnNKbUFvAAIELdnUUgMEAAAAAA%3D%3D",     "content_type": "image/jpg",     "http_code": 200,     "header_size": 162,     "request_size": 181,     "filetime": -1,     "ssl_verify_result": 20,     "redirect_count": 0,     "total_time": 0.509,     "namelookup_time": 0,     "connect_time": 0.058,     "pretransfer_time": 0.343,     "size_upload": 0,     "size_download": 28497,     "speed_download": 55986,     "speed_upload": 0,     "download_content_length": 28497,     "upload_content_length": 0,     "starttransfer_time": 0.481,     "redirect_time": 0 }

Https://mp.weixin.qq.com/cgi-bin/showqrcode? Ticket = Latest % 3d % 3d

Https://mp.weixin.qq.com/cgi-bin/showqrcode? Ticket = Latest % 3d % 3d

 

4. Download the QR code

After the QR code is generated, you can right-click the browser and save it as a local image. However, if there are many QR codes, it is easier to download them using a program.

We use CURL to retrieve all information about the image and save the image data as a file. A complete download code is as follows:

 = "gQHi8DoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL0UweTNxNi1sdlA3RklyRnNKbUFvAAIELdnUUgMEAAAAAA==" = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=".( = downloadImageFromWeiXin( = "qrcode.jpg" = (, 'w' ( !==  ( !== (, ["body"( downloadImageFromWeiXin( = curl_init(, CURLOPT_HEADER, 0, CURLOPT_NOBODY, 0);        curl_setopt(, CURLOPT_SSL_VERIFYPEER, , CURLOPT_SSL_VERIFYHOST, , CURLOPT_RETURNTRANSFER, 1 = curl_exec( = curl_getinfo( (('body' => ), ('header' => 

 

5. Scan QR code events with Parameters

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 event with the scene value will be pushed to the developer.

1. If you do not pay attention to it, push the following events

1389684286

2. Event push when the user is concerned

1389684184

Event code:

The following code identifies two scenarios for scanning a QR code with parameters:

 

 

 

========================================================== ======================================

Follow-up methods for fanwe public platform accounts:
1. Address Book-Add friends-search for Public Accounts-search for "fangtimes Studio"
2. Address Book-add friend-search number-Enter "pondbaystudio"
3. Scan the following QR code

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.