1验证Token,链接api:
$timestamp=$_GET['timestamp'];
$nonce=$_GET['nonce'];
$token='weixinr';
$signature=$_GET['signature'];
$array=array($timestamp,$nonce,$token);
sort($array);
$tmpstr=implode('',$array);
$tmpstr=sha1($tmpstr);
if($tmpstr==$signature){
echo $_GET['echostr'];
exit;
}
2.消息回复:
$arr=$GLOBALS['HTTP_RAW_POST_DATA'];
$postObj= simplexml_load_string($arr);
if(strtolower($postObj->MsgType)=='event'){
if(strtolower($postObj->Event=='subscribe')){
$toUser=$postObj->FromUserName;
$FromUserName=$postObj->ToUserName;
$time=time();
$MsgType='text';
$Content='欢迎关注订阅号';
$template="
<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName>