1.公众号基本配置(token验证失败)
<?php define("TOKEN", "你自己的token"); $wechatObj = new CallbackAPI; $wechatObj->valid(); class CallbackAPI { /** * 签名验证 * @return [type] [description] */ public function valid() { $echoStr = $_GET["echostr"]; $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; $token = TOKEN; //将token、timestamp、nonce按字典序排序 $tmpArr = array($token, $timestamp, $nonce); sort($tmpArr); $tmpStr = implode($tmpArr); //对tmpStr进行sha1加密 $tmpStr = sha1($tmpStr); if($tmpStr == $signature){ header('content-type:text'); echo $echoStr; exit; } } }
2.公众平台测试账号接口配置信息(token验证失败)
<?php //微信服务器发送过来的 :接受get参数 $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; //自己定义的TOKEN $token = 'phplove1'; $echostr = $_GET['echostr']; @file_put_contents('Public/checksing.html', '<br/>'.$signature.'-'.$timestamp.'-'.$nonce.'-'.$token, FILE_APPEND); $tmpArr = array($token, $timestamp, $nonce); sort($tmpArr, SORT_STRING); $tmpStr = implode( $tmpArr ); $tmpStr = sha1( $tmpStr ); @file_put_contents('Public/checksing.html', '<br/>'.$tmpStr.'--'.$echostr, FILE_APPEND); //进行比对 if( $signature ){ echo $echostr; }else{ return false; }