Php development-generate two-dimensional codes with parameters in batches. php batch Parameters
The two-dimensional code with parameters is very useful for channel marketing and promotion. Multiple two-dimensional codes with different scenario values can be obtained. After a user scans the QR code, the public number can receive event push, the good news is that we have activated this interface. Let's take a look at it.
For details about the interface, see the public platform developer documentation (http://mp.weixin.qq.com/wiki/18/28fc21e7ed87bec960651f0ce873ef8a.html), I am here on the Code directly.
Demo diagram:
Due to the limited generation of QR codes with parameters, all codes are generated by serial numbers and will be accumulated at the next generation.
In addition, remarks are provided to facilitate future statistics.
Public function createewm () {if (IS_POST) {$ access_token = checkAccessToken ($ this-> token); // get access_token $ json_url = 'https: // token? Access_token = '. $ access_token; $ action_name = $ this-> _ post ('Action _ name'); // generated type (temporary and permanent) $ create_num = $ this-> _ post ('create _ num'); // generated quantity // the last generation ID in the database query $ now_secne_id = M ('erweima ') -> where (array ('Token' => $ this-> token)-> order ('Scene _ id desc ')-> getField ('Scene _ id '); // Add 1 $ start_secne_id = intval ($ now_secne_id) + 1 to 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 ') {// json data of temporary post $ curl_data = '{"expire_seconds": 1800, "action_name": "QR_SCENE", "action_info": {"scene ": {"scene_id ":'. $ I. '}}}';} if ($ action_name = 'qr _ LIMIT_SCENE') {// permanent post json data $ curl_data = '{"action_name": "QR_LIMIT_SCENE ", "action_info": {"scene": {"scene_id ":'. $ I. '}}}';} $ json_info = json_decode ($ this-> api_notice_in Crement ($ json_url, $ curl_data), true); // This indicates that the data is successfully generated. record the data so that it can be inserted into the database. It is convenient for future statistics to find if ($ json_info ['errcode']! = 40013) {$ data [$ n] ['Token'] = $ this-> token; $ data [$ n] ['tid'] = $ 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 ('added successfully');} 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 ) ; }
It's easy. It's basically enough. Just take it if you like it.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.