![](https://i-blog.csdnimg.cn/blog_migrate/cf35821930dd3a3251a51d74e2fc0a7e.jpeg)
ThinkPHP6 微信小程序消息推送配置时报错:
{“ret“:200302,“err_msg“:“verify token fail“}
贴一下我的代码:
控制器
class Message
{
public function wxCustomerPush()
{
$requestMethod = request()->method();
if ($requestMethod === 'GET') {
// 如果是GET请求,则说明是token认证
$wxServiceResult = new wxServiceResult();
return $wxServiceResult->index(input());
} else {
// 如果是POST请求,则说明是消息推送
}
}
}
被控制器调用的业务模型,如效验成功,则原路返回 echostr
public function index($param){
$signature = $param["signature"];
$timestamp = $param["timestamp"];
$nonce = $param["nonce"];
$echostr = $param["echostr"];
$token = "wxpush1621246785"; // 注意,这里改成微信管理后台那里你填写的Token(令牌)
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr, SORT_STRING);
$tmpStr = implode($tmpArr);
$tmpStr = sha1($tmpStr);
if ($tmpStr == $signature) {
return $echostr;
} else {
return false;
}
}
这里注意一个坑,需要关闭 APP_DEBUG = false,笔者就是在这里困扰了一天