token值加密

<?php
/**
 * 公众号被动接受处理类
 */

$wx = new Wx();

class Wx {
    // 微信后台设置的token值 php7.1之后可以加权限 private
    const TOKEN = 'weixin';

    // 构造方法
    public function __construct(){
        // 判断是否是第1次接入 echostr
        if (!empty($_GET['echostr'])) {
            echo $this->checkSign();
        }
    }


    /**
     * 初次接入校验
     * @return [type] [description]
     */
    private function checkSign(){
        // 得到微信公众号发过来的数据
        $input = $_GET;
        // 把echostr放在临时变量中
        $echostr = $input['echostr'];
        $signature = $input['signature'];
        // 在数组中删除掉
        unset($input['echostr'],$input['signature']);
        // 在数据中添加一个字段token
        $input['token'] = self::TOKEN;
        // 进行字典排序
        $tmpStr = implode( $input );
        // 进行加密操作
        $tmpStr = sha1( $tmpStr );

        // 进行比对
        if ($tmpStr === $signature) {
            return $echostr;
        }
        return '';
    }



}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。