WeChat Public platform Development (83) generating a _php with parameter QR Code tutorial

Source: Internet
Author: User
Tags cdata ticket
This article describes how to use the advanced interface to develop the function of the parameter QR code on the public platform.

First, the scene two-dimensional code

In order to meet the needs of User channel promotion analysis, the public platform provides an interface to generate two-dimensional code with parameters. The interface can be used to obtain a number of two-dimensional code with different scene values, after the user scans, the public number can receive the event push.

There are currently 2 types of two-dimensional code, the temporary two-dimensional code and permanent Two-dimensional code, the former has an expiration time, the maximum is 1800 seconds, but can generate a large number, the latter no expiration time, the number is less (currently the parameter only supports 1--100000). Two kinds of QR codes are applicable to account binding, user source statistics and other scenarios respectively.

When a user scans a two-D code with scene values, the following two events may be pushed:

If the user has not yet paid attention to the public number, the user can focus on the public number, followed by the scene value attention event will be pushed to the developer.

If the user is already concerned about the public number, the user will automatically enter the session after scanning, and will also push the scene value scan event to the developer.

The process of obtaining a QR code with parameters consists of two steps, first creating the QR code ticket, and then exchanging the QR code with ticket to the specified URL.

Second, create two-dimensional code Ticket

Every time you create a QR code, ticket needs to provide a developer's own set of parameters (SCENE_ID), respectively, the temporary QR Code and permanent Two-dimensional code to create two-dimensional code ticket process.

Temporary QR Code request description

HTTP request URL

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

Post data format

< span="">< span="">< span="">     "Expire_seconds": 1800< span="">< span="">     "action_name": "Qr_scene"  < span="">   "Action_info  " "  Scene"< span="">  < span="">   < span=""> < span="">   < span="">  "scene_id": < span=""> 100000   < span=""> < span=""> < span="">< span=""> }

Return format:

< span="">"Ticket": "gqfk8doaaaaaaaaaasxodhrwoi8vd2vpeglulnfxlmnvbs9xl3kwexe0t3jscwy3utltc3zpmklvaaieg9juugmecacaaa==" "Expire_seconds" < span=""> : 1800< span="">

< span="">

HTTP request URL

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

Post data format

< span="">"Action_name": "Qr_limit_scene"< span="">"Action_info< span="">" "Scene"< span="">"Scene" _id ": 1000< span="">

< span="">

< span="">"Ticket": "gqhi8doaaaaaaaaaasxodhrwoi8vd2vpeglulnfxlmnvbs9xl0uwetnxni1sdla3rklyrnnkbufvaaieldnuugmeaaaaaa=="< span="">

< span="">

< span="">

Return result parameter description

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 (
                                                                                  
                                                                                      }      
                                                                                    
                                                                                  
                                                                             /span> 
                                                                         
                                                                         
                                                                    
                                                                   
                                                             
                                                        

Iii. Adoption of Ticket In exchange for two-dimensional code

After obtaining the QR code ticket, the developer can exchange ticket for QR code images. It can be called without a login state.

HTTPS GET Request Description (ticket required UrlEncode)

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

Ticket the correct case, the HTTP return code is 200, is a picture, can be directly displayed or downloaded.

The HTTP header example is as follows:

 "url": "Https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket= Gqhi8doaaaaaaaaaasxodhrwoi8vd2vpeglulnfxlmnvbs9xl0uwetnxni1sdla3rklyrnnkbufvaaieldnuugmeaaaaaa%3d%3d ",< span="">"Content_Type": "Image/jpg",  < span="">  "Http_code": $,  < span="">  "header_size": 162,  < span=""> "Request_size": 181,  < span="">  "FILETIME":-1,  < span="">  "Ssl_verify_result":  < span=""> "Redirect_count": 0,  < span="">  "total_time": 0.509,  < span="">  "Namelookup_time" : 0,  < span="">  "connect_time": 0.058,  < span="">  "pretransfer_time": 0.343,  < span=""> "Size_upload": 0,  < span="">  "size_download": 28497,  < span="">  "speed_download": 55986,  < span=""> "Speed_upload": 0,  < span="">  "download_content_length": 28497,  < span="">  " Upload_content_length ": 0,  < span="">  " starttransfer_time ": 0.481,  < span="">  " Redirect_time ": 0  < span="">  }

< span="">

https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket= Gqfk8doaaaaaaaaaasxodhrwoi8vd2vpeglulnfxlmnvbs9xl3kwexe0t3jscwy3utltc3zpmklvaaieg9juugmecacaaa%3d%3d

https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket= Gqhi8doaaaaaaaaaasxodhrwoi8vd2vpeglulnfxlmnvbs9xl0uwetnxni1sdla3rklyrnnkbufvaaieldnuugmeaaaaaa%3d%3d

Four, download QR code

After the two-dimensional code generation, you can right-click in the browser to save as a local picture, but if there are many two-dimensional code, it is more convenient to use the program to download.

We use curl to get all the information about the picture and save the picture 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
                                     
                                      < span $ch span>, curlopt_nobody, 0); 
                                       curl_setopt (, Curlopt_ssl_verifypeer, 
                                          
                                           , Curlopt_ssl_verifyhost, 
                                             
                                              , Curlopt_returntransfer, 1
                                               
                                                 = curl_exec ( 
                                                  
                                                    = curl_getinfo (
                                                      
                                                      
                                                       
                                                          ( (' body ' = span $package span>),  (' header ' = 
                                                              
                                                               
                                                       
                                                     
                                                  
                                               
                                             
                                          
                                      
                                   

< span="">

Five, scan with parameter QR code event

When a user scans a two-D code with scene values, the following two events may be pushed:

If the user has not yet paid attention to the public number, the user can focus on the public number, followed by the scene value attention event will be pushed to the developer.

If the user is already concerned about the public number, the scene value scan event is pushed to the developer.

1. When the user is not concerned, follow-up event push

1389684286      < Span event< span>
                        
                              
                             
                               " Span << span>   
                                 
                                 Span Span>       
                                    
                                     < /span>
                                              
                                     

< span="">

< span="">

2. Event push when the user is already concerned

1389684184      < Span event< span>
                        
                              
                             
                               " Span << span>   
                                 
                                 
                                
                                      
                                      
                                               
                                

< span="">

< span="">

Event code:

The following code determines the scanning of two-dimensional code with parameters

Event)    {case        "subscribe":            $CONTENTSTR = "Welcome attention";            if (Isset ($object->eventkey)) {                $contentStr = "Focus on the two-dimensional code scene". $object->eventkey;            }            break;        Case "Scan":            $contentStr = "Scan". $object->eventkey;            break;        Default: Break            ;           }    $RESULTSTR = $this->transmittext ($object, $contentStr);    return $RESULTSTR;}

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

Double Studio public Platform account attention method:
1. Contacts-Add Friends-Find public number-search "double Studio"
2. Contacts-Add Friends-Search number-enter "Pondbaystudio"
3. Use the QR code below to scan

http://www.bkjia.com/PHPjc/738500.html www.bkjia.com true http://www.bkjia.com/PHPjc/738500.html techarticle This article describes how to use the advanced interface to develop the function of the parameter QR code on the public platform. First, the scene two-dimensional code in order to meet the user channel promotion analysis needs, the public flat ...

  • 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.