1.公众号后台配置

1.1 url需要是线上地址,且url可以外部访问到 checkToken是个接口名
1.2 token自己随便写,但是要在代码中配置
1.3 aeskey兼容模式无需过多关注
2.代码部分
public function checkToken()
{
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$signature = $_GET["signature"]; //5e27a0b458104f8506603ccd94b1391ed4a7a4b6
$timestamp = $_GET["timestamp"]; //1732936449
$nonce = $_GET["nonce"];//793616711
$echoStr = $_GET["echostr"];//2107083572574656405
if ($this->checkSign($signature, $timestamp, $nonce)) {
return (int)$echoStr;//一定是int
} else {
throw new CustomerException("错误");
}
}
}
public function checkSign($signature, $timestamp, $nonce)
{
$token = config('extra.mp.token');
if (!$token) {
throw new CustomerException("未设置token");
}
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr, SORT_STRING);
$tmpStr = implode($tmpArr);
$tmpStr = sha1($tmpStr);
if ($tmpStr == $signature) {
return true;
} else {
return false;
}
}
