


WeChat development - Php batch generation of QR codes with parameters, php parameters_PHP tutorial
WeChat development - Php batch generates QR codes with parameters, php parameters
QR codes with parameters are very useful for channel marketing and promotion. Obtain multiple QR codes with different scene values. After the user scans them, the official account can receive event push. Fortunately, WeChat has opened this interface, so let’s study it below.
For specific interface description, please refer to the WeChat public platform developer documentation (http://mp.weixin.qq.com/wiki/18/28fc21e7ed87bec960651f0ce873ef8a.html). I will directly enter the code here.
Demo picture:
Since the generation of QR codes with parameters is limited, I generate them by number, and they will be accumulated directly the next time they are generated.
In addition, there are notes in the settings to facilitate future statistics.
<span> 1</span> <span>public</span> <span>function</span><span> createewm(){ </span><span> 2</span> <span>if</span><span>(IS_POST){ </span><span> 3</span> <span>$access_token</span>=checkAccessToken(<span>$this</span>->token); <span>//</span><span>获取access_token</span> <span> 4</span> <span>$json_url</span>='https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token='.<span>$access_token</span><span>; </span><span> 5</span> <span> 6</span> <span>$action_name</span>=<span>$this</span>->_post('action_name'); <span>//</span><span>生成类型(临时、永久)</span> <span> 7</span> <span>$create_num</span>=<span>$this</span>->_post('create_num'); <span>//</span><span>生成数量 </span><span> 8</span> <span> 9</span> <span> //数据库里查询最后生成一个编号</span> <span>10</span> <span>$now_secne_id</span>=M('erweima')->where(<span>array</span>('token'=><span>$this</span>->token))->order('scene_id desc')->getField('scene_id'<span>); </span><span>11</span> <span>12</span> <span>//</span><span>新生成在最后一个编辑上加1</span> <span>13</span> <span>$start_secne_id</span>=<span>intval</span>(<span>$now_secne_id</span>)+1<span>; </span><span>14</span> <span>$end_secne_id</span>=<span>intval</span>(<span>$now_secne_id</span>)+<span>intval</span>(<span>$create_num</span><span>); </span><span>15</span> <span>$n</span>=0<span>; </span><span>16</span> <span>for</span>(<span>$i</span>=<span>$start_secne_id</span>;<span>$i</span><=<span>$end_secne_id</span>;<span>$i</span>++<span>){ </span><span>17</span> <span>$curl_data</span>=''<span>; </span><span>18</span> <span>if</span>(<span>$action_name</span>=='QR_SCENE'<span>){ </span><span>19</span> <span>//</span><span>临时 post的json数据</span> <span>20</span> <span>$curl_data</span>='{"expire_seconds": 1800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": '.<span>$i</span>.'}}}'<span>; </span><span>21</span> <span> } </span><span>22</span> <span>23</span> <span>if</span>(<span>$action_name</span>=='QR_LIMIT_SCENE'<span>){ </span><span>24</span> <span>//</span><span>永久 post的json数据</span> <span>25</span> <span>$curl_data</span>='{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": '.<span>$i</span>.'}}}'<span>; </span><span>26</span> <span> } </span><span>27</span> <span>$json_info</span>=json_decode(<span>$this</span>->api_notice_increment(<span>$json_url</span>,<span>$curl_data</span>),<span>true</span><span>); </span><span>28</span> <span>29</span> <span>//</span><span>这里代表生成成功,记录数据以便插入到数据库,方便以后统计查找</span> <span>30</span> <span>if</span>(<span>$json_info</span>['errcode']!=40013<span>){ </span><span>31</span> <span>$data</span>[<span>$n</span>]['token']=<span>$this</span>-><span>token; </span><span>32</span> <span>$data</span>[<span>$n</span>]['tiket']=<span>$json_info</span>['ticket'<span>]; </span><span>33</span> <span>$data</span>[<span>$n</span>]['url']=<span>$json_info</span>['url'<span>]; </span><span>34</span> <span>$data</span>[<span>$n</span>]['scene_id']=<span>$i</span><span>; </span><span>35</span> <span>$data</span>[<span>$n</span>]['expire_seconds']=<span>$json_info</span>['expire_seconds'<span>]; </span><span>36</span> <span>$data</span>[<span>$n</span>]['action_name']=<span>$action_name</span><span>; </span><span>37</span> <span>$data</span>[<span>$n</span>]['remark']=''<span>; </span><span>38</span> <span>$data</span>[<span>$n</span>]['createtime']=<span>time</span><span>(); </span><span>39</span> <span>$n</span>++<span>; </span><span>40</span> }<span>else</span><span>{ </span><span>41</span> <span>$this</span>->error('操作失败'<span>); </span><span>42</span> <span> } </span><span>43</span> <span> } </span><span>44</span> <span>45</span> <span>if</span>(<span>count</span>(<span>$data</span>)>0<span>){ </span><span>46</span> <span>$res</span>= M('erweima')->addAll(<span>$data</span>);<span>//</span><span>插入数据</span> <span>47</span> <span>if</span>(<span>$res</span><span>){ </span><span>48</span> <span>$this</span>->success('添加成功'<span>); </span><span>49</span> }<span>else</span><span>{ </span><span>50</span> <span>$this</span>->error('操作失败'<span>); </span><span>51</span> <span> } </span><span>52</span> }<span>else</span><span>{ </span><span>53</span> <span>$this</span>->error('操作失败'<span>); </span><span>54</span> <span> } </span><span>55</span> <span> } </span><span>56</span> }
<span>function</span> api_notice_increment(<span>$url</span>, <span>$data</span><span>){ </span><span>$ch</span> =<span> curl_init(); </span><span>$header</span> = "Accept-Charset: utf-8"<span>; curl_setopt(</span><span>$ch</span>, CURLOPT_URL, <span>$url</span><span>); curl_setopt(</span><span>$ch</span>, CURLOPT_CUSTOMREQUEST, "POST"<span>); curl_setopt(</span><span>$ch</span>, CURLOPT_SSL_VERIFYPEER, <span>FALSE</span><span>); curl_setopt(</span><span>$ch</span>, CURLOPT_SSL_VERIFYHOST, <span>FALSE</span><span>); curl_setopt(</span><span>$curl</span>, CURLOPT_HTTPHEADER, <span>$header</span><span>); curl_setopt(</span><span>$ch</span>, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'<span>); curl_setopt(</span><span>$ch</span>, CURLOPT_FOLLOWLOCATION, 1<span>); curl_setopt(</span><span>$ch</span>, CURLOPT_AUTOREFERER, 1<span>); curl_setopt(</span><span>$ch</span>, CURLOPT_POSTFIELDS, <span>$data</span><span>); curl_setopt(</span><span>$ch</span>, CURLOPT_RETURNTRANSFER, <span>true</span><span>); </span><span>$tmpInfo</span> = curl_exec(<span>$ch</span><span>); </span><span>if</span> (curl_errno(<span>$ch</span><span>)) { </span><span>//</span><span>curl_close( $ch )</span> <span>return</span> <span>$ch</span><span>; }</span><span>else</span><span>{ </span><span>//</span><span>curl_close( $ch ) </span> <span>return</span> <span>$tmpInfo</span><span>; } curl_close( </span><span>$ch</span><span> ) ; }</span>
It’s very simple. It’s basically enough. Just take it if you like it

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics





1. Open the software and enter the wps text operation interface. 2. Find the insert option in this interface. 3. Click the Insert option and find the QR code option in its editing tool area. 4. Click the QR code option to pop up the QR code dialog box. 5. Select the text option on the left and enter our information in the text box. 6. On the right side, you can set the shape of the QR code and the color of the QR code.

How to use PHP to dynamically generate QR codes. QR codes (QRCode) are widely used in various fields. They can store a large amount of information and are easy to scan. In web applications, we often need to dynamically generate QR codes to provide users with convenient operations. This article will introduce how to use PHP to dynamically generate QR codes. 1. Install and configure the PHPQRCode library. In order to facilitate the generation of QR codes, we can use the PHPQRCode library. First, we need

Prerequisite: Enable QR code scanning on your iPhone The ability to scan QR codes is enabled by default on all iPhones running iOS 11. Therefore, you need to make sure your iPhone is updated to the latest available version, at least iOS11, to be able to scan QR codes natively. Before proceeding with any of the methods below, you must ensure that the feature is enabled on your iPhone. You can enable QR code scanning on your iPhone by opening the Settings app and tapping the Camera section. On the next screen, enable the "Scan QR code" toggle. This should turn on the feature so you can scan and extract from QR codes using any of the following methods

How to use PHP to generate batch QR codes? With the continuous development of Internet technology, QR codes have become a very common information transmission tool. QR codes can store a large amount of information and can be quickly scanned and recognized, so they have been widely used in various industries. In many cases, we need to generate a large number of QR codes in batches, such as for product labels, event tickets, etc. PHP is a scripting language widely used in web development and is flexible, simple and easy to use. Below, we will introduce how to use PHP to generate

How to generate QR code with time limit using PHP? With the popularity of mobile payments and electronic tickets, QR codes have become a common technology. In many scenarios, we may need to generate a QR code with a time limit, which will become invalid even after a certain period of time. This article will introduce how to use PHP to generate a time-limited QR code and provide code examples for reference. Installing the PHPQRCode library To use PHP to generate QR codes, we need to install the PHPQRCode library first. This library

What should I do if the QR code on Enterprise WeChat cannot be loaded? What should we do when we find that the QR code cannot be loaded and cannot be displayed when logging into the computer version of Enterprise WeChat? Here, the editor will give you a detailed introduction to the solution to the problem that the QR code of Enterprise WeChat cannot be loaded. Anyone who needs it Friends, come and take a look! Method 1. Network reasons 1. The network speed may be slow, resulting in slow loading and failure to display. You can disconnect and reconnect. 2. Check the computer's own network problems to see if it is connected to the network. You can restart the network device. Method 2: Maintenance and update: The QR code may not be generated because the version of Enterprise WeChat is too low. You can upgrade the software to the latest version. Method three, firewall 1

QR code is a widely used information encoding method in modern society. Vue is a front-end framework. How to use Vue to generate QR code? 1. Understand the principle of QR code generation. The principle of QR code generation is to convert a piece of text or a URL address into a picture, in which the information of the text or URL address is encoded. You can use third-party libraries to generate QR codes. This article introduces how to use the Qrcode.js library to generate QR codes. Qrcode.js is a lightweight, dependency-free QR code generation library. two

PHP coding tips: How to generate a QR code with anti-counterfeiting verification function? With the development of e-commerce and the Internet, QR codes are increasingly used in various industries. In the process of using QR codes, in order to ensure product safety and prevent counterfeiting, it is very important to add anti-counterfeiting verification functions to the QR codes. This article will introduce how to use PHP to generate a QR code with anti-counterfeiting verification function, and attach corresponding code examples. Before starting, we need to prepare the following necessary tools and libraries: PHPQRCode: PHP
