首页 > 微信 > 详细

php微信开发-tp5下验证服务器的代码

时间:2017-06-30 19:15:25      阅读:429      评论:0      收藏:0      [点我收藏+]

废话少说,直接上干货!

 1 <?php
 2 namespace app\index\controller;
 3  
 4 use think\Controller;
 5   
 6  
 7 
 8 Class Index extends Controller
 9 {
10     public function index()//接收微信客户端发送的信息并回应! 
11     { 
12     
13      //获得参数 signature nonce token timestamp echostr
14         $nonce     = $_GET[‘nonce‘];
15         $token     = ‘wexin‘;
16         $timestamp = $_GET[‘timestamp‘];
17         $echostr   = $_GET[‘echostr‘];
18         $signature = $_GET[‘signature‘];
19         //形成数组,然后按字典序排序
20         $array = array();
21         $array = array($nonce, $timestamp, $token);
22         sort($array);
23         //拼接成字符串,sha1加密 ,然后与signature进行校验
24         $str = sha1( implode( $array ) );
25         if( $str  == $signature && $echostr ){
26             //第一次接入weixin api接口的时候
27             echo  $echostr;
28             exit;
29         }
30     }
31      
32     
33  
34 }

文件名为Index.php 是位于index模块下的Index控制器文件。

php微信开发-tp5下验证服务器的代码

原文:http://www.cnblogs.com/xiaogou/p/7100356.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!