Our experimental scheme is based on a barrel optical microresonator filled with a dye solution. The barrel mirror provides a confining potential, a chemical potential, and an effective mass for a photon, making the system formally equivalent to a one-dimensional gas of harmonically trapped, number-conserving, and massive bosons. Within the framework of quantum statistical mechanics, we propose an exact analytical solution to the problem of Bose-Einstein condensation in harmonically trapped, one-dimensional, and ideal photons. It is found that the photon number of vapor is characterized by an analytical function, which involves a $q$-digamma function in mathematics. The numerical calculation of the analytical solution gives many interesting results. In the thermodynamic limit, the analytical expressions of the critical temperature and the condensate fraction are derived. We find that the spectral radiance of a one-dimensional barrel cavity has a sharp peak at the frequency of the cavity cutoff when the photon number exceeds the critical value determined by a temperature.