The use of solar energy to convert CO2 into clean energy is one of the ideal strategies for achieving carbon neutrality. However, the rapid recombination of photogenerated electron holes, the complexity of the reduction products and the consumption of sacrificial materials severely limit its development and application. In this work, g-C3N4-PDI (CNP) and MOF-545-NH2 (MNH) were prepared by calcination and hydrothermal methods, respectively, and CNP/MNH photocatalysts were prepared by in situ growth of MNH on CNP surface. The photocatalytic CO2 conversion reaction of CNP/MNH in triethanolamine and aniline solutions was investigated. Experiments show that the prepared CNP/MNH catalyst has excellent photocatalytic performance. When triethanolamine was used as a sacrificial agent, the yield of CH4 reached 192.7 μmol·g−1·h−1 (selectivity 92.94 %). In particular, while the catalyst realizes the conversion of CO2 in the aniline solution, it is surprising to find that part of the CO2 is converted to ethanol. The catalyst’s photochemical properties, CO2 reduction pathway, and aniline oxidation products were characterized by XPS, UV–vis DRS, PL, electrochemistry, zeta potential, ESR, GC–MS and in-situ infrared spectroscopy. The results show that the modification of the catalyst and the formation of heterojunction not only increase the adsorption of CO2, but also accelerate the process of photogenerated electron migration, which plays an important role in the process of carbon dioxide conversion. This study provides a new perspective for the design of photocatalytic CO2 conversion catalysts, and also provides a feasible method for aniline wastewater treatment.