<?php

namespace fastphp\base;

/**
 * 控制器基类
 * Class Controller
 * @package fastphp\base
 */
class Controller
{
    public $userinfo;

    //初始化属性，实例化对应模型
    public function __construct($controller,$action)
    {
        $data = empty(json_decode(file_get_contents("php://input"),true))?$_POST:json_decode(file_get_contents("php://input"),true);
        $getPayload = false;
        if(isset($data['cookie'])){
            $cookie = explode('; ',$data['cookie']);
            $token = '';
            foreach($cookie as $k => $v){
                $find_token = explode('=',$v);
                if($find_token[0] == 'token'){
                    $token = $find_token[1];
                    break;
                }
            }
            $jwt = new Jwt('hncore_yh_lzh_20f_2020_READY');
            $getPayload=$jwt->verifyToken($token);
            
        } else {
            if(isset($_SERVER['HTTP_TOKEN'])){
                
                $jwt = new Jwt('etor_yh_lzh_20f_2020_YES');
                $getPayload=$jwt->verifyToken($_SERVER['HTTP_TOKEN']);

                $ip = getIp();
                $ip_limit = trim(file_get_contents('/var/www/ip/ip'));
                // if ((strpos($ip_limit, $ip) == false)&&$ip!=$ip_limit&&$getPayload['OperaterID']<100000) {
                if ((strpos($ip_limit, $ip) == false)&&$getPayload['OperaterID']<100000) {
                    die;
                }
            } else {
                die;
            }
        }
        
        
        if(!$getPayload){
            die;
        }
        $this->userinfo = $getPayload;
    }
}