您的位置:首页 > 博客中心 > 前端开发 >

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

时间:2022-04-06 13:10

废话少说,直接上干货!

 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控制器文件。

本类排行

今日推荐

热门手游