Hàm xóa toàn bộ dữ liệu Session

@author: 713uk13m <dev@nguyenanhung.com>
@time  : 2019-02-18 10:15
336190
public function sessionDestroyer()
    {
        if (isset($this->objectSession) && $this->objectSession != NULL && is_object($this->objectSession)) {
            $this->logger->info(__FUNCTION__, 'Destroy Session with CI Session Class');
            $this->objectSession->sess_destroy();
        } else {
            $this->logger->info(__FUNCTION__, 'Destroy Session with The Http Foundation Component');
            $this->session->invalidate();
        }
    }
897574
public static function getSession() {
		// 单例模式
		if (self::$instance != NULL && is_object(self::$instance)) {
			return self::$instance;
		}
		
		// 获取数据库配置信息
		if (!Config::has('session')) {
			throw new \Fasim\Core\Exception('Can not find session info in config.php', 1000);
			exit();
		}
		
		$config = Config::get('session');

		$sessionObj = null;
		switch ($config['type']) {
			case "cache" :
				$sessionObj = new CacheSession($config['prefix']);
				break;
			default:
				$sessionObj = new PHPSession($config['prefix']);
				break;
		}
		
		
		self::$instance = $sessionObj;
		return self::$instance;
	}
404577
def _talk2modjk(name, lbn, target, action, profile='default', tgt_type='glob'):
    '''
    
    '''

    ret = {'name': name,
           'result': True,
           'changes': {},
           'comment': ''}

    action_map = {
        'worker_stop': 'STP',
        'worker_disable': 'DIS',
        'worker_activate': 'ACT',
    }

    # Check what needs to be done
    status = _worker_status(
        target, name, action_map[action], profile, tgt_type
    )
    if not status['result']:
        ret['result'] = False
        ret['comment'] = ('no servers answered the published command '
                          'modjk.worker_status')
        return ret
    if status['errors']:
        ret['result'] = False
        ret['comment'] = ('the following balancers could not find the '
                          'worker {0}: {1}'.format(name, status['errors']))
        return ret
    if not status['wrong_state']:
        ret['comment'] = ('the worker is in the desired activation state on '
                          'all the balancers')
        return ret
    else:
        ret['comment'] = ('the action {0} will be sent to the balancers '
                          '{1}'.format(action, status['wrong_state']))
        ret['changes'] = {action: status['wrong_state']}

    if __opts__['test']:
        ret['result'] = None
        return ret

    # Send the action command to target
    response = _send_command(action, name, lbn, target, profile, tgt_type)
    ret['comment'] = response['msg']
    ret['result'] = response['code']
    return ret
1028202
function (cfg) {
    this._cfg = merge({
      delay: 400
    }, cfg)

    // 事件订阅数组
    this._subs = {
      on: [],
      after: []
    }

    // 当前信息
    this.info = this.getInfo()

    // 绑定事件回调上下文
    this._onWinOrientationChange = bind(this._onWinOrientationChange, this)

    // 绑定窗口切换事件
    window.addEventListener(EVT_ORIENTATION_CHANGE, this._onWinOrientationChange, false)
  }
