微信的接入在填写服务器URL时指向TOKEN验证的php文件,列如http://localhost/wlink.php
验证示例代码
responseMsg ( $openid ); } //验证TOKEN后输出验证 function valid() { $echoStr = $_GET ["echostr"]; if (checkSignature ()) { echo $echoStr; exit (); } } //验证TOKEN算法 function checkSignature() { if (! defined ( "TOKEN" )) { throw new Exception ( 'TOKEN is not defined!' ); } $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; } } ?>
通过上述代码,我们就能通过微信的Token验证,在公众平台上面完成接入了。