<?php //------微信会发送4个参数到我们的服务器进行验证(签名 时间戳 随机字符串 随机数)------ //------获取微信验证数据------ $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; $echostr = $_GET["echostr"]; //-------token要与服务器填写一致------- $token="要与服务器填写一致";
//------将token、timestamp、nonce三个参数进行字典序排序----- $tmpArr = array($nonce,$token,$timestamp); sort($tmpArr,SORT_STRING);
//------将三个参数字符串拼接成一个字符串进行sha1加密------ $str = implode($tmpArr); $sign = sha1($str);
//------加密后的字符串与服务器发送过的signature比对------ if ($sign == $signature) { echo $echostr; }
|