首页 >后端开发 >php教程 >(一)微信公众号开发基本配置,信公众开发基本配置_PHP教程

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

WBOY
WBOY原创
2016-07-12 09:01:471233浏览

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

 

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

 

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> }

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

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

 

 

 

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

 

 

 

 

 

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1087776.htmlTechArticle(一)微信公众号开发基本配置,信公众开发基本配置 作为用代码进行微信开发者或要实现事件响应等功能,微信开发基本配置是必不可少...
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn