PHP development of batch generation with parameters of the two-dimensional code, PHP batch Parameters
With the parameters of the two-dimensional code for the channel marketing is very useful, you can obtain a number of different scene values of the two-dimensional code, the user scan, the public can receive the event push, the welcome is the opening of this interface, the following to study it.
For a description of the interface, see the Public Platform Developer documentation (http://mp.weixin.qq.com/wiki/18/28fc21e7ed87bec960651f0ce873ef8a.html), I'll go directly to the code here.
Demo diagram:
Since the generation of parametric QR codes is limited, all of them are generated by number and are added directly to the next generation.
In addition, with the setting has notes, convenient for later statistics.
Public Function Createewm () {if (is_post) {$access _token=checkaccesstoken ($this->token);//Get Access_token $json _url= ' https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token= '. $access _token; $action _name= $this->_post (' action_name '); Build type (temporary, permanent) $create _num= $this->_post (' create_num '); Generate quantity//database query finally generate a number $now _secne_id=m (' Erweima ')->where (Array (' token ' = $this->token))->order (' s cene_id desc ')->getfield (' scene_id '); The new build adds 1 $start _secne_id=intval ($now _secne_id) +1 on the last edit; $end _secne_id=intval ($now _secne_id) +intval ($create _num); $n = 0; for ($i = $start _secne_id; $i <= $end _secne_id; $i + +) {$curl _data= '; if ($action _name== ' Qr_scene ') {//Temporary post JSON data $curl _data= ' {"expire_seconds": 1800, "Action_name": "QR _scene "," Action_info ": {" SCENE ": {" scene_id ": '. $i. '}} '; } if ($action _name== ' Qr_limit_scene ') {//JSON for permanent postData $curl _data= ' {"Action_name": "Qr_limit_scene", "Action_info": {"SCENE": {"scene_id": '. $i. '}} '; } $json _info=json_decode ($this->api_notice_increment ($json _url, $curl _data), true); This represents the success of the build, logging the data for insertion into the database, so that it is convenient for later statistics to find if ($json _info[' Errcode ']!=40013) {$data [$n] [' token ']= $this->token; $data [$n] [' Tiket ']= $json _info[' ticket ']; $data [$n] [' url ']= $json _info[' url ']; $data [$n] [' scene_id ']= $i; $data [$n] [' expire_seconds ']= $json _info[' expire_seconds ']; $data [$n] [' Action_name ']= $action _name; $data [$n] [' remark ']= '; $data [$n] [' Createtime ']=time (); $n + +; }else{$this->error (' operation failed '); }} if (count ($data) >0) {$res = M (' Erweima ')->addall ($data);//Insert Data if ($res) {$this ->success (' Add success '); }else{$this->error (' operation failed '); }}else{$this->error (' operation failed '); } } }
function Api_notice_increment ($url, $data) { $ch = Curl_init (); $header = "Accept-charset:utf-8"; curl_setopt ($ch, Curlopt_url, $url); curl_setopt ($ch, Curlopt_customrequest, "POST"); curl_setopt ($ch, Curlopt_ssl_verifypeer, FALSE); curl_setopt ($ch, Curlopt_ssl_verifyhost, FALSE); curl_setopt ($curl, Curlopt_httpheader, $header); curl_setopt ($ch, Curlopt_useragent, ' mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0) '); curl_setopt ($ch, curlopt_followlocation, 1); curl_setopt ($ch, Curlopt_autoreferer, 1); curl_setopt ($ch, Curlopt_postfields, $data); curl_setopt ($ch, Curlopt_returntransfer, true); $tmpInfo = curl_exec ($ch); if (Curl_errno ($ch)) { //curl_close ($ch) return $ch; } else{ //curl_close ($ch) return $tmpInfo; } Curl_close ($ch);
Very simple, basic enough, like to take away
The above is the whole content of this article, I hope that everyone's learning to help, but also hope that we support a lot of help the home.
http://www.bkjia.com/PHPjc/1138976.html www.bkjia.com true http://www.bkjia.com/PHPjc/1138976.html techarticle PHP Development of batch generation with parameters of the two-dimensional code, PHP batch parameters with parameters of the two-dimensional code for channel marketing is very useful, you can get a number of different scene values of two-dimensional ...