function checkSignature($signature, $timestamp, $nonce) { $tmpArr = array(localToken(), $timestamp, $nonce); sort($tmpArr, SORT_STRING); $tmpStr = implode($tmpArr); $tmpStr = sha1($tmpStr); if (strtoupper($tmpStr) == strtoupper($signature)) { return true; } else { return false; } }
<?php //error_log('token验证:'.print_R($GLOBALS,true),3,dirname(__FILE__).'/pay.log'); require_once 'LogUtil.php'; include 'globleconfig.php'; $logFile = dirname(__FILE__) . '/pay.log'; $token = localToken(); LogUtil::logs(time() . " index.php =====> " . $token, $logFile); $echostr = $_GET["echostr"]; $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; LogUtil::logs(time() . " index.php =====> " . $echostr, $logFile); if (!empty($_GET) && checkSignature($signature, $timestamp, $nonce)) { if ($echostr) { echo $echostr; exit; } } $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; if (!empty($postStr)) { dopost($postStr); } else { echo ""; } function dopost($postXml) { $postArray = xml2array($postXml); $postData = $postArray['xml']; error_log('token验证:' . print_R($postData, true), 3, dirname(__FILE__) . '/pay.log'); switch ($postData['MsgType']) {