为了账号安全,请及时绑定邮箱和手机立即绑定

为什么不能让通过验证?

为什么不能让通过验证?


define("TOKEN","weixin");

$timestamp = $_GET['timestamp'];

$nonce     = $_GET['nonce'];

$token     = TOKEN;

$signature = $_GET['signature'];

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

sort($tmpArr,SORT_STRING);

$tmpStr    =implode($tmpArr);

$tmpStr    =sha1($tmpStr);

if($tmpStr == $signature){

echo $_GET['echostr'];

exit;

}


在网上找了个这样的代码 就通过了

<?php

/**

  * wechat php test

  */


//define your token

define("TOKEN", "weixin");

$wechatObj = new wechatCallbackapiTest();

$wechatObj->valid();


class wechatCallbackapiTest

{

public function valid()

    {

        $echoStr = $_GET["echostr"];


        //valid signature , option

        if($this->checkSignature()){

        echo $echoStr;

        exit;

        }

    }


    public function responseMsg()

    {

//get post data, May be due to the different environments

$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];


      //extract post data

if (!empty($postStr)){

                

              $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);

                $fromUsername = $postObj->FromUserName;

                $toUsername = $postObj->ToUserName;

                $keyword = trim($postObj->Content);

                $time = time();

                $textTpl = "<xml>

<ToUserName><![CDATA[%s]]></ToUserName>

<FromUserName><![CDATA[%s]]></FromUserName>

<CreateTime>%s</CreateTime>

<MsgType><![CDATA[%s]]></MsgType>

<Content><![CDATA[%s]]></Content>

<FuncFlag>0</FuncFlag>

</xml>";             

if(!empty( $keyword ))

                {

              $msgType = "text";

                $contentStr = "Welcome to wechat world!";

                $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);

                echo $resultStr;

                }else{

                echo "Input something...";

                }


        }else {

        echo "";

        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;

}

}

}


?>


正在回答

1 回答

我也在学习

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
PHP实现微信公众平台开发—基础篇
  • 参与学习       102031    人
  • 解答问题       219    个

由浅入深一起玩转微信公众平台开发,课程由浅入深,内容详实

进入课程

为什么不能让通过验证?

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号