Home > php教程 > php手册 > body text

(一)微信公众号开发基本配置,信公众开发基本配置

WBOY
Release: 2016-06-16 09:16:28
Original
1650 people have browsed it

(一)微信公众号开发基本配置,信公众开发基本配置

 

作为用代码进行微信开发者或要实现事件响应等功能,微信开发基本配置是必不可少的环节,本文大致梳理开发配置的流程。

 

1、登入微信公众平台:开发 ---> 基本配置

 

 

2、在基本配置页面有“服务器配置”,默认是未启用状态,需要我们先点击“修改配置”进行相关项目填写

 

3、填写以下项目内容

 

  •  URL:必须以http://开头,目前仅支持80端口,服务器地址必须是可访问的有效地址(注:用本文中URL举例,曾经看到一篇博文将URL地址填为http://tx.heivr.com/token,但亲测实际开发中无法响应事件,修改URL至具体的文件即可成功);
  • EncodingAESKey随机生成即可;
  • token:微信特别强调了填写的URL需要响应token,因此在index.php中需要进行验证,代码如下:
    <span> 1</span> <?<span>php
    </span><span> 2</span> <span>define</span>("TOKEN", "此处填写你设置的token值"<span>);
    </span><span> 3</span> 
    <span> 4</span> <span>$wechatObj</span> = <span>new</span><span> CallbackAPI;
    </span><span> 5</span> <span>$wechatObj</span>-><span>valid();
    </span><span> 6</span> 
    <span> 7</span> <span>class</span><span> CallbackAPI {
    </span><span> 8</span> 
    <span> 9</span>     <span>/*</span><span>*
    </span><span>10</span> <span>     * 签名验证
    </span><span>11</span> <span>     * @return [type] [description]
    </span><span>12</span>      <span>*/</span>
    <span>13</span>      <span>public</span> <span>function</span><span> valid() {
    </span><span>14</span>         <span>$echoStr</span> = <span>$_GET</span>["echostr"<span>];
    </span><span>15</span>         <span>$signature</span> = <span>$_GET</span>["signature"<span>];
    </span><span>16</span>         <span>$timestamp</span> = <span>$_GET</span>["timestamp"<span>];
    </span><span>17</span>         <span>$nonce</span> = <span>$_GET</span>["nonce"<span>];
    </span><span>18</span>         <span>$token</span> =<span> TOKEN;
    </span><span>19</span>         <span>//</span><span>将token、timestamp、nonce按字典序排序</span>
    <span>20</span>         <span>$tmpArr</span> = <span>array</span>(<span>$token</span>, <span>$timestamp</span>, <span>$nonce</span><span>);
    </span><span>21</span>         <span>sort</span>(<span>$tmpArr</span><span>);      
    </span><span>22</span>         <span>$tmpStr</span> = <span>implode</span>(<span>$tmpArr</span><span>);
    </span><span>23</span>         <span>//</span><span>对tmpStr进行sha1加密</span>
    <span>24</span>         <span>$tmpStr</span> = <span>sha1</span>(<span>$tmpStr</span><span>);
    </span><span>25</span>         <span>if</span>(<span>$tmpStr</span> == <span>$signature</span><span>){
    </span><span>26</span>             <span>header</span>('content-type:text'<span>);
    </span><span>27</span>             <span>echo</span> <span>$echoStr</span><span>;
    </span><span>28</span>             <span>exit</span><span>;
    </span><span>29</span> <span>        }
    </span><span>30</span> <span>    }
    </span><span>31</span> }
    Copy after login

    在浏览器中运行index.php若程序无误即可看到返回的字符串,且此时完成验证,并将代码中的token填写到基本配置中的相应位置,点击提交。(注:提交后可能会出现“token验证失败”的提示,若检查代码及各项参数无误,则需多点击几次提交即可成功

 4、提交成功后,点击“开启”按钮,即进入开发者模式,该模式开启后功能 ---> 自定义菜单等部分功能即不可用,若想使用点击“停用”即可

 

 

 

 特此声明:相关文章均为查阅资料、阅读大神博文后结合实际开发情况遇到的问题整理而成,能找到原博的必会署名,找不到原博而引用的内容还望原博主海涵

 

 

 

 

 

 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!