<?php

class Open{
    use mytrate;
    public function actionQuery_token()
    {
        $params=file_get_contents('php://input');
        $params=json_decode($params,true);
        return $params;
        self::writeLog('query_token.txt',$params);
        $OperatorID=empty($params['OperatorID'])? '':$params['OperatorID'];
        $checkParams=self::checkParams($params);
        if($checkParams!=2){
            return ['Msg'=>$checkParams.'为空','Ret'=>4003,'Data'=>['Status'=>1]];
        }
        $re=self::fillParams($params['OperatorID']);
        if($re==1)
            return ['Msg'=>'OperatorID不存在','Ret'=>4003,'Data'=>['Status'=>1]];
        $checkSig=self::checkSig($OperatorID,$params);
        if($checkSig==1)
            return self::encodeData(['OperatorID'=>$OperatorID,'SuccStat'=>1,'FailReason'=>4],4001,'签名错误');

        $data=self::decryptString($params['Data']);
        $datas=json_decode($data,true);
        if(isset($datas['OperatorID'])&&isset($datas['OperatorSecret'])){
            if(($datas['OperatorID']==$OperatorID)&&($datas['OperatorSecret']==self::$OperatorSecret)){
                $AccessToken=self::getStr();
                $redis=Common::createRedis();
                $key='token-'.self::$Owner.'-';
                $redis->set($key,$AccessToken,86400);
                $strr=['OperatorID'=>$OperatorID,'SuccStat'=>0,'AccessToken'=>$AccessToken,
                    'TokenAvailableTime'=>86400,'FailReason'=>0];
                self::writeLog('query_token.txt',$strr);
                return self::encodeData($strr,0);
            }
            $re=['OperatorID'=>$OperatorID,'SuccStat'=>1,'FailReason'=>5];
            return self::encodeData($re,4003,'OperatorID,Data错误');
        }
        $re=['OperatorID'=>$OperatorID,'SuccStat'=>1,'FailReason'=>6];
        return self::encodeData($re,4003,'OperatorID,Data缺失');
    }

    public function actionNotification_stationstatus(){
        $receive=self::pushCheck();
        if(isset($receive['code'])&&$receive['code']==200){
            $da=$receive['data']['ConnectorStatusInfo'];
            if(isset($da['ConnectorID'])&&isset($da['Status'])){
                $redis=Common::createRedis();
                $key=self::$Owner.'--'.$da['ConnectorID'];
                $status=$da['Status'];
                $redis->set($key,$status);
                $result=1;
//                self::writeLog('change_status.txt',$da);
                if($result){
                    return self::encodeData(['Status'=>0],0);
                }else{
                    return self::encodeData(['Status'=>1],0);
                }
            }else{
                return self::encodeData(['Status'=>1],4004,'Aes加密错误');
            }
        }else{
            return $receive;
        }
    }

}