<?php /** * wechat php test */ //define your token define("TOKEN", "Am7L5YjkVwfSVNRO"); $wechatObj = new wechatCallbackapiTest(); //$wechatObj->valid(); $wechatObj->reponseMsg(); class wechatCallbackapiTest { public function valid() { $echoStr = $_GET["echostr"]; //valid signature , option if ($this->checkSignature()) { echo $echoStr; exit; } } public function reponseMsg() { //获取到微信推送过来的post数据(xml格式) //$postObj = $GLOBALS["HTTP_RAW_POST_DATA"];不能用_-_ $postArr = $GLOBALS["HTTP_RAW_POST_DATA"]; //将xml数据转化成一个对象; if (!empty($postArr)) { $postObj = simplexml_load_string($postArr, 'SimpleXMLElement', LIBXML_NOCDATA); $file = fopen('1.txt', 'a+'); fwrite($file, var_export($postObj, true));