欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

php判断是否是周一到周六 节假日顺延

程序员文章站 2022-05-16 18:43:09
...
/**
     * 
     * @param type $url
     * @param type $type
     * @param type $arr
     * @return type
     */
    public function http_curl($url, $type = 'get', $arr = '') {

        if($arr){
            $o = "";
            foreach ( $arr as $k => $v ) 
            { 
                $o.= "$k=" . urlencode( $v ). "&" ;
            }
            $arr = substr($o,0,-1);
        }
        
        $ch = curl_init();
        
        $user_agent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36";
        curl_setopt($ch, CURLOPT_USERAGENT,$user_agent);
        curl_setopt($ch, CURLOPT_URL, $url); //设置访问的地址
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //获取的信息返回
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        if ($type == 'post') {
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $arr);
        }
        $output = curl_exec($ch); //采集
        if (curl_error($ch)) {
            return curl_error($ch);
        }
        return $output;
        
    }
    
    
    
    /**
     * 判断当天是否是节假日或者周日
     * https://www.cnblogs.com/luqiang213917/p/9638801.html   
     * http://www.easybots.cn/holiday_api.net
     * https://www.cnblogs.com/clschao/articles/7116412.html
     */
    public function judge_holiday(  ) {
        
        $t = time();
        
        $date = date( "Y-m-d" , $t );
        $date = str_replace("-", "", $date);
        
        $week = date( "w" , $t );
        
        if( $week == 0 ){
            return false;
        }
        
        
        //正常工作日对应结果为 0, 法定节假日对应结果为 1, 节假日调休补班对应的结果为 2,休息日对应结果为 3 
        $url = "http://api.goseek.cn/Tools/holiday?date=".$date;
        $ret = $this->http_curl($url);
        if( !$ret ){
            $ret = json_decode($ret,true);
            if( $week==6 && $ret==1 ){
                return false;
            }else{
                return true;
            }
        }
        
        return false;
        
    }