zoukankan      html  css  js  c++  java
  • Yii框架 书写xml接口

    <?php 
    class  InterfacesController extends Controller{    
        /*
        * 会员访问记录XML接口
        * 2015-07-15
        */   
       public function actionMemberrecordlist(){     
            //获取url路径传来的参数
            $stardate=$_GET['stardate'];
            $ltime=$_GET['ltime'];
            $key=$_GET['key'];
            $mykey=md5($stardate.$ltime.'asde89dsmm'); 
            //判断ltime请求的时间是否大于60秒    
            //判断钥匙是否正确  
            if($key!=$mykey) {
                echo  '密钥错误'; //表示非法请求
                exit();
            } 
            if( $ltime+60<=(time())){
                echo  '时间超时'; //表示非法请求
                exit();
            }
            //满足条件查询用户访问记录表
             $sql="select user_name,reference_url,module,action,login_ip,login_time  
                      from `smm_en_user_log` 
                      where login_time>='{$stardate}' and user_name !=''";
            
                $result=Yii::app()->db->createCommand($sql)->queryAll();
                if($result){        
                    $html='<?xml version="1.0" encoding="UTF-8" ?>
                            <memberrecordlist xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schem                        aLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';
                       foreach ($result as $key => $value) {
                         if(preg_match('/(\<*\>)+/',$value['action'])){
                              continue;
                          }else{
                            $html.='<recordinfo>
                              <email>'.$value['user_name'].'</email>
                              <source>'.$value['reference_url'].'</source>
                              <items>'.$value['module'].'</items>
                              <content>'.$value['action'].'</content>
                              <ip>'.$value['login_ip'].'</ip>
                              <date>'.$value['login_time'].'</date>
                             </recordinfo>';
                          }        
                        }
                     $html.='</memberrecordlist>';
                     echo $html;
                }else{
                     echo  '对不起,查询的数据为空,没有满足需求的数据!';
                     exit();
                }
           
       }
  • 相关阅读:
    Linux内核架构读书笔记
    Linux内核container_of 宏
    Linux内核架构读书笔记
    Linux内核架构读书笔记
    Linux内核架构读书笔记
    Linux内核架构读书笔记- 2.4.1 进程复制
    作业07:字符串索引与切片
    作业06:数字类型
    作业04:逻辑运算
    作业05:用户登录(三次机会)且每次输入错误显示剩余次数
  • 原文地址:https://www.cnblogs.com/lccjob/p/4739616.html
Copyright © 2011-2022 走看看