一。
编写PHP文件,文件名例如:index.php
在php文件中,我们首先要token口令:
define("TOKEN", "weixin"); //用户可以任意填写口令,在这里写的是weixin。
验证消息是否来自于微信:
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = TOKEN;
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr); //将$token,$timestamp,$nonce三个值排序;
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr ); //使用sha1加密$tmpStr字符串;
if( $tmpStr == $signature ){ //将$tmpStr得到的值和$signature的值作比较,如果为真则来自于微信.
return true;
}else{
return false;
}
二。将创建的index.php文件传入服务器。
三。登录微信公众平台,设置URL地址(传入服务器的index.php所在的地址或位置),例如:
URL:http://www.zhaoqiaole.top/wx/index.php
填写Token口令,例如:
Token:weixin //Token口令必须与index.php文件中填写的口令一致。
点击提交,显示配置成功,则配置成功。