今天要做一个项目,定时给别人发邮件,要调取一个接口,接口地址如下:
$begin_time = date("Y-m-d", strtotime("-1 day"))." 19:00:00";//开始时间
$end_time = date("Y-m-d", time())." 18:59:59";//结束时间
$url = "http://xxx.???.com.cn/senior?id=3367&limit=999&offset=0&isblack=true&startdate=".$begin_time."&enddate=".$end_time;
$article = file_get_contents($url);
$article = json_decode($article,true);
按说挺简单的哈。可是,file_get_contents始终返回空!
苦恼了好一阵,竟然发现, 时间那里不能有空格, 空格必须有 %20 来代替,哎。。。
对比一下,错误的是:
$url = "http://xxx.???.com.cn/senior?id=3367&limit=999&offset=0&isblack=true&startdate=2020-07-22 00:00:00&enddate=2020-07-23 59:00:00";
正确的应该是这样
$url = "http://xxx.???.com.cn/senior?id=3367&limit=999&offset=0&isblack=true&startdate=2020-07-22%2000:00:00&enddate=2020-07-23%2059:00:00";