zoukankan      html  css  js  c++  java
  • 微信公众号开发启用服务器配置提交token验证失败 php

    URL写到根域名即可(www.abc.com),token随便写,EncodingAESKey自动生成,加密方式明文模式。

    php验证代码

    public function checkToken()
        {
            header("Content-type: text/html; charset=utf-8");
    
            //1.将timestamp,nonce,toke按字典顺序排序
            $timestamp = $_GET['timestamp'];
            $nonce = $_GET['nonce'];
            $token = 'asd123456zxc';
            $signature = $_GET['signature'];
            $array = array($timestamp,$nonce,$token);
            //2.将排序后的三个参数拼接之后用sha1加密
            $tmpstr = implode('',$array);
            $tmpstr = sha1($tmpstr);
            //3.将加密后的字符串与signature进行对比,判断该请求是否来自微信
            if($tmpstr == $signature){
                echo $_GET['echostr'];
                exit;
            }
        }

    注意:如果配置都是正确的,但是一直就是token验证失败,可能是因为编码问题,加上“header("Content-type: text/html; charset=utf-8");”即可

  • 相关阅读:
    Django部署到服务器
    springboot使用Redis缓存
    ubuntu下pip更换国内源
    ubuntu环境变量文件
    python open找不到路径
    centos 8 安装nginx
    centos8 mysql8的远程访问
    centos 8 安装mysql-server 8
    今日收获
    今日收获
  • 原文地址:https://www.cnblogs.com/zxf100/p/12713297.html
Copyright © 2011-2022 走看看