?? ???? ?? ??? ????, ?? ?? ??? ??? ????.
?? ??? ???? ??? ??? ? GET ??? ?? ??? Url? ?????. , ??? 4?? ????? ?????:
* ?? — WeChat ???? ??
* ????? — ?????
* nonce — ??? ??
* echostr — ??? ???
???? ??? ???? URL ???? ???? ?????. ? GET ??? echostr ???? ??? ??? ???? ???? ????, ??? ??? ???? ?????. ?? ??? ???? ??? ?? ????, ????? ???? ? ?? ????? ?????. ??? ????? ??? ????.
* ??, ?????, ??? ? ?? ????? ????? ?????.
* ? ?? ????? ?????. ???? ???? SHA1 ???? ?? ??? ???? ?????.
* ???? ?? ???? ???? ??? ???? ??? WeChat?? ?????? ??? ? ????.
??:
<? $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 $_GET['echostr']; }else{ return false; } ?>
??? WeChat? ??? ??? json? ???? ????.
??? XML ???? ??? ?? ????? simplexml_load_string? ???? ???. POST ???? urlencode? ???? HTTP_RAW_POST_DATA? ???? ???? ?? ? ????.
ToUserName ??? ???? WeChat ID, ????? ?? ??? ?? WeChat ID
FromUserName ??? ?? ??? WeChat ID
CreateTime ??? ?? ??
MsgType ?? ???? ???
??? ??? ??
<?php $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; //符合微信的POST規(guī)范 if (!emptyempty($postStr)) { $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); //XML轉(zhuǎn)對(duì)象函數(shù),可能最近這一兩年入行的不太清楚XML函數(shù) //數(shù)據(jù)從對(duì)象取出 $fromUsername = $postObj->FromUserName; $toUsername = $postObj->ToUserName; $CreateTime = $postObj->CreateTime; $MsgType = $postObj->MsgType; $Content = $postObj->Content; $keyword = trim($postObj->Content); //安全Trim $time = time(); //XML數(shù)據(jù)體 $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(!emptyempty( $keyword )) //如果發(fā)信息來(lái)了,不是空白POST,微信規(guī)定立即回復(fù),不用推送. { $msgType = "text"; //定義類型 $contentStr = "Hello World,I am Tater!"; //回復(fù) $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); //記住,Tpl是要載入的 echo $resultStr; //輸出,以便微信抓! } else { echo "What are you say!"; //輸入信息有問(wèn)題,提示輸入! } } else { echo ""; exit; } ?>
? ??? WeChat ????? ??? ?? ??? ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)