• 微信回复(二)


    <?php
    
    
    /*echo $_GET['echostr'];
    exit;*/
    
    
    //接收xml数据
    $postStr = $GLOBALS['HTTP_RAW_POST_DATA'];
    //把xml数据转化成对象
    $postObj = simplexml_load_string($postStr);
    //接收post的值
    $fromuserName = $postObj->FromUserName;
    $touserName = $postObj->ToUserName;
    $time = time();
    $msgType = $postObj->MsgType;
    $keywords = $postObj->Content;
    
    
    //自动回复
    $textTpl = "<xml>
                <ToUserName><![CDATA[%s]]></ToUserName>
                <FromUserName><![CDATA[%s]]></FromUserName>
                <CreateTime>%s</CreateTime>
                <MsgType><![CDATA[%s]]></MsgType>
                <Content><![CDATA[%s]]></Content>
                </xml>";
    
    //关键词自动回复
    if($postObj->MsgType == "text" ){
        if($postObj->Content == '1'){
            $content = '111!!!!';
            $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content);
            echo $resultful;
        }else if($postObj->Content == '2'){
    
            $content = '222!!!!';
            $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content);
            echo $resultful;
        }else{
            $content = 'hello world!';
            $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content);
            echo $resultful;
            
        }
            
        
    }else if ($postObj->MsgType == 'image'){
            $msgType = 'text';
            $content = 'output image';
            $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content);
            echo $resultful;
    }else if ($postObj->MsgType == 'voice'){
            $msgType = 'text';
            $content = 'output voice';
            $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content);
            echo $resultful;
    
    }else if ($postObj->MsgType == 'video'){
            $msgType = 'text';
            $content = 'output video';
            $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content);
            echo $resultful;
    
    }else if ($postObj->MsgType == 'music'){
            
            $msgType = 'text';
            $content = 'output music';
            $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content);
            echo $resultful;
    
    }else {
            $content = 'output tuwen';
            $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content);
            echo $resultful;
    }
    
    ?>
  • 相关阅读:
    python网络编程之最简单的单工通信
    ruby : Exception Notification
    python学习之操作mysql
    python学习之最简单的获取本机ip信息的小程序
    python学习之最简单的用户注册及登录验证小程序
    mongo数据库的导入导出
    mac安装django1.5.4
    mac安装软件管家homebrew
    关于mac安装rails报错clang: error: unknown argument
    在mac上安装nodejs
  • 原文地址:https://www.cnblogs.com/healy/p/6735830.html
Copyright © 2020-2023  润新知