Public ID development instance and public development instance
The Index. PHP file below is an example of a public number written based on PHP 5.6.30.
The Code is as follows:
Valid ();} else {$ wechatObj-> responseMsg ();} class wechatCallbackapiTest {public function valid () {$ echoStr = $ _ GET ["echostr"]; if ($ this-> checkSignature () {header ('content-type: text'); echo $ echoStr; exit ;}} private function checkSignature () {$ signature = $ _ GET ["signature"]; $ timestamp = $ _ GET ["timestamp"]; $ nonce = $ _ GET ["nonce"]; $ token = TOKEN; $ tmpArr = array ($ token, $ timestamp, $ nonce); sort ($ TmpArr, SORT_STRING); $ tmpStr = implode ($ tmpArr); $ tmpStr = sha1 ($ tmpStr); if ($ tmpStr = $ signature) {return true ;} else {return false ;}} public function responseMsg () {// $ HTTP_RAW_POST_DATA is about to be canceled (already) in the release instructions of php in high version. Please switch to php: // declaration read from input // $ postStr = $ GLOBALS ["HTTP_RAW_POST_DATA"]; $ postStr = file_get_contents ('php: // input'); if (! Empty ($ postStr) {$ postObj = simplexml_load_string ($ postStr, 'simplexmlelement', LIBXML_NOCDATA); $ fromUsername = $ postObj-> FromUserName; $ toUsername = $ postObj-> ToUserName; $ keyword = trim ($ postObj-> Content); $ time = time (); $ textTpl ="
% S
0
"; If ($ keyword = "? "| $ Keyword = "? ") {$ MsgType =" text "; // set the time zone date_default_timezone_set (" Asia/Shanghai "); $ contentStr = date (" Y-m-d H: I: s ", time (); $ resultStr = sprintf ($ textTpl, $ fromUsername, $ toUsername, $ time, $ msgType, $ contentStr); echo $ resultStr ;}} else {echo ""; exit ;}}}