Reconstructing the scattering matrix of photonic systems from quasinormal modes