微信公众平台自定义脚本

时间:2014-12-12 13:03:28   收藏:0   阅读:316
 	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;
        	}
    	}

将脚本放到服务器上,在微信公众平台上设置脚本地址为脚本地址在服务器上的地址

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!