At the end of the Southern Song Dynasty, as the country was troubled by domestic and foreign aggression, foreign countries began eyeing the dynasty, with the goal of invading the Central Plains. When an attack on the city finally commenced, Zhang Junbao—a disciple of the Wuji faction—turned the tide and united with Song Dynasty general Wei Linchuan, risking everything to defend the border.