微信开发之Php批量生成带参数的二维码
带 参数 的二维码对于渠道营销推广来说是很有用的,可以获得多个带不同场景值的二维码,用户扫描后,公众号可以接收到事件推送,可喜的是微信开通了这个接口,那下面就来研究一下吧。 具体接口说明请参见,微信公众平台 开发 者文档(http://mp.weixin.qq.co
带参数的二维码对于渠道营销推广来说是很有用的,可以获得多个带不同场景值的二维码,用户扫描后,公众号可以接收到事件推送,可喜的是微信开通了这个接口,那下面就来研究一下吧。
具体接口说明请参见,微信公众平台开发者文档(http://mp.weixin.qq.com/wiki/18/28fc21e7ed87bec960651f0ce873ef8a.html),我这里就直接上代码。
演示图:
由于带参数二维码生成是有限的,所有我是按编号生成的,下次生成的时候直接累加。
另外带设置有备注,方便以后统计。
<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><strong>生成</strong>类型(临时、永久)</span> <span> 7</span> <span>$create_num</span>=<span>$this</span>->_post('create_num'); <span>//</span><span><strong>生成</strong>数量 </span><span> 8</span> <span> 9</span> <span> //数据库里查询最后<strong>生成</strong>一个编号</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>新<strong>生成</strong>在最后一个编辑上加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>$end_secne_id;<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>这里代表<strong>生成</strong>成功,记录数据以便插入到数据库,方便以后统计查找</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>
很简单,基本够用了,喜欢就拿走

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











PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

The future of PHP will be achieved by adapting to new technology trends and introducing innovative features: 1) Adapting to cloud computing, containerization and microservice architectures, supporting Docker and Kubernetes; 2) introducing JIT compilers and enumeration types to improve performance and data processing efficiency; 3) Continuously optimize performance and promote best practices.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.
