Photon-number-resolved heralded-photon source for improved quantum key distribution