zoukankan      html  css  js  c++  java
  • 微信测试号开发 服务器 token验证

    测试号上填写url为配置的服务器验证的访问地址,token随便填 但要保证与自己服务器配置的token相同

    编写本地token验证测试文件


    /**
    * token验证测试页面
    * @return 默认信息
    */
    public function index()
    {

      //获得几个参数
      $token = '';//此处填写之前开发者配置的token
      $nonce = $_GET['nonce'];
      $timestamp = $_GET['timestamp'];
      $echostr = $_GET['echostr'];
      $signature = $_GET['signature'];

      //file_put_contents('weixin_log.txt', "IP=".$_SERVER['REMOTE_ADDR'].PHP_EOL,FILE_APPEND); //记录访问IP到log日志
      //file_put_contents('weixin_log.txt', "QUERY_STRING=".$_SERVER['QUERY_STRING'].PHP_EOL,FILE_APPEND);//记录请求字符串到log日志
      //file_put_contents('weixin_log.txt', '$_GET[echostr])='.htmlspecialchars($_GET['echostr']).PHP_EOL,FILE_APPEND); //记录是否获取到echostr参数


      //参数字典序排序
      $array = array();
      $array = array($nonce, $timestamp, $token);
      sort($array);
      //验证
      $str = sha1( implode( $array ) );//sha1加密
      //对比验证处理好的str与signature,若确认此次GET请求来自微信服务器,请原样返回echostr参数内容,则接入生效,成为开发者成功,否则接入失败。
      if( $str == $signature && $echostr ){
      ob_clean();
       echo $echostr;
     }
     else{
      //接入成功后的其他处理
      }

     }

  • 相关阅读:
    POJ 1862 Stripies (简单贪心)
    HDU 2181 哈密顿绕行世界问题(DFS)
    POJ 3262 Protecting the Flowers (贪心)
    Aizu 2249 Road Construction (最短路 SPFA)
    POJ 3484 Showstopper(二分)
    HDU 6235 2017-CCPC-哈尔滨站 Permutation(简单模拟)
    IDEA常用插件
    解决IDEA插件加载失败
    解决zsh无法使用maven
    Linux安装Maven
  • 原文地址:https://www.cnblogs.com/jiafeimao-dabai/p/7229891.html
Copyright © 2011-2022 走看看