Second-harmonic generation in a resonator