微信公众平台开发者模式接入PHP代码

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="
 				
				
				
				%s
				
				
				";
	$info=sprintf($template,$toUser,$FromUserName,$time,$MsgType,$Content);
        echo $info;
	}
}


 
  


 

你可能感兴趣的:(微信,timestamp)