当前位置 : 主页 > 网络编程 > PHP >

tips-1048079-01.php

来源:互联网 收集:自由互联 发布时间:2021-06-28
tips-1048079-01.php class WeChat{ private $_appid; private $_appsecret; private $_token; public function __construct($appid, $appsecret, $token) { $this-_appid = $appid; $this-_appsecret = $appsecret; $this-_token = $token; } public functio
tips-1048079-01.php
class WeChat
{
    private $_appid;
    private $_appsecret;
    private $_token;
    
    public function __construct($appid, $appsecret, $token)
    {
        $this->_appid = $appid;
        $this->_appsecret = $appsecret;
        $this->_token = $token;
    }

    public function valid()
    {
        $echoStr = $_GET["echostr"];

        //valid signature , option
        if($this->checkSignature())
        {
            echo $echoStr;
            exit;
        }
    }

    private function checkSignature()
    {
        $signature = $_GET["signature"];
        $timestamp = $_GET["timestamp"];
        $nonce = $_GET["nonce"];

        $token = $this->_token;
        $tmpArr = array($token, $timestamp, $nonce);
        sort($tmpArr);
        $tmpStr = implode( $tmpArr );
        $tmpStr = sha1( $tmpStr );
        
        if( $tmpStr == $signature )
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}
上一篇:tips-1048079-03.php
下一篇:csv2array.php
网友评论