public function responseMsg() { //get post data, May be due to the different environments $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; //extract post data if (!empty($postStr)) { $postObj = simplexml_load_string($postStr, ‘SimpleXMLElement‘, LIBXML_NOCDATA);//发送人 $fromUsername = $postObj->FromUserName;//接收人 $toUsername = $postObj->ToUserName; $keyword = trim($postObj->Content); $msgType = $postObj->MsgType; if($msgType == ‘text‘) {//接收类型为文本 echo sprintf(wechatCallbackapi::$textTpl, $fromUsername, $toUsername, time(), "text", "返回文本");//echo sprintf(wechatCallbackapi::$imageTpl, $fromUsername, $toUsername, time(), "返回文本", $event["t"], "图片地址", "图片链接地址"); } else if($msgType == ‘event‘){//接收类型为事件 $msgEvent = $postObj->Event; if ($msgEvent == ‘CLICK‘){ $eventKey = $postObj->EventKey; echo sprintf(wechatCallbackapi::$textTpl, $fromUsername, $toUsername, time(), "text", "返回文本"); } } }else { echo ""; exit; } }
将脚本放到服务器上,在微信公众平台上设置脚本地址为脚本地址在服务器上的地址