微信公众平台 - thinkphp5微信服务器配置问题,为什么一直验证不了token
本文介绍了微信公众平台 - thinkphp5微信服务器配置问题,为什么一直验证不了token的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
现在验证是通过了,就差返回给微信那边,我返回echostr还是true 微信那边都说我token验证失败
<?php
namespace app\index\controller;
use think\Request,think\Db;
use think\Cache;
class Autoreply extends RestBase{
// 获取微信数据
public function checktoken(){
$request = Request::instance();
$get = $request->param();
$timestamp = $get['timestamp'];//timestamp其实就是一个时间戳
$nonce = $get['nonce'];//nonce是一个随机参数
$token = "";//这个token填写你在微信公众平台上写的那个值
$signature = $get['signature'];//这个signature其实就是在微信公众平台已经加密好的字符串
$echostr = $get['echostr'];
$array = array();
$array = array($token,$timestamp,$nonce);
sort($array);
$tmpstr = sha1(implode('',$array));
if($tmpstr == $signature){
echo $get['echostr'];
}else{
return false;
}
}
}
解决方案
自己已经解决 我的解决办法就是加一个头部声明传过去是以utf-8编码,因为你的数据可能传过去是乱码的.
header("Content-type: text/html; charset=utf-8");
这篇关于微信公众平台 - thinkphp5微信服务器配置问题,为什么一直验证不了token的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文