public function build()

in Server/php/app_token.php [44:79]


    public function build()
    {
        if ($this->app_key === null) {
            throw new ValueError('missing secretKey');
        }
        if ($this->service === null) {
            throw new ValueError('missing service');
        }

        $signKey = generate_sign($this->app_key, $this->issue_timestamp, $this->salt);

        $buf = '';
        $app_id_bytes = $this->app_id;
        $buf .= pack('N', strlen($app_id_bytes));
        $buf .= $app_id_bytes;
        $buf .= pack('N', $this->issue_timestamp);
        $buf .= pack('N', $this->salt);
        $buf .= pack('N', $this->timestamp);
        $buf .= $this->service->pack();
        if ($this->options === null) {
            $this->options = new AppTokenOptions();
        }
        $buf .= $this->options->pack();

        $fix_length_buf = getFixedLengthBytesAuto($buf);

        $signature = sign($signKey, $fix_length_buf);

        $token_buf = '';
        $token_buf .= pack('N', strlen($signature));
        $token_buf .= $signature;
        $token_buf .= $fix_length_buf;

        $fix_length_token_buf = getFixedLengthBytesAuto($token_buf);
        return self::VERSION_0 . base64_encode(compress($fix_length_token_buf));
    }