<?php
namespace Home\Controller;
vendor('tencentsdk.TCloudAutoLoader');

use Think\Controller;
use SignedCookie;
use Zhida\OAuthHelperV3;
use Think\Upload\Driver\Qiniu\QiniuStorage;

use Think\Log;

class IndexController extends Controller
{
    private $auth_type = OAuthHelperV3::SCOPE_USERINFO;
    private $cookie_uid_key = 'skp-rotor-v1';
    private $debug = 1;
    private $today;
    use ControllerTrait;
    
    public function index()
    {
      session_start();
      $_SESSION['joinTime'] = time();
      $num = M('num')->where('id=1')->select();
      $num = $num[0]['num'];
      $this->assign('num',$num);
        
      $this->display();
    }

    public function addNum(){
      if(time() > 1584720000)
      {
        header("HTTP/1.0 404 Not Found");
        exit;
      }
      $referer = $_SERVER['HTTP_REFERER'];
      $refererInfo = parse_url( $referer );
      if( $refererInfo['host'] != $_SERVER['HTTP_HOST'] )
      {
          header("HTTP/1.0 404 Not Found");
          exit;
      }
      session_start();
      if(!$_SESSION['joinTime'] || time() - $_SESSION['joinTime'] < 2)
      {
          header("HTTP/1.0 404 Not Found");
          exit;
      }
      $name = $_POST['name'];
      $business = $_POST['business'];
      if($name != '')
      {
        M('num')->where('id=1')->setInc('num');
        M('info')->add(array(
          'name' => $name,
          'business' => $business,
          'addtime' => time()
        ));
      }
      
    }
}