php微信開發-tp5下驗證服務器的代碼


廢話少說,直接上干貨!

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM