2019年10月

PHP获取指定N个工作日后日期

<?php
// 制定允许其他域名访问
header('Access-Control-Allow-Origin:*');
// 响应类型
header('Access-Control-Allow-Methods:*');
//请求头
header('Access-Control-Allow-Headers:*');
// 响应头设置
header('Access-Control-Allow-Credentials:false');

//节假日 需要手动维护配置文件或者放入db中
$holiday=['2019-01-01', '2019-01-05', '2019-01-06', '2019-01-12', '2019-01-13', '2019-01-19', '2019-01-20', '2019-01-26', '2019-01-27', '2019-02-04', '2019-02-05', '2019-02-06', '2019-02-07', '2019-02-08', '2019-02-09', '2019-02-10', '2019-02-16', '2019-02-17', '2019-02-23', '2019-02-24', '2019-03-02', '2019-03-03', '2019-03-09', '2019-03-10', '2019-03-16', '2019-03-17', '2019-03-23', '2019-03-24', '2019-03-30', '2019-03-31', '2019-04-05', '2019-04-06', '2019-04-07', '2019-04-13', '2019-04-14', '2019-04-20', '2019-04-21', '2019-04-27', '2019-05-01', '2019-05-02', '2019-05-03', '2019-05-04', '2019-05-11', '2019-05-12', '2019-05-18', '2019-05-19', '2019-05-25', '2019-05-26', '2019-06-01', '2019-06-02', '2019-06-07', '2019-06-08', '2019-06-09', '2019-06-15', '2019-06-16', '2019-06-22', '2019-06-23', '2019-06-29', '2019-06-30', '2019-07-06', '2019-07-07', '2019-07-13', '2019-07-14', '2019-07-20', '2019-07-21', '2019-07-27', '2019-07-28', '2019-08-03', '2019-08-04', '2019-08-10', '2019-08-11', '2019-08-17', '2019-08-18', '2019-08-24', '2019-08-25', '2019-08-31', '2019-09-01', '2019-09-07', '2019-09-08', '2019-09-13', '2019-09-14', '2019-09-15', '2019-09-21', '2019-09-22', '2019-09-28', '2019-10-01', '2019-10-02', '2019-10-03', '2019-10-04', '2019-10-05', '2019-10-06', '2019-10-07', '2019-10-13', '2019-10-19', '2019-10-20', '2019-10-26', '2019-10-27', '2019-11-02', '2019-11-03', '2019-11-09', '2019-11-10', '2019-11-16', '2019-11-17', '2019-11-23', '2019-11-24', '2019-11-30', '2019-12-01', '2019-12-07', '2019-12-08', '2019-12-14', '2019-12-15', '2019-12-21', '2019-12-22', '2019-12-28', '2019-12-29'];

function afterWorkDay($start_timestamp='',$add_workday_num='',$holiday=[]){
    //实际工作时间数组
    $workday=array();
    $i=0;
    //判断实际工作时间数组的长度
    while(count($workday)<intval($add_workday_num)){
        $i++;
        $onewdate=date('Y-m-d',($start_timestamp)+$i*(60*60*24));
        //非节假日添加实际工作时间数组
        if(!in_array($onewdate,$holiday)){
            $workday[]=$onewdate;
        }
    }
    return date('Y-m-d',($start_timestamp)+$i*(60*60*24));
}

$day = $_GET['day'];
$date = $_GET['date'];
$day = (int)$day - 1;
$start_time=strtotime($date);
//计算N个工作日后的时间 $N-1对应共N天
echo afterWorkDay($start_time,$day,$holiday);

PHP获取法定节假日接口

<?php
// 过慢,暂不使用 http://api.goseek.cn/Tools/holiday?date=20201002
// 正常工作日对应结果为 0, 法定节假日对应结果为 1, 节假日调休补班对应的结果为 2,休息日对应结果为 3
// 使用:http://tool.bitefu.net/jiari/?d=
// 工作日对应结果为 0, 休息日对应结果为 1, 节假日对应的结果为 2
$arr=[];
$start=strtotime('20191028');
for ($i=0; $i < 100; $i++) { 
    $now = $start+86400*$i;
    $day = date('Ymd', $now);
    $res = https_request("http://tool.bitefu.net/jiari/?d=".$day);
    if($res==1||$res==2){
        file_put_contents('holiday.txt', $day.PHP_EOL, FILE_APPEND);
    }
    usleep(300);
}

function https_request($url, $data = null){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($curl, CURLOPT_TIMEOUT,6);
    if (!empty($data)){
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($curl);
    curl_close($curl);
    return $output;
}