微信公众号设置Token

微信GET传递的数据:array (
  'appid' => '1',
  'signature' => '1dcfa2cc768ca9362ae5dcdd838268f12787f1b6',
  'echostr' => '1460826792410339829',
  'timestamp' => '1449726453',
  'nonce' => '870354798',
)
$echoStr = array_key_exists('echostr',$_GET) ? $_GET["echostr"]:null;
$signature = array_key_exists('signature',$_GET) ? $_GET["signature"]:null;
$timestamp = array_key_exists('timestamp',$_GET) ? $_GET["timestamp"]:null;
$nonce = array_key_exists('nonce',$_GET) ? $_GET["nonce"]:null;
$公众号id = array_key_exists('appid',$_GET) ? $_GET["appid"]:null;
 
 
  

$tmpArr = array($token, $timestamp, $nonce);

-- :array ( 0 => 'linhekeji1',/*自己设置的数据*/ 1 => '1449726453',/*微信传递的timestamp*/ 2 => '870354798',/*微信传递的nonce*/)

// use SORT_STRING rule
sort($tmpArr, SORT_STRING);
$tmpStr = implode($tmpArr); 
 /*返回字符串的顺序
 :'1449726453870354798linhekeji1'
 
  
*/ 

  $tmpStr = sha1 ( $tmpStr );
//判断与微信传过来的 signature 信息的是否相同
if ($tmpStr == $signature) {
   echo $echoStr;  
} else {
    echo "微信签名验证失败";
}

你可能感兴趣的:(微信公众号设置Token)