废话少说,直接上干货!
1 <?php 2 namespace appindexcontroller; 3 4 use thinkController; 5 6 7 8 Class Index extends Controller 9 {10 public function index()//接收微信客户端发送的信息并回应! 11 { 12 13 //获得参数 signature nonce token timestamp echostr14 $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控制器文件。