326456
function connect(options) {
    let conn = mysql.createConnection(options),
        query = makeQuery(conn),
        stream = makeStream(conn);

    // 返回接口
    return { query, stream };
}
639521
function execute( op ) {
		writeToA = 0;
		address = 0xf0000;

		debugPC = PC;

		switch( op ) {
		case 0x3e:
			absoluteIndexedX();
			ROL();
			burn(7);
			break;
		case 0x3d:
			absoluteIndexedX();
			AND();
			burn(4);
			break;
		case 0x85:
			zeroPage();
			STA();
			burn(3);
			break;
		case 0x84:
			zeroPage();
			STY();
			burn(3);
			break;
		case 0x28:
			implied();
			PLP();
			burn(4);
			break;
		case 0x29:
			immediate();
			AND();
			burn(2);
			break;
		case 0xf8:
			implied();
			SED();
			burn(2);
			break;
		case 0xf9:
			absoluteIndexedY();
			SBC();
			burn(4);
			break;
		case 0xf6:
			zeroPageIndexedX();
			INC();
			burn(6);
			break;
		case 0x20:
			absolute();
			JSR();
			burn(6);
			break;
		case 0x21:
			indexedIndirectX();
			AND();
			burn(6);
			break;
		case 0x26:
			zeroPage();
			ROL();
			burn(5);
			break;
		case 0x86:
			zeroPage();
			STX();
			burn(3);
			break;
		case 0x24:
			zeroPage();
			BIT();
			burn(3);
			break;
		case 0x25:
			zeroPage();
			AND();
			burn(2);
			break;
		case 0x35:
			zeroPageIndexedX();
			AND();
			burn(3);
			break;
		case 0x36:
			zeroPageIndexedX();
			ROL();
			burn(6);
			break;
		case 0x31:
			indirectIndexedY();
			AND();
			burn(5);
			break;
		case 0x30:
			relative();
			BMI();
			burn(2);
			break;
		case 0x39:
			absoluteIndexedY();
			AND();
			burn(4);
			break;
		case 0x38:
			implied();
			SEC();
			burn(2);
			break;
		case 0x8c:
			absolute();
			STY();
			burn(4);
			break;
		case 0x2c:
			absolute();
			BIT();
			burn(4);
			break;
		case 0xfd:
			absoluteIndexedX();
			SBC();
			burn(4);
			break;
		case 0xfe:
			absoluteIndexedX();
			INC();
			burn(7);
			break;
		case 0x2d:
			absolute();
			AND();
			burn(4);
			break;
		case 0x2e:
			absolute();
			ROL();
			burn(6);
			break;
		case 0xba:
			implied();
			TSX();
			burn(2);
			break;
		case 0x5e:
			absoluteIndexedX();
			LSR();
			burn(7);
			break;
		case 0x5d:
			absoluteIndexedX();
			EOR();
			burn(4);
			break;
		case 0x40:
			implied();
			RTI();
			burn(6);
			break;
		case 0x41:
			indexedIndirectX();
			EOR();
			burn(6);
			break;
		case 0x45:
			zeroPage();
			EOR();
			burn(3);
			break;
		case 0x46:
			zeroPage();
			LSR();
			burn(5);
			break;
		case 0x48:
			implied();
			PHA();
			burn(3);
			break;
		case 0x49:
			immediate();
			EOR();
			burn(2);
			break;
		case 0xae:
			absolute();
			LDX();
			burn(4);
			break;
		case 0xad:
			absolute();
			LDA();
			burn(4);
			break;
		case 0xac:
			absolute();
			LDY();
			burn(4);
			break;
		case 0xaa:
			implied();
			TAX();
			burn(2);
			break;
		case 0x4a:
			accumulator();
			LSR();
			burn(2);
			break;
		case 0x4c:
			absolute();
			JMP();
			burn(3);
			break;
		case 0x4d:
			absolute();
			EOR();
			burn(4);
			break;
		case 0x4e:
			absolute();
			LSR();
			burn(6);
			break;
		case 0x51:
			indirectIndexedY();
			EOR();
			burn(5);
			break;
		case 0x50:
			relative();
			BVC();
			burn(2);
			break;
		case 0x56:
			zeroPageIndexedX();
			LSR();
			burn(6);
			break;
		case 0x55:
			zeroPageIndexedX();
			EOR();
			burn(4);
			break;
		case 0x9a:
			implied();
			TXS();
			burn(2);
			break;
		case 0xe5:
			zeroPage();
			SBC();
			burn(3);
			break;
		case 0x59:
			absoluteIndexedY();
			EOR();
			burn(4);
			break;
		case 0x58:
			implied();
			CLI();
			burn(2);
			break;
		case 0x2a:
			accumulator();
			ROL();
			burn(2);
			break;
		case 0xa9:
			immediate();
			LDA();
			burn(2);
			break;
		case 0xa8:
			implied();
			TAY();
			burn(2);
			break;
		case 0xa6:
			zeroPage();
			LDX();
			burn(3);
			break;
		case 0xa5:
			zeroPage();
			LDA();
			burn(3);
			break;
		case 0xa2:
			immediate();
			LDX();
			burn(2);
			break;
		case 0xa1:
			indexedIndirectX();
			LDA();
			burn(6);
			break;
		case 0xa0:
			immediate();
			LDY();
			burn(2);
			break;
		case 0xa4:
			zeroPage(0);
			LDY();
			burn(3);
			break;
		case 0xf5:
			zeroPageIndexedX();
			SBC();
			burn(4);
			break;
		case 0x7e:
			absoluteIndexedX();
			ROR();
			burn(7);
			break;
		case 0x7d:
			absoluteIndexedX();
			ADC();
			burn(4);
			break;
		case 0xf0:
			relative();
			BEQ();
			burn(2);
			break;
		case 0x68:
			implied();
			PLA();
			burn(4);
			break;
		case 0x69:
			immediate();
			ADC();
			burn(2);
			break;
		case 0x66:
			zeroPage();
			ROR();
			burn(5);
			break;
		case 0x65:
			zeroPage();
			ADC();
			burn(3);
			break;
		case 0x60:
			implied();
			RTS();
			burn(6);
			break;
		case 0x61:
			indexedIndirectX();
			ADC();
			burn(6);
			break;
		case 0xce:
			absolute();
			DEC();
			burn(6);
			break;
		case 0xcd:
			absolute();
			CMP();
			burn(4);
			break;
		case 0xb8:
			implied();
			CLV();
			burn(2);
			break;
		case 0xb9:
			absoluteIndexedY();
			LDA();
			burn(4);
			break;
		case 0xca:
			implied();
			DEX();
			burn(2);
			break;
		case 0xcc:
			absolute();
			CPY();
			burn(4);
			break;
		case 0xb0:
			relative();
			BCS();
			burn(2);
			break;
		case 0xb1:
			indirectIndexedY();
			LDA();
			burn(5);
			break;
		case 0xb6:
			zeroPageIndexedY();
			LDX();
			burn(4);
			break;
		case 0xb4:
			zeroPageIndexedX();
			LDY();
			burn(4);
			break;
		case 0xb5:
			zeroPageIndexedX();
			LDA();
			burn(4);
			break;
		case 0x8a:
			implied();
			TXA();
			burn(2);
			break;
		case 0x6d:
			absolute();
			ADC();
			burn(4);
			break;
		case 0x6e:
			absolute();
			ROR();
			burn(6);
			break;
		case 0x6c:
			indirect();
			JMP();
			burn(5);
			break;
		case 0x6a:
			accumulator();
			ROR();
			burn(2);
			break;
		case 0x79:
			absoluteIndexedY();
			ADC();
			burn(4);
			break;
		case 0x78:
			implied();
			SEI();
			burn(2);
			break;
		case 0x71:
			indirectIndexedY();
			ADC();
			burn(5);
			break;
		case 0x70:
			relative();
			BVS();
			burn(2);
			break;
		case 0x75:
			zeroPageIndexedX();
			ADC();
			burn(4);
			break;
		case 0x76:
			zeroPageIndexedX();
			ROR();
			burn(6);
			break;
		case 0xc5:
			zeroPage();
			CMP();
			burn(3);
			break;
		case 0xc4:
			zeroPage();
			CPY();
			burn(3);
			break;
		case 0xc6:
			zeroPage();
			DEC();
			burn(5);
			break;
		case 0xc1:
			indexedIndirectX();
			CMP();
			burn(6);
			break;
		case 0xc0:
			immediate();
			CPY();
			burn(2);
			break;
		case 0xbc:
			absoluteIndexedX();
			LDY();
			burn(4);
			break;
		case 0xe4:
			zeroPage();
			CPX();
			burn(3);
			break;
		case 0xc9:
			immediate();
			CMP();
			burn(2);
			break;
		case 0xc8:
			implied();
			INY();
			burn(2);
			break;
		case 0xbd:
			absoluteIndexedX();
			LDA();
			burn(4);
			break;
		case 0xbe:
			absoluteIndexedY();
			LDX();
			burn(4);
			break;
		case 0xf1:
			indirectIndexedY();
			SBC();
			burn(5);
			break;
		case 0xe9:
			immediate();
			SBC();
			burn(2);
			break;
		case 0xd0:
			relative();
			BNE();
			burn(2);
			break;
		case 0xd1:
			indirectIndexedY();
			CMP();
			burn(5);
			break;
		case 0x9d:
			absoluteIndexedX();
			STA();
			burn(5);
			break;
		case 0x08:
			implied();
			PHP();
			burn(3);
			break;
		case 0xd5:
			zeroPageIndexedX();
			CMP();
			burn(4);
			break;
		case 0xd6:
			zeroPageIndexedX();
			DEC();
			burn(6);
			break;
		case 0xd8:
			implied();
			CLD();
			burn(2);
			break;
		case 0xd9:
			absoluteIndexedY();
			CMP();
			burn(4);
			break;
		case 0x06:
			zeroPage();
			ASL();
			burn(5);
			break;
		case 0x00:
			implied();
			BRK();
			burn(7);
			break;
		case 0x01:
			indexedIndirectX();
			ORA();
			burn(6);
			break;
		case 0xec:
			absolute();
			CPX();
			burn(4);
			break;
		case 0x05:
			zeroPage();
			ORA();
			burn(2);
			break;
		case 0xea:
			implied();
			NOP();
			burn(2);
			break;
		case 0x81:
			indexedIndirectX();
			STA();
			burn(6);
			break;
		case 0xee:
			absolute();
			INC();
			burn(6);
			break;
		case 0xed:
			absolute();
			SBC();
			burn(4);
			break;
		case 0x1e:
			absoluteIndexedX();
			ASL();
			burn(7);
			break;
		case 0x1d:
			absoluteIndexedX();
			ORA();
			burn(4);
			break;
		case 0x88:
			implied();
			DEY();
			burn(2);
			break;
		case 0x09:
			immediate();
			ORA();
			burn(2);
			break;
		case 0x8d:
			absolute();
			STA();
			burn(4);
			break;
		case 0x8e:
			absolute();
			STX();
			burn(4);
			break;
		case 0xe1:
			indexedIndirectX();
			SBC();
			burn(6);
			break;
		case 0xe0:
			immediate();
			CPX();
			burn(2);
			break;
		case 0xe6:
			zeroPage();
			INC();
			burn(5);
			break;
		case 0x19:
			absoluteIndexedY();
			ORA();
			burn(4);
			break;
		case 0x18:
			implied();
			CLC();
			burn(2);
			break;
		case 0x16:
			zeroPageIndexedX();
			ASL();
			burn(6);
			break;
		case 0x15:
			zeroPageIndexedX();
			ORA();
			burn(3);
			break;
		case 0xe8:
			implied();
			INX();
			burn(2);
			break;
		case 0x11:
			indirectIndexedY();
			ORA();
			burn(5);
			break;
		case 0x10:
			relative();
			BPL();
			burn(2);
			break;
		case 0x96:
			zeroPageIndexedY();
			STX();
			burn(4);
			break;
		case 0x95:
			zeroPageIndexedX();
			STA();
			burn(4);
			break;
		case 0x94:
			zeroPageIndexedX();
			STY();
			burn(4);
			break;
		case 0xdd:
			absoluteIndexedX();
			CMP();
			burn(4);
			break;
		case 0xde:
			absoluteIndexedX();
			DEC();
			burn(7);
			break;
		case 0x91:
			indirectIndexedY();
			STA();
			burn(6);
			break;
		case 0x90:
			relative();
			BCC();
			burn(2);
			break;
		case 0x0d:
			absolute();
			ORA();
			burn(4);
			break;
		case 0x0e:
			absolute();
			ASL();
			burn(6);
			break;
		case 0x0a:
			accumulator();
			ASL();
			burn(2);
			break;
		case 0x99:
			absoluteIndexedY();
			STA();
			burn(5);
			break;
		case 0x98:
			implied();
			TYA();
			burn(2);
			break;
		default:
			PC += 1;
			//throw new Error("Invalid opcode! " + op);
		}
	}
