Android 模拟URL数据 , 方便在后台没提供接口期间客户端自己测试

环境基于 PhpStudy8 搭建:

index.php 源码:

<?php

    header('Content-type:text/html;charset=utf-8');

    //渠道分类接口
    $JsonFile1 = new JsonFile('channellist',"channellist.json");
    $JsonFile2 = new JsonFile('commonlist',"commonlist.json");
    $JsonFile3 = new JsonFile('update',"update.json");
    $JsonFile4 = new JsonFile('videolist',"videolist.json");


    $file_path="index666.html";
    if ($_GET['key']=== ($JsonFile1->key)) {
       $file_path=$JsonFile1->filename;
    }elseif ($_GET['key']=== ($JsonFile2->key)) {
       $file_path=$JsonFile2->filename;
    }elseif ($_GET['key']=== ($JsonFile3->key)) {
       $file_path=$JsonFile3->filename;
    }elseif ($_GET['key']=== ($JsonFile4->key)) {
       $file_path=$JsonFile4->filename;
    }

  
    if(file_exists($file_path)){
      // $str = file_get_contents($file_path);//将整个文件内容读入到一个字符串中
      // $str = str_replace("\r\n","",$str);
      // echo trim($str);

      $myfile = fopen($file_path, "r") or die("Unable to open file!");
	  echo @fread($myfile,filesize($file_path));
	  fclose($myfile);
    }

    class JsonFile{

      public $key;     //定义属性

      public $filename;

      function __construct($key,  $filename) {
        $this->key=$key;
        $this->filename=$filename;
      }

    }

?>
posted @ 2020-01-07 14:51  javakam  阅读(305)  评论(0)    收藏  举报