核心代码
class Wechat
{
public function __construct()
{
//构造函数直接调用微信官方给的私有方法
$this->checkSignature();
}
//微信官方给的核心代码
private function checkSignature()
{
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$echostr = $_GET["echostr"];
//与上图的Token保持一致
$token = 'php';
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr, SORT_STRING);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
echo $echostr;
}else{
return false;
}
}
//调用共有方法
public function index()
{
}
}
官方文档
https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Access_Overview.html