Rumah > Artikel > pembangunan bahagian belakang > (一)微信公众号开发基本配置,信公众开发基本配置_PHP教程
作为用代码进行微信开发者或要实现事件响应等功能,微信开发基本配置是必不可少的环节,本文大致梳理开发配置的流程。
1、登入微信公众平台:开发 ---> 基本配置
2、在基本配置页面有“服务器配置”,默认是未启用状态,需要我们先点击“修改配置”进行相关项目填写
3、填写以下项目内容
<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、提交成功后,点击“开启”按钮,即进入开发者模式,该模式开启后功能 ---> 自定义菜单等部分功能即不可用,若想使用点击“停用”即可
特此声明:相关文章均为查阅资料、阅读大神博文后结合实际开发情况遇到的问题整理而成,能找到原博的必会署名,找不到原博而引用的内容还望原博主海涵