• 微信回复(二)


    <?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;
    }
    
    ?>
  • 相关阅读:
    抬起头,看到满天星星
    别再嫌弃你妈妈话多唠叨啦,她可能正在做声音健脑操呢
    此生不能不認識的一個人
    长尾夹除了夹东西还能做什么?
    Markdown使用经验总结
    注册quora失败
    电脑插入耳机后声音仍然外放
    centOS下安装tree命令
    解决ubuntu “无法获得锁"
    虚拟机上Ubuntu无法上网问题
  • 原文地址:https://www.cnblogs.com/healy/p/6735830.html
Copyright © 2020-2023  润新知