Step1 你要有的一个php空间, 建立api\weixin.php, 输入如下代码
<?php
header('Contetent-Type:text');
class WechatAPI
{
public function validSignature($value = '')
{
//取得参数
$timestamp = $_GET['timestamp'];
$nonce = $_GET['nonce'];
$token = 'weixin';
$signature = $_GET['signature'];
//生成数组
$array = array($timestamp, $nonce, $token);
//处理
$tmpstr = implode('', $array);
$tmpstr = sha1($tmpstr);
//将加密后的字符串与signature进行对比
if ($tmpstr == $signature) {
header('content-type:text');
echo $_GET['echostr'];
exit;
}
}
}
$a = new WechatAPI;
$a->validSignature();
Step2 登录微信公众平台->点左侧的基本配置->服务器配置->修改配置->URL填写你上面的weixin.php的网址->Token填写weixin->随机生成一个 EncodingAESKey->可以选"明文模式"->提交
这样就可以验证成功了.