How does the Sun generate its energy? We all know that the sun generates its energy from nuclear fusion in the core. The electromagnetic radiation produced slowly travels upwards, while constantly being absorbed and re-emitted by the charged ions, until it reaches the photosphere, where it can basically travel freely (because there are less charged ions), until it travels out into space and then into our eyes.
But I just realized that this doesn't seem to be consistent with the exercise where we calculate the surface temperature of the sun using the Stefan-Boltzmann law. This law is a consequence of blackbody radiation theory, and so by using this law, we're now assuming that the sun's energy comes from the thermal motion of the particles in the photosphere. But as explained in the first paragraph, the energy actually comes from nuclear fusion deep in the core. I am probably stupid for not figuring out how these two explanations of the energy are consistent, but apparently I can't and I need help. Is it because the radiation from the core is absorbed by the photosphere, and then being re-emitted as blackbody radiation? Or is it because of something else?
 A: The gamma rays released deep in the core of a star are scattered off of ionized atoms there, which adds energy to the atoms and removes it from the photons. The scattering events are so frequent that it takes a time scale of order ~thousands of years for a photon to rattle its way all the way out to where it can escape into space without further scatterings. In rattling around like that, the radiation comes into thermal equilibrium with the ions it scatters off of and assumes a blackbody-shaped wavelength distribution. The gammas are thus converted into visible light, IR, and UV photons.
The energetic neutrons that the fusion reactions also emit are similarly scattered off the ions in the plasma and thereby heat the plasma too. In some regions of the sun's interior, convective cells get set up which actively transport hot matter up out of the core towards the surface and on the way, the hot matter gets mixed and equilibrates with the photons it encounters and so that energy also shows up in the temperature of the outermost parts of the sun.
The neutrinos released during the fusion reactions in the core radiate straight out of the sun because the plasma, though very dense, is almost completely transparent to them. They carry energy off, but do not thermally equilibrate with matter on their way out.
A: The energy we receive from the Sun, in the form of photons, comes from the photosphere. This is the very outer layer of the Sun. If it is in equilibrium, i.e. not getting any hotter or colder, then in terms of what we can see when we look from the outside, it does not matter where the energy comes from that heats the photosphere.
The Sun is of course much hotter in the interior, but we cannot see the interior. It is covered by a photosphere that is opaque, so it is the photosphere we see.
A few other things. The radiation field inside the Sun, from the core right up to the photosphere is as close to a blackbody distribution as you will find. That is because the mean free path of photons is extremely short compared with the length scale on which the temperature changes. i.e. photons are emitted and absorbed by material at the same temperature (do not think of individual photons making their way to the surface, that is not what happens).
Nevertheless, the temperature does change with depth and so does the temperature of the blackbody radiation field. If you were to peel off the solar photosphere you would see a hotter blackbody beneath. There are no energy conservation issues - the luminosity of that hotter blackbody would be the same because it's surface area is smaller.
In fact the photosphere is where the approximation to a blackbody is worst. That is because the photons escaping from the Sun come from slightly different temperatures, depending on their wavelengths, resulting in absorption lines and other features. The spectrum of the Sun is therefore a composite of spectra from regions with a range of temperatures, from about 4000K up to around 10,000K.  The effective temperature of the Sun (the commonly quoted value) is just defined as
$$ T_{\rm eff} =\left( \frac{L}{4\pi R^2\sigma}\right)^{1/4}$$
where $L$ is the solar luminosity and $R$ is the radius of the photosphere.
A: When an ion absorbs and re-emits radiation, it will usually emit at a different frequency from that absorbed.
The characteristic nuclear frequencies are only present in the inner reactive core, before they get absorbed.
The emission frequencies from there on out are primarily dependent on the temperature of the ionised gas.
A: The sun light received at earth, is approximately fitted with the black body curve:


Solar irradiance spectrum above atmosphere and at surface. Extreme UV and X-rays are produced (at left of wavelength range shown) but comprise very small amounts of the Sun's total output power.

That the law used the surface area for the definition

Specifically, the Stefan–Boltzmann law states that the total energy radiated per unit surface area of a black body across all wavelengths per unit time

does not mean that the radiated energy comes only from the surface of the body under consideration, whether at low temperatures or at sun temperature. The surface area is necessary to compute the power. Black body radiation comes from the whole body.
The fact that the radiation from the sun follows more or less black body radiation means that the radiation comes from the whole sun, the one coming from the center  taking a large number of years to come out finally added to the one of the plasma of the surface give the observed curve. That it is not an exact fit to a black body is due to these various mechanisms by which the radiation is produced.
