亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么不能讓通過驗證?

為什么不能讓通過驗證?


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實現微信公眾平臺開發—基礎篇
  • 參與學習       102027    人
  • 解答問題       219    個

由淺入深一起玩轉微信公眾平臺開發,課程由淺入深,內容詳實

進入課程

為什么不能讓通過驗證?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號