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.
When a user scans a two-D code with scene values, the following two events may be pushed:
(1) If the user has not paid attention to the public number, then the user can pay attention to the public number, attention will be sent with the scene value attention events to the developer.
(2) If the user has been concerned about the public number, the user will automatically enter the session after the scan, also will take the scene value scan event to the developer.
The process of obtaining a QR code with parameters consists of two steps: (I) first creating the QR code ticket; (II) then exchanging the QR code with ticket to the specified URL.
(I) first create QR code ticket
Each time you create a QR code ticket you need to provide a developer's own set of parameters (SCENE_ID).
/** * First create a QR code ticket * @param string $sceneid scene value ID * generate temporary QR code when string $type value is ' temp ' * @param string $expir e_seconds QR code Expiration Time * @return string QR code ticket */public function _getticket ($sceneid, $type = ' temp ', $expire _ seconds=604800) {if ($type = = ' temp ') {$data = ' {"Expire_seconds":%s, "Action_name": "Qr_scene", "Action_info": {"SCENE": {"scene_id":%s}} '; $data = sprintf ($data, $expire _seconds, $sceneid);} else{$data = ' {"Action_name": "Qr_limit_scene", "Action_info": {"SCENE": {"scene_id":%s}} '; $data = sprintf ($data, $ Sceneid);} $curl = ' https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token= '. $this->_getaccesstoken (); $content = $ This->_request ($curl, True, ' POST ', $data); $cont = Json_decode ($content); return $cont->ticket;}
(ii) then exchange the QR code with ticket to the specified URL
After obtaining the QR code ticket, the developer can exchange ticket for QR code images. Note that this interface can be called without logging in.
Then with ticket to the specified URL in exchange for the QR Code public Function _getqrcode ($sceneid, $type = ' temp ', $expire _seconds=604800) {$ticket = $this- >_getticket ($sceneid, $type, $expire _seconds); $curl = ' https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket= '. UrlEncode ($ticket); $content = $this->_request ($curl); return $content;}
Call Output:
Header (' Content-type:image.jpeg '); $result = $wechat->_getqrcode (+); echo $result;
The browser can directly output two-dimensional code, is a picture, can be directly displayed or downloaded.