Designing efficient dual-functional catalysts for photocatalytic oxygen reduction to produce hydrogen peroxide (H2O2) and photodegradation of dye pollutants is challenging. In this work, we designed and fabricated an S-scheme heterojunction (g-C3N4/ZnO composite photocatalyst) via one-pot calcination of a mixture of ZIF-8 and melamine in the KCl/LiCl molten salt medium. The KCN/ZnO composite produced 4.72 mM of H2O2 within 90 min under illumination (with AM 1.5 filter), which is almost 1.3 and 7.8 times than that produced over KCN and ZnO, respectively. Simultaneously, the KCN/ZnO also showed excellent photodegradation performance for the dye pollutants (Rhodamine B, RhB), with a removal rate of 92 % within 2 h. The apparent degradation rate constant of RhB over KCN/ZnO was approximately 5–8 times that of KCN and ZnO. In the photocatalytic process, photo-generated holes and superoxide radicals are the main active species. Oxygen (O2) was mainly reduced to produce H2O2 via a two-electron (2e−) pathway with superoxide radicals as intermediates and the 2e− oxygen reduction reaction selectivity of KCN/ZnO was close to 69.82 %. Photo-generated holes are mainly responsible for the degradation of RhB. Compared with pure KCN and ZnO, the enhanced photocatalytic activity of the KCN/ZnO composite is mainly attributed to the following aspects: 1) larger specific surface area and pore volume is beneficial to expose more active sites; 2) stronger light harvesting ability and red-shifted absorption edge bestow the compound a stronger light utilization efficiency; 3) the construction of S-scheme heterostructure between KCN and ZnO improve the photogenerated electron-hole pairs separation ability and bestow photogenerated carriers a higher redox potential.