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;
    }
    
    ?>
  • 相关阅读:
    POJ 1691 Painting a Board(状态压缩DP)
    POJ 1946 Cow Cycling(抽象背包, 多阶段DP)
    Leetcode: Best Time to Buy and Sell Stock I, II
    Leetcode: Valid Palindrome
    POJ 1946 Cow Cycling
    POJ 1661 Help Jimmy(递推DP)
    POJ 1160 Post Office(区间DP)
    POJ 2486 apple tree
    Android播放器框架分析之AwesomePlaye
    【开源框架】Android之史上最全最简单最有用的第三方开源库收集整理,有助于快速开发,欢迎各位...
  • 原文地址:https://www.cnblogs.com/healy/p/6735830.html
Copyright © 2011-2022 走看看