微信开发笔记

1、token验证。服务器地址:http://***/public/index.php/index/Wechat/index
文件路径:\application\index\controller\Wechat.php

<?php
namespace app\index\controller;

use think\facade\Config;
use think\facade\Request;

class Wechat{
    public function index(){
        $token     = Config::get('wechat.official_account.default.token');    
        $echostr   = 'failure';  
        $timestamp =Request::get('timestamp');          //input('timestamp');//
        $nonce     =Request::get('nonce');              //input('nonce');// 
        $signature = Request::get('signature');         //input('signature');//
       
        $list     = array($token, $timestamp, $nonce);
        $hashcode = sort($list, SORT_STRING) ? sha1(implode('', $list)) : '';
        if($hashcode == $signature) {
            $echostr =input('echostr');
        }
        return $echostr;    // 验证时必须关闭调试模式
    }
}