zoukankan      html  css  js  c++  java
  • 微信回复(二)

    <?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;
    }
    
    ?>
  • 相关阅读:
    bzoj3514 Codechef MARCH14 GERALD07加强版
    差分数列(学习笔记)
    mysql 数据库 replace、regexp的用法
    30岁前男人需要完成的事
    硬盘故障修复十大攻略
    网络工程师考试必备知识
    系统不能正常关机
    忘记XP登入密码的9种解决办法
    Mysql全文搜索match...against的用法
    双绞线网线的连接方式
  • 原文地址:https://www.cnblogs.com/healy/p/6735830.html
Copyright © 2011-2022 走看看