The extraction of ammonia (NH3) through electrocatalytic nitrate reduction reaction (NO3 -RR) represents a sustainable avenue in NH3 generation and utilization. However, the catalytic efficiency of the NO3 -RR is hindered by the sluggish kinetics. This study first theoretically found that phosphide-based heterostructure can alter the adsorption structure of intermediates in the nitrate-to-ammonia process, thereby achieving precise regulation of the energy barrier in the rate-determining step. Based on theoretical design, a novel Co-doped Fe2P@NiP2 heterojunction catalyst is successfully synthesized, which deliver a notable NH3 yield rate of 0.395mmolh-1cm-2 at -0.7V versus RHE, as well as a remarkable ammonia Faraday efficiency of 97.2% at -0.6V versus RHE. Experimental and theoretical results further confirm that redistributing electrons and shifting the center of the d-band upwards through interfacial doping modulate intermediates adsorption strength and inhibition of hydrogen evolution, leading to excellent performance in NO3 --to-NH3. Further integrating the Co-Fe2P@NiP2 catalyst into a Zn-nitrate battery exhibits a substantial voltage output of 1.49V and a commendable power density of 13.2mWcm-2. The heteroatom-doped heterojunction strategy provides a versatile route for developing advanced catalysts, thereby broadening the horizons of electrocatalytic methodologies for nitrate reduction and ammonia synthesis.