zoukankan      html  css  js  c++  java
  • 微信公众平台——基础配置——服务器配置:PHP版

    在自己的服务器上新建一个空白php文件,输入以下任一版本的代码,如下:

    版本一:

    <?php
    $token = "dige1994";
    $signature = $_GET["signature"];
    $timestamp = $_GET["timestamp"];
    $nonce = $_GET["nonce"];
    $echostr = $_GET["echostr"];
    
    $tmpArr = array($token, $timestamp, $nonce);
    sort($tmpArr);
    $tmpStr = implode( $tmpArr );
    $tmpStr = sha1( $tmpStr );
    
    if($tmpStr == $signature ){
        echo $echostr;
    }else{
        echo "err";
    }
    ?>

    版本二:

    <?php
    define("TOKEN", "dige1994"); //TOKEN值
    $wechatObj = new wechat();
    $wechatObj->valid();
    class wechat{
        public function valid() {
            $echoStr = $_GET["echostr"];
            if($this->checkSignature()){
                echo $echoStr;
                exit;
                }
        }
        private function checkSignature() {
            $signature = $_GET["signature"];
            $timestamp = $_GET["timestamp"];
            $nonce = $_GET["nonce"];
            $token = TOKEN;
            $tmpArr = array($token, $timestamp, $nonce);
            sort($tmpArr);
            $tmpStr = implode( $tmpArr );
            $tmpStr = sha1( $tmpStr );
            if( $tmpStr == $signature ) {
                return true;
            } else {
                return false;
            }
        }
    }
    ?>

    在微信公众平台——基本配置——服务器配置中,将上述文件的地址填到URL栏中,将$token的值填到Token栏,消息加解密密钥随机生成,消息加解密方式在学习阶段建议选择明文方式,然后提交,提交成功后再点启用配置。

  • 相关阅读:
    Docker学习总结(四)--应用部署
    strcat的由来
    ubuntu man不到pthread_mutex_XX
    string::front
    string::find_last_of
    string::find_last_not_of
    string::find_first_of
    string::find_first_not_of
    string::erase
    string::empty
  • 原文地址:https://www.cnblogs.com/dige1993/p/6947470.html
Copyright © 2011-2022 走看看