Exemple #1
0
<?php

define("TOKEN", "hongbao");
define("APPID", "wx8d80c4101193fcdb");
define("APPSECRET", "57ff9e369cae45f7ec9ffe28c0b43e9f");
$wxObj = new weixin();
$wxObj->responseMsg();
class weixin
{
    public function valid()
    {
        $echoStr = $_GET["echostr"];
        if ($this->checkSignature()) {
            echo $echoStr;
            exit;
        }
    }
    public function responseMsg()
    {
        $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
        if (!empty($postStr)) {
            $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
            $RX_TYPE = trim($postObj->MsgType);
            //消息类型分离
            switch ($RX_TYPE) {
                case "event":
                    $result = $this->receiveEvent($postObj);
                    break;
                default:
                    $this->valid();
                    break;