wordpress微信机器人验证失败解决
1 min read使用wordpress微信机器人与微信公众号开发配置时,总是token验证失败,网上许多资料显示改代码或改文件名各类方法挺多,有些已经过时或是不全,综合测试后使用如下办法:
vim /wordpress/wp-content/plugins/weixin-robot-advanced/token.php
# 按如下内容修改
checkSignature()){
header('content-type:text'); //手动添加
ob_clean(); //手动添加
echo $echoStr;
exit;
}
}
private function checkSignature() {
$signature = $_GET ["signature"];
$timestamp = $_GET ["timestamp"];
$nonce = $_GET ["nonce"];
$token = TOKEN;
$tmpArr = array (
$token,
$timestamp,
$nonce
);
sort ( $tmpArr );
$tmpStr = implode ( $tmpArr );
$tmpStr = sha1 ( $tmpStr );
if ($tmpStr == $signature) {
return true;
} else {
return false;
}
}
}
$wechatObj = new wechatCallbackapiTest();
$wechatObj->valid();
}
#
服务器地址在微信公众号平台开发基本配置里写全地址:
https://servername/wordpress/wp-content/plugins/weixin-robot-advanced/token.php
验证类型:安全
然后可验证token成功。tokenpockettoken是什么tokenviewtokentoken是什么tokenizertokeninsight