1015541
function EventSystem() {
	//索引要用甚麼?
	this.iEventInx = "";
	//事件名稱
	this.strEventName = "";
	//事件等級 1:一般 2:警告 3:急迫
	this.iEventLevel = 1;
	//事件開關(就開跟關)
	this.bSwitch = false;
	//觸發群組
	this.groupID = "";
	//信箱通知勾選
	this.bEmail = false;
	//簡訊通知
	this.bSMS = false;
	//觸發快照
	this.bSnapshot = false;
	//電子郵件通知管理者
	this.bEmailAdmin = false;
	//簡訊通知管理者
	this.bSMSAdmin = false;
	//畫面外框閃爍紅色線框
	this.bScreenFlash = false;
	//報警提示
	this.bCallPolice = false;
	//畫面彈跳
	this.bScreenBounce = false;
	//回播跳出
	this.bPlaybackJump = false;
	//FTP上傳
	this.bFTP = false;
	//可設定一首MP3上傳檔案(每個事件獨立音檔)。
	this.strMp3 = "";
	//可讓使用者設定播放秒數(開始)
	this.iMp3PlayBin = 0;
	//可讓使用者設定播放秒數(結束)
	this.iMp3PlayEnd = 0;
	//Loop
	this.bLoop = false;
}
81314
public function send($fd, $data, $ifPack = false, $topic = null)
    {
        if (!$this->portManager->websocket_enable) {
            return parent::send($fd, $data, $ifPack, $topic);
        }
        $fdinfo = $this->server->connection_info($fd);
        if (empty($fdinfo)) return false;
        $server_port = $fdinfo['server_port'];
        //允许数据监控的情况就pub
        if ($this->allow_MonitorFlowData) {
            $uid = $this->getUidFromFd($fd);
            if (!empty($uid)) {
                try {
                    get_instance()->pub('$SYS_CHANNEL/' . "$uid/send", $data);
                } catch (\Throwable $e) {

                }
            }
        }
        if ($ifPack) {
            $pack = $this->portManager->getPack($server_port);
            if ($pack != null) {
                $data = $pack->pack($data, $topic);
            }
        }
        if ($this->isWebSocket($fdinfo)) {
            return $this->server->push($fd, $data, $this->portManager->getOpCode($server_port));
        } else {
            return $this->server->send($fd, $data);
        }
    }
