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;
    }
    
    ?>
  • 相关阅读:
    Object.Instantiate 实例
    .idata数据的解析
    数据结构-静态链表
    数据结构-循环链表
    Android---两个视图间的淡入淡出
    HDU 4597 Play Game 2013 ACM-ICPC吉林通化全国邀请赛H题
    Android 编译时出现r cannot be resolved to a variable
    找工作笔试面试那些事儿(5)---构造函数、析构函数和赋值函数
    SFINAE 模板替换失败而非报错的应用
    模板实参推导 & xx_cast的实现
  • 原文地址:https://www.cnblogs.com/healy/p/6735830.html
Copyright © 2011-2022 走看看