收藏
回答

消息推送url配置问题-请求超时,请检查信息是否填写正确?

url:https://jinyuanea.cn/MsgPush/demo1.php

可以正常访问

PHP代码如下:

/**

  * wechat php test

  */


//define your token

define("TOKEN", "*******");

$wechatObj = new wechatCallbackapiTest();

$wechatObj->valid();

class wechatCallbackapiTest

{

    public function valid()

    {

        $echoStr = $_GET['echostr'];

        //valid signature , option

        if($this->checkSignature()){

            echo $echoStr;

            exit;

        }

    }

        

    private function checkSignature()

    {

        // you must define TOKEN by yourself

        if (!defined($_GET['echostr'])) {

            echo "TOKEN is not defined!";

        }

        $signature = $_GET['signature'];

        $timestamp = $_GET['timestamp'];

        $nonce = $_GET['nonce'];

        $token = TOKEN;


        $tmpArr = array($token, $timestamp, $nonce);

        // use SORT_STRING rule

        sort($tmpArr, SORT_STRING);

        $tmpStr = implode( $tmpArr );

        $tmpStr = sha1( $tmpStr );

        

        if( $tmpStr == $signature ){

            echo $_GET['echostr'];

        }else{

            echo false;

        }

    }

}


?>

回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容
问题标签