The unramified principal series of $p$-adic groups. I. The spherical function