A heat exchanger comprising a first header, a second header, heat exchange tubes, and an end cap, wherein each of the heat exchange tubes has an end connected to the first header and another end connected to the second header, an inner cavity of each of the heat exchange tubes communicates an inner cavity of the first header with an inner cavity of the second header, and each of the first header and the second header comprises two ports disposed in a length direction thereof; wherein the end cap is assembled and fixed to one port of the two ports of the first header or one port of the two ports of the second header, and the end cap comprises a body and a first opening formed in the body; wherein the body comprises a second cavity and a first groove portion, and the first groove portion is located between the first opening and the second cavity; wherein the first groove portion comprises a first bottom wall close to the first opening, the first bottom wall is provided with a third opening communicating the first opening with the second cavity, the second cavity is in communication with the inner cavity of the first header or the inner cavity of the second header, the first opening is located farther from the inner cavity of the first header or the inner cavity of the second header than the second cavity, and the first opening is configured for inflow or outflow of a refrigerant; wherein a flow area of the first groove portion is greater than a flow area of the third opening; the heat exchanger being characterized in that the body further comprises a first channel that is formed by extending the third opening in a direction from the second cavity toward the first opening; the first channel is located between the first opening and the first groove portion, and is in communication with the first opening and the first groove portion; and a width of the third opening in a transverse extension direction of the first bottom wall and a width of the first channel in the transverse extension direction of the first bottom wall are both smaller than a width of the first groove portion in the transverse extension direction of the first bottom wall. a first header, a second header, heat exchange tubes, and an end cap, wherein each of the heat exchange tubes has an end connected to the first header and another end connected to the second header, an inner cavity of each of the heat exchange tubes communicates an inner cavity of the first header with an inner cavity of the second header, and each of the first header and the second header comprises two ports disposed in a length direction thereof; wherein the end cap is assembled and fixed to one port of the two ports of the first header or one port of the two ports of the second header, and the end cap comprises a body and a first opening formed in the body; wherein the body comprises a second cavity and a first groove portion, and the first groove portion is located between the first opening and the second cavity; wherein the first groove portion comprises a first bottom wall close to the first opening, the first bottom wall is provided with a third opening communicating the first opening with the second cavity, the second cavity is in communication with the inner cavity of the first header or the inner cavity of the second header, the first opening is located farther from the inner cavity of the first header or the inner cavity of the second header than the second cavity, and the first opening is configured for inflow or outflow of a refrigerant; wherein a flow area of the first groove portion is greater than a flow area of the third opening; the heat exchanger being characterized in that the body further comprises a first channel that is formed by extending the third opening in a direction from the second cavity toward the first opening; the first channel is located between the first opening and the first groove portion, and is in communication with the first opening and the first groove portion; and a width of the third opening in a transverse extension direction of the first bottom wall and a width of the first channel in the transverse extension direction of the first bottom wall are both smaller than a width of the first groove portion in the transverse extension direction of the first bottom wall.