微信接入事件回调的时候,用的是微信官方的代码,但是就是无法通过验证,实在是想骂骂腾讯写文档的人
我的代码如下:
//回调鉴权
public function check_signature()
{
$param = $this->request->get();
$signature = $param["signature"];
$timestamp = $param["timestamp"];
$nonce = $param["nonce"];
$token = config('wx_trade_plugin')['token'];
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr, SORT_STRING);
$tmpStr = implode($tmpArr);
$tmpStr = sha1($tmpStr);
$param['tmpStr'] = $tmpStr;
if ($tmpStr == $signature ) {
echo $param["echostr"]);
} else {
echo 'error';
}
}
思来想去还是觉得没毛病,于是我自己用postman测试,也看不出任何问题
终于在试了很多次之后,我将代码改成这样子,神奇的通过了,心中万马奔腾!!!
//回调鉴权
public function check_signature()
{
$param = $this->request->get();
$signature = $param["signature"];
$timestamp = $param["timestamp"];
$nonce = $param["nonce"];
$token = config('wx_trade_plugin')['token'];
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr, SORT_STRING);
$tmpStr = implode($tmpArr);
$tmpStr = sha1($tmpStr);
$param['tmpStr'] = $tmpStr;
//重点
header("Content-type: text/html; charset=utf-8");
if ($tmpStr == $signature ) {
//重点
echo htmlspecialchars($param["echostr"]);
} else {
echo 'error';
}
}