For celestial measurement, it is difficult to enable a single optical system to image and measure both stars and the sun due to vastly different light intensity of targets and limited response capability of the image sensor pixel. Here, we develop an all-day optical attitude sensor integrating stars and the sun measurement based on extended pixel response model of the CMOS APS (Active-pixel sensor) imager. For extremely large light intensity, we extend the conventional pixel response model to the oversaturated stage where the pixel values reverse and drop below the saturation value. Based on this, the integration of the star sensor and the sun sensor is realized. The pixels image the starry sky with linear response, and make use of the oversaturation response to image the sun and obtain a black spot on the bright background. This principle enables the capability of all-day high-precision attitude measurement using a single miniaturized sensor. An integrated optical attitude sensor is designed and manufactured. Ground-based observation results show that the orientation accuracy from sun measurement is better than 9" (3σ), and the attitude accuracy from star measurement is better than 5" (3σ) for pointing and 11" (3σ) for rolling. The sensor can be applied to high-precision all-day navigation systems for miniaturized spacecrafts and aircrafts.