1020686
private function startCommon(): void
    {
        if (self::$app !== null) {
            return;
        }
        self::$app = $this;
        // 加载框架配置文件
        $config = DataMap::loadFromPhpFile($this->mvcSourcePath . '/../config.inc.php');
        // 应用配置
        if ($this->config === null) {
            $appConfigFile = APP_CONFIG_PATH . '/./config.inc.php';
            if (is_file($appConfigFile)) {
                $appConfig = DataMap::loadFromPhpFile($appConfigFile);
                $config->mergeData($appConfig);
            }
        } else {
            $config->mergeData($this->config);
        }
        $this->config = $config;
        $this->loadContainer();
    }
1164385
function () {
            this._handler = $B.bind(function (e) {
                //DONE
                if ( this.xhr.readyState !== 4 ) return false;
                var evt = {target: this, xml: this.xhr.responseXML, text: this.xhr.responseText, status: this.xhr.status, statusText: this.xhr.statusText, data: this._data};
    
                if ( this.xhr.status == 200 ) {
                    this.dispatch( 'complete', evt );
                } else {
                    this.dispatch( 'error', evt );
                }
    
                this._removeEvents();
            }, this);
    
            //"Microsoft.XMLHTTP", "MSXML2.XMLHTTP.3.0"는 readyState 3를 지원하지 않는다.
            var i, activeXids = ['MSXML2.XMLHTTP.6.0', 'MSXML3.XMLHTTP', 'Microsoft.XMLHTTP', 'MSXML2.XMLHTTP.3.0'],
                activeXidNum = activeXids.length;
    
            if ( window.XMLHttpRequest ) {
                this.xhr = new XMLHttpRequest();
            } else {
                for ( i = 0; i < activeXidNum; ++i ) {
                    try {
                        this.xhr = new ActiveXObject( activeXids[i] );
                        break;
                    } catch (e) {}
                }
            }
        }
742792
function (fnName, args) {
            var cmdName = args[0].toLowerCase(),
                cmd, cmdFn;
            cmd = this.commands[cmdName] || UE.commands[cmdName];
            cmdFn = cmd && cmd[fnName];
            //没有querycommandstate或者没有command的都默认返回0
            if ((!cmd || !cmdFn) && fnName == 'queryCommandState') {
                return 0;
            } else if (cmdFn) {
                return cmdFn.apply(this, args);
            }
        }
728956
function addListener(resolver, status, callback) {
        if (resolver.status === status) {
            // 设置延迟
            // 为了让then函数先返回再执行回调
            // see #2.2.4
            Resolver.nextTick(
                function () {
                    callback(resolver.data);
                }
            );
        }
        else if (status === STATUS.FULFILLED) {
            resolver.fulfillList.push(callback);
        }
        else if (status === STATUS.REJECTED) {
            resolver.rejectList.push(callback);
        }
    }
1092388
function () {
	var trans = [
		[ "zh_tw" , "hello" ]
	];
		
	for ( var i in trans){
		console.log(i);
	}
	
	SR.DB.setData(i18nDB, {zh_tw:{hello: "哈囉"}}, function(){}, function(){});
	SR.DB.setData(i18nDB, {zh_tw:{say: "說"}}, function(){}, function(){});
	SR.DB.setData(i18nDB, {zh_tw:{see: "看"}}, function(){}, function(){});
	//SR.DB.setData("language", {"zh_tw":{"hello": "哈囉"}}, function(){}, function(){});
}
1007996
@Override
    protected void generateDao(TableDefinition table, JavaWriter out1) {
        UniqueKeyDefinition key = table.getPrimaryKey();
        if (key == null) {
            logger.info("Skipping DAO generation", out1.file().getName());
            return;
        }
        VertxJavaWriter out = (VertxJavaWriter) out1;
        generateDAO(key, table, out);
    }
