The hydrogenation process in oil fields is a crucial step for improving oil quality and reducing pollutant emissions during crude oil processing. In the context of "dual carbon", the greenization of hydrogen supply mode has become a key factor in industry transformation. The traditional hydrogen production mode has a higher carbon emission intensity and is seriously out of sync with the low-carbon development requirements of the oil and gas industry. Therefore, it is of greater practical significance to develop green and safe hydrogen production methods. This paper uses a mixture of (NH4)2S2O8 and dicyandiamide as the precursor and prepares porous g-C3N4 (pg-C3N4) through a thermal polymerization method. The microstructure, light absorption capacity, chemical structure, and crystal structure of pg-C3N4 are analyzed by TEM, XRD, DRS, and FT-IR spectroscopy. The photocatalysis hydrogen production from water splitting and the degradation of pollutants over pg-C3N4 are also investigated. The results show that the specific surface area of pg-C3N4 is approximately 49 m2/g. The results show that the specific surface area of pg-C?N? is approximately 49 m2/g. Compared with bulk g-C?N?, pg-C?N? possesses a larger specific surface area and a relatively higher separation efficiency of photogenerated electron-hole pairs, thereby significantly enhancing its performance in water splitting for hydrogen production under visible light as well as its activity in decomposing Rhodamine B (RhB). Moreover, it can maintain good performance and structural stability. This paper provides a green hydrogen production method for the development of hydrogenation processes in oil fields.