微信服务器URL验证代码示例(PHP)
微信公众号开发 和 小程序开发 的 服务器端验证代码 示例:
$signature = $_GET['signature'];
$timestamp = $_GET['timestamp'];
$nonce = $_GET['nonce'];
$token = 'your_token';
// 将token、timestamp、nonce按字典序排序
$array = array($token, $timestamp, $nonce);
sort($array);
$string = implode('', $array);
// 进行SHA1加密
$sha1 = sha1($string);
// 验证signature
if ($sha1 === $signature) {
echo $_GET['echostr']; // 验证成功返回echostr
} else {
echo 'Invalid request';
}
2.37KB
文件大小:
评论区