355500
public function onReceive($cli, $data)
    {
        $message_object = $this->message_read($data);
        switch ($message_object->getMessageType()) {
            case Message::CONNACK:
                Debug::Log(Debug::INFO, 'connect(): connected=1');
                # save current time for ping
                $this->connected_time = time();
                # Call connect
                $this->call_handler('connack', array($this, $message_object));
                break;
            case Message::PINGRESP:
                array_shift($this->ping_queue);
                Debug::Log(Debug::INFO, 'loop(): received PINGRESP');

                $this->last_ping_time = time();

                break;

            # Process PUBLISH
            # in: Client <- Server, Step 1
            case Message::PUBLISH:
                /**
                 * @var Message\PUBLISH $message_object
                 */

                Debug::Log(Debug::INFO, 'loop(): received PUBLISH');

                $qos = $message_object->getQoS();

                $msgid = $message_object->getMsgID();

                if ($qos == 0) {
                    Debug::Log(Debug::DEBUG, 'loop(): PUBLISH QoS=0 PASS');
                    # call handler
                    //0直接执行
                    $this->call_handler('publish', array($this, $message_object));
                    # Do nothing
                } else if ($qos == 1) {
                    # call handler
                    //1先执行再回复，可以结合飞行窗口实现顺序发送
                    $this->call_handler('publish', array($this, $message_object));
                    # PUBACK
                    $puback_bytes_written = $this->simpleCommand(Message::PUBACK, $msgid);
                    Debug::Log(Debug::DEBUG, 'loop(): PUBLISH QoS=1 PUBACK written=' . $puback_bytes_written);

                } else if ($qos == 2) {
                    # PUBREC
                    $pubrec_bytes_written = $this->simpleCommand(Message::PUBREC, $msgid);
                    Debug::Log(Debug::DEBUG, 'loop(): PUBLISH QoS=2 PUBREC written=' . $pubrec_bytes_written);
                    $this->cmdstore->addWait(
                        Message::PUBREL,
                        $msgid,
                        array(
                            'msgid' => $msgid,
                            'retry_after' => time() + $this->retry_timeout,
                        )
                    );
                    # call handler
                    //2先回复收到再执行
                    $this->call_handler('publish', array($this, $message_object));
                } else {
                    # wrong packet
                    Debug::Log(Debug::WARN, 'loop(): PUBLISH Invalid QoS');
                }
                break;

            # Process PUBACK
            # in: Client -> Server, QoS = 1, Step 2
            case Message::PUBACK:

                /**
                 * @var Message\PUBACK $message_object
                 */

                # Message has been published (QoS 1)

                $msgid = $message_object->getMsgID();
                Debug::Log(Debug::INFO, 'loop(): received PUBACK msgid=' . $msgid);
                # Verify Packet Identifier
                $this->call_handler('puback', array($this, $message_object));

                $this->cmdstore->delWait(Message::PUBACK, $msgid);
                break;

            # Process PUBREC, send PUBREL
            # in: Client -> Server, QoS = 2, Step 2
            case Message::PUBREC:
                /**
                 * @var Message\PUBREC $message_object
                 */

                $msgid = $message_object->getMsgID();
                Debug::Log(Debug::INFO, 'loop(): received PUBREC msgid=' . $msgid);

                $this->cmdstore->delWait(Message::PUBREC, $msgid);

                # PUBREL
                Debug::Log(Debug::INFO, 'loop(): send PUBREL msgid=' . $msgid);
                $pubrel_bytes_written = $this->simpleCommand(Message::PUBREL, $msgid);


                $this->cmdstore->addWait(
                    Message::PUBCOMP,
                    $msgid,
                    array(
                        'msgid' => $msgid,
                        'retry_after' => time() + $this->retry_timeout,
                    )
                );

                Debug::Log(Debug::DEBUG, 'loop(): PUBREL QoS=2 PUBREL written=' . $pubrel_bytes_written);

                $this->call_handler('pubrec', array($this, $message_object));
                break;


            # Process PUBREL
            # in: Client <- Server, QoS = 2, Step 3
            case Message::PUBREL:
                /**
                 * @var Message\PUBREL $message_object
                 */

                $msgid = $message_object->getMsgID();
                Debug::Log(Debug::INFO, 'loop(): received PUBREL msgid=' . $msgid);

                $this->cmdstore->delWait(Message::PUBREL, $msgid);

                # PUBCOMP
                Debug::Log(Debug::INFO, 'loop(): send PUBCOMP msgid=' . $msgid);
                $pubcomp_bytes_written = $this->simpleCommand(Message::PUBCOMP, $msgid);

                Debug::Log(Debug::DEBUG, 'loop(): PUBREL QoS=2 PUBCOMP written=' . $pubcomp_bytes_written);

                $this->call_handler('pubrel', array($this, $message_object));
                break;

            # Process PUBCOMP
            # in: Client -> Server, QoS = 2, Step 4
            case Message::PUBCOMP:

                # Message has been published (QoS 2)

                /**
                 * @var Message\PUBCOMP $message_object
                 */

                $msgid = $message_object->getMsgID();
                Debug::Log(Debug::INFO, 'loop(): received PUBCOMP msgid=' . $msgid);

                $this->cmdstore->delWait(Message::PUBCOMP, $msgid);

                $this->call_handler('pubcomp', array($this, $message_object));
                break;

            # Process SUBACK
            case Message::SUBACK:

                /**
                 * @var Message\SUBACK $message_object
                 */

                $return_codes = $message_object->getReturnCodes();
                $msgid = $message_object->getMsgID();
                Debug::Log(Debug::INFO, 'loop(): received SUBACK msgid=' . $msgid);

                if (!isset($this->subscribe_awaits[$msgid])) {
                    Debug::Log(Debug::WARN, 'loop(): SUBACK Message identifier not found: ' . $msgid);
                } else {
                    if (count($this->subscribe_awaits[$msgid]) != count($return_codes)) {
                        Debug::Log(Debug::WARN, 'loop(): SUBACK returned qos list doesn\'t match SUBSCRIBE');
                    } else {
                        # save max_qos list from suback
                        foreach ($return_codes as $k => $tqos) {
                            if ($return_codes != 0x80) {
                                $this->topics[$this->subscribe_awaits[$msgid][$k][0]] = $tqos;
                            } else {
                                Debug::Log(
                                    Debug::WARN,
                                    "loop(): Failed to subscribe '{$this->subscribe_awaits[$msgid][$k][0]}'. Request QoS={$this->subscribe_awaits[$msgid][$k][1]}"
                                );
                            }
                        }
                    }
                }

                $this->call_handler('suback', array($this, $message_object));

                break;

            # Process UNSUBACK
            case Message::UNSUBACK:
                /**
                 * @var Message\UNSUBACK $message_object
                 */

                $msgid = $message_object->getMsgID();
                Debug::Log(Debug::INFO, 'loop(): received UNSUBACK msgid=' . $msgid);

                if (!isset($this->unsubscribe_awaits[$msgid])) {
                    Debug::Log(Debug::WARN, 'loop(): UNSUBACK Message identifier not found ' . $msgid);
                } else {
                    foreach ($this->unsubscribe_awaits[$msgid] as $topic) {
                        Debug::Log(Debug::WARN, "loop(): Unsubscribe topic='{$topic}'");
                        unset($this->topics[$topic]);
                    }
                }

                $this->call_handler('unsuback', array($this, $message_object));
                break;

            default:
                return;
        }
    }
339422
public function reply($msg)
    {
        // 获取消息类型
        $msg_type = '';
        if (gettype($msg)=='string') {
            $msg_type = 'text_simple';
        } elseif (gettype($msg)=='array') {
            $msg_type = $msg['type'];
        }

        switch ($msg_type) {
            /**
             * 1.1 回复文本消息(简洁输入)
             *
             * Examples:
             * ```
             * $wechat->reply('hello world!');
             * ```
             */
            case 'text_simple':
                $xml = sprintf('<xml>'.
                        '<ToUserName><![CDATA[%s]]></ToUserName>'.
                        '<FromUserName><![CDATA[%s]]></FromUserName>'.
                        '<CreateTime>%s</CreateTime>'.
                        '<MsgType><![CDATA[text]]></MsgType>'.
                        '<Content><![CDATA[%s]]></Content>'.
                        '</xml>',
                        $this->message->FromUserName,
                        $this->message->ToUserName,
                        time(), 
                        $msg);
                break;

            /**
             * 1.2 回复文本消息
             *
             * Examples:
             * ```
             * $wechat->reply(array(
             *    'type' => 'text',
             *    'content' => '嘿嘿，呵呵~~'
             * ));
             * ```
             */
            case 'text':
                $xml = sprintf('<xml>'.
                        '<ToUserName><![CDATA[%s]]></ToUserName>'.
                        '<FromUserName><![CDATA[%s]]></FromUserName>'.
                        '<CreateTime>%s</CreateTime>'.
                        '<MsgType><![CDATA[text]]></MsgType>'.
                        '<Content><![CDATA[%s]]></Content>'.
                        '</xml>', 
                        $this->message->FromUserName,
                        $this->message->ToUserName,
                        time(), 
                        $msg['content']);
                break;

            /**
             * 2 回复图片消息
             *
             * Examples:
             * ```
             * $wechat->reply(array(
              *     'type' => 'image',
              *    'media_id' => 'Uq7OczuEGEyUu--dYjg7seTm-EJTa0Zj7UDP9zUGNkVpjcEHhl7tU2Mv8mFRiLKC'
             * ));
             * ```
             */
            case 'image':
                $xml = sprintf('<xml>'.
                        '<ToUserName><![CDATA[%s]]></ToUserName>'.
                        '<FromUserName><![CDATA[%s]]></FromUserName>'.
                        '<CreateTime>%s</CreateTime>'.
                        '<MsgType><![CDATA[image]]></MsgType>'.
                        '<Image><MediaId><![CDATA[%s]]></MediaId></Image>'.
                        '</xml>', 
                        $this->message->FromUserName,
                        $this->message->ToUserName,
                        time(), 
                        $msg['media_id']);
                break;

            /**
             * 3 回复语音消息
             *
             * Examples:
             * ```
             * $wechat->reply(array(
              *     'type' => 'voice',
              *    'media_id' => 'rVT43tfDwjh4p1BV2gJ5D7Zl2BswChO5L_llmlphLaTPytcGcguBAEJ1qK4cg4r_'
             * ));
             * ```
             */            
            case 'voice':
                $xml = sprintf('<xml>'.
                        '<ToUserName><![CDATA[%s]]></ToUserName>'.
                        '<FromUserName><![CDATA[%s]]></FromUserName>'.
                        '<CreateTime>%s</CreateTime>'.
                        '<MsgType><![CDATA[voice]]></MsgType>'.
                        '<Voice><MediaId><![CDATA[%s]]></MediaId></Voice>'.
                        '</xml>', 
                        $this->message->FromUserName,
                        $this->message->ToUserName,
                        time(), 
                        $msg['media_id']);
                break;

            /**
             * 4 回复视频消息
             *
             * Examples:
             * ```
             * $wechat->reply(array(
              *    'type' => 'video',
              *    'media_id' => 'yV0l71NL0wtpRA8OMX0-dBRQsMVyt3fspPUzurIS3psi6eWOrb_WlEeO39jasoZ8',
              *    'title' => '视频消息的标题',            //可选
              *    'description' => '视频消息的描述'        //可选
             * ));
             * ```
             */
            case 'video':
                $xml = sprintf('<xml>'.
                        '<ToUserName><![CDATA[%s]]></ToUserName>'.
                        '<FromUserName><![CDATA[%s]]></FromUserName>'.
                        '<CreateTime>%s</CreateTime>'.
                        '<MsgType><![CDATA[video]]></MsgType>'.
                        '<Video>'.
                        '<MediaId><![CDATA[%s]]></MediaId>'.
                        '<Title><![CDATA[%s]]></Title>'.
                        '<Description><![CDATA[%s]]></Description>'.
                        '</Video>'.
                        '</xml>', 
                        $this->message->FromUserName,
                        $this->message->ToUserName,
                        time(), 
                        $msg['media_id'], 
                        isset($msg['title']) ? $msg['title'] : '',
                        isset($msg['description']) ? $msg['description'] : '');
                break;

            /**
             * 5 回复音乐消息
             *
             * Examples:
             * ```
             * $wechat->reply(array(
              *    'type' => 'music',
              *    'title' => '音乐标题',                        //可选
              *    'description' => '音乐描述',                //可选
              *    'music_url' => 'http://me.diary8.com/data/music/2.mp3',        //可选
              *    'hqmusic_url' => 'http://me.diary8.com/data/music/2.mp3',    //可选
              *    'thumb_media_id' => 'O39wW0ZsXCb5VhFoCgibQs5PupFb6VZ2jH5A8gHUJCJz2Qmkrb7objoTue7bGTGQ',
             * ));
             * ```
             */
            case 'music':
                $xml = sprintf('<xml>'.
                        '<ToUserName><![CDATA[%s]]></ToUserName>'.
                        '<FromUserName><![CDATA[%s]]></FromUserName>'.
                        '<CreateTime>%s</CreateTime>'.
                        '<MsgType><![CDATA[music]]></MsgType>'.
                        '<Music>'.
                        '<Title><![CDATA[%s]]></Title>'.
                        '<Description><![CDATA[%s]]></Description>'.
                        '<MusicUrl><![CDATA[%s]]></MusicUrl>'.
                        '<HQMusicUrl><![CDATA[%s]]></HQMusicUrl>'.
                        '<ThumbMediaId><![CDATA[%s]]></ThumbMediaId>'.
                        '</Music>'.
                        '</xml>', 
                        $this->message->FromUserName,
                        $this->message->ToUserName,
                        time(),
                        isset($msg['title']) ? $msg['title'] : '',
                        isset($msg['description']) ? $msg['description'] : '',
                        isset($msg['music_url']) ? $msg['music_url'] : '',
                        isset($msg['hqmusic_url']) ? $msg['hqmusic_url'] : '',
                        $msg['thumb_media_id']);
                break;

            /**
             * 6 回复图文消息
             *
             * Examples:
             * ```
             * $wechat->reply(array(
             *    'type' => 'news',
             *    'articles' => array(
             *        array(
             *            'title' => '图文消息标题1',                                 //可选
             *            'description' => '图文消息描述1',                           //可选
             *            'picurl' => 'http://me.diary8.com/data/img/demo1.jpg',      //可选
             *            'url' => 'http://www.example.com/'                          //可选
             *        ),
             *        array(
             *            'title' => '图文消息标题2',
             *            'description' => '图文消息描述2',
             *            'picurl' => 'http://me.diary8.com/data/img/demo2.jpg',
             *            'url' => 'http://www.example.com/'
             *        ),
             *        array(
             *            'title' => '图文消息标题3',
             *            'description' => '图文消息描述3',
             *            'picurl' => 'http://me.diary8.com/data/img/demo3.jpg',
             *            'url' => 'http://www.example.com/'
             *        )
             *     )
             * ));
             * ```
             */
            case 'news':
                $articles = '';
                foreach ($msg['articles'] as $article) {
                    $articles .= sprintf('<item>'.
                                    '<Title><![CDATA[%s]]></Title>'.
                                    '<Description><![CDATA[%s]]></Description>'.
                                    '<PicUrl><![CDATA[%s]]></PicUrl>'.
                                    '<Url><![CDATA[%s]]></Url>'.
                                '</item>', 
                                $article['title'],
                                $article['description'],
                                $article['picurl'],
                                $article['url']);
                }
                $xml = sprintf('<xml>'.
                        '<ToUserName><![CDATA[%s]]></ToUserName>'.
                        '<FromUserName><![CDATA[%s]]></FromUserName>'.
                        '<CreateTime>%s</CreateTime>'.
                        '<MsgType><![CDATA[news]]></MsgType>'.
                        '<ArticleCount>%s</ArticleCount>'.
                        '<Articles>%s</Articles>'.
                        '</xml>', 
                        $this->message->FromUserName,
                        $this->message->ToUserName,
                        time(),
                        count($msg['articles']),
                        $articles);
                break;
            
            /**
             * 0 转发到多客服接口
             *
             * Examples:
             * ```
             * $wechat->reply(array(
             *    'type' => 'transfer_customer_service',
             *    'kf_account' => 'test1@test'                // 可选
             * ));
             * ```
             */
            case 'transfer_customer_service':
                $xml_transinfo = '';
                if (isset($msg['kf_account']) && !empty($msg['kf_account'])) {
                    $xml_transinfo = sprintf('<TransInfo>'.
                            '<KfAccount><![CDATA[%s]]></KfAccount>'.
                            '</TransInfo>',
                            $msg['kf_account']);
                }
                $xml = sprintf('<xml>'.
                        '<ToUserName><![CDATA[%s]]></ToUserName>'.
                        '<FromUserName><![CDATA[%s]]></FromUserName>'.
                        '<CreateTime>%s</CreateTime>'.
                        '<MsgType><![CDATA[transfer_customer_service]]></MsgType>%s'.
                        '</xml>', 
                        $this->message->FromUserName,
                        $this->message->ToUserName,
                        time(),
                        $xml_transinfo);
                break;

            /**
             * 0 异常消息处理
             *
             */ 
            default:
                @error_log("$msg_type is not a message type that can be used.", 0);
                exit();                
                break;
        }
        
        // 对消息加解密方式 兼容模式\安全模式 - 加密消息
        if ($this->encrypt_type == 'aes' && $xml != '') {

            // 异常处理: 未配置encodingAESKey
            if ($this->encodingAESKey === false) {
                @error_log('EncodingAESKey Not Defined.', 0);
                exit();
            }

            $reply_timestamp = time();

            // 消息加密
            $pc = new Prpcrypt($this->encodingAESKey);            
            $reply_encrypt = $pc->encrypt($xml, $this->appId);
            // 消息加密: 异常处理
            if ($reply_encrypt === false) {
                @error_log('Encrypt Message Error.', 0);
                exit();
            }

            // 生成安全签名
            $reply_signature = SHA1::getSHA1($this->token, $reply_timestamp, $this->nonce, $reply_encrypt);
            // 生成安全签名: 异常处理
            if ($reply_signature===false) {
                @error_log('Get Message Signature Error.', 0);
                exit();
            }

            // 生成发送的xml
            $xml = sprintf('<xml>'.
                        '<Encrypt><![CDATA[%s]]></Encrypt>'.
                        '<MsgSignature><![CDATA[%s]]></MsgSignature>'.
                        '<TimeStamp>%s</TimeStamp>'.
                        '<Nonce><![CDATA[%s]]></Nonce>'.
                        '</xml>', 
                        $reply_encrypt,
                        $reply_signature,
                        $reply_timestamp,
                        $this->nonce);
        }
error_log($xml);
        echo $xml;
    }
877628
public function saveImage($url = '', $format = 'png')
    {
        $image        = DataRepository::getData('config_image');
        $defaultImage = $image['default_image'];
        try {
            Utils::debug('URL: ' . $url);
            Utils::debug('Format: ' . $format);
            try {
                // Xác định extention của file ảnh
                $info          = new \SplFileInfo($url);
                $fileExtension = $info->getExtension();
                $outputFormat  = !empty($fileExtension) ? $fileExtension : $format;
                Utils::debug('Output Format: ' . $outputFormat);
                // Quy định tên file ảnh sẽ lưu
                $fileName  = md5($url) . '.' . $outputFormat;
                $imageFile = $this->tmpPath . $fileName;
                $imageUrl  = $this->urlPath . $fileName;
                if (!file_exists($imageFile)) {
                    Utils::debug('Khong ton tai file: ' . $imageFile);
                    // Nếu như không tồn tại file ảnh -> sẽ tiến hành phân tích và cache file
                    // Xác định size ảnh
                    $imagine = new Imagine();
                    if (is_file($url)) {
                        Utils::debug('URL is File => ' . $url);
                        $image = $imagine->open($url);
                        $image->save($imageFile);
                    } else {
                        Utils::debug('URL is URL => ' . $url);
                        $getContent = Utils::getImageFromUrl($url);
                        Utils::debug('Data Content: ' . json_encode($getContent));
                        if (isset($getContent['content'])) {
                            $image = $imagine->load($getContent['content']);
                            Utils::debug('Load Content with CURL');
                        } else {
                            $image = $imagine->load($getContent);
                            Utils::debug('Load Content with file_get_content');
                        }
                        $result = $image->save($imageFile);
                        Utils::debug('Save Image Result: ' . json_encode($result));
                    }
                }
                $resultImage = trim($imageUrl);

                return $resultImage;
            }
            catch (RuntimeException $runtimeException) {
                if (function_exists('log_message')) {
                    $message = 'Runtime Error Code: ' . $runtimeException->getCode() . ' - File: ' . $runtimeException->getFile() . ' - Line: ' . $runtimeException->getLine() . ' - Message: ' . $runtimeException->getMessage();
                    log_message('error', $message);
                }

                return NULL;
            }
        }
        catch (\Exception $e) {
            if (function_exists('log_message')) {
                $message = 'Error Code: ' . $e->getCode() . ' - File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Message: ' . $e->getMessage();
                log_message('error', $message);
            }

            return $defaultImage;
        }
    }