(1)由点 $A(0,3)$ 在椭圆 $C: \frac{x^2}{a^2} + \frac{y^2}{b^2} = 1$ 上,可得 $b=3$,即 $b^2=9$。
将点 $P\left(3, \frac{3}{2}\right)$ 代入椭圆方程,得:
$$ \frac{9}{a^2} + \frac{\left(\frac{3}{2}\right)^2}{9} = 1 $$
$$ \frac{9}{a^2} + \frac{9}{4 \times 9} = 1 \implies \frac{9}{a^2} + \frac{1}{4} = 1 $$
$$ \frac{9}{a^2} = \frac{3}{4} \implies a^2 = 12 $$
因为 $a > b > 0$,所以 $c = \sqrt{a^2 - b^2} = \sqrt{12 - 9} = \sqrt{3}$。
椭圆的离心率 $e = \frac{c}{a} = \frac{\sqrt{3}}{\sqrt{12}} = \frac{\sqrt{3}}{2\sqrt{3}} = \frac{1}{2}$。
(2)由(1)知椭圆方程为 $\frac{x^2}{12} + \frac{y^2}{9} = 1$。
直线 $AP$ 的斜率 $k_{AP} = \frac{3 - \frac{3}{2}}{0 - 3} = \frac{\frac{3}{2}}{-3} = -\frac{1}{2}$。
直线 $AP$ 的方程为 $y - 3 = -\frac{1}{2}(x - 0)$,即 $x + 2y - 6 = 0$。
线段 $AP$ 的长度 $|AP| = \sqrt{(3-0)^2 + \left(\frac{3}{2}-3\right)^2} = \sqrt{9 + \frac{9}{4}} = \sqrt{\frac{45}{4}} = \frac{3\sqrt{5}}{2}$。
设点 $B$ 到直线 $AP$ 的距离为 $d$。
由 $\triangle ABP$ 的面积为 9,得:
$$ S_{\triangle ABP} = \frac{1}{2} |AP| \cdot d = 9 $$
$$ \frac{1}{2} \cdot \frac{3\sqrt{5}}{2} \cdot d = 9 \implies d = \frac{36}{3\sqrt{5}} = \frac{12}{\sqrt{5}} = \frac{12\sqrt{5}}{5} $$
设过点 $B$ 且平行于 $AP$ 的直线方程为 $x + 2y + m = 0$ ($m \neq -6$)。
由平行线间的距离公式(或点到直线距离),有:
$$ \frac{|m - (-6)|}{\sqrt{1^2 + 2^2}} = \frac{12\sqrt{5}}{5} $$
$$ \frac{|m + 6|}{\sqrt{5}} = \frac{12\sqrt{5}}{5} \implies |m + 6| = 12 $$
解得 $m + 6 = 12$ 或 $m + 6 = -12$,即 $m = 6$ 或 $m = -18$。
情形一:当 $m = 6$ 时,直线方程为 $x + 2y + 6 = 0$。
联立直线与椭圆方程:
$$ \begin{cases} x + 2y + 6 = 0 \implies x = -2y - 6 \\ \frac{x^2}{12} + \frac{y^2}{9} = 1 \end{cases} $$
代入消元:
$$ \frac{(-2y - 6)^2}{12} + \frac{y^2}{9} = 1 $$
$$ \frac{4(y + 3)^2}{12} + \frac{y^2}{9} = 1 \implies \frac{(y + 3)^2}{3} + \frac{y^2}{9} = 1 $$
两边同乘 9:
$$ 3(y^2 + 6y + 9) + y^2 = 9 $$
$$ 3y^2 + 18y + 27 + y^2 = 9 $$
$$ 4y^2 + 18y + 18 = 0 \implies 2y^2 + 9y + 9 = 0 $$
$$ (2y + 3)(y + 3) = 0 $$
解得 $y = -\frac{3}{2}$ 或 $y = -3$。
当 $y = -\frac{3}{2}$ 时,$x = -2(-\frac{3}{2}) - 6 = 3 - 6 = -3$,即点 $B_1(-3, -\frac{3}{2})$。
此时直线 $l$ 即为直线 $PB_1$。由于 $P(3, \frac{3}{2})$,$B_1(-3, -\frac{3}{2})$,
$k_{l} = \frac{-\frac{3}{2} - \frac{3}{2}}{-3 - 3} = \frac{-3}{-6} = \frac{1}{2}$。
直线 $l$ 方程为 $y - \frac{3}{2} = \frac{1}{2}(x - 3) \implies 2y - 3 = x - 3 \implies x - 2y = 0$。
当 $y = -3$ 时,$x = -2(-3) - 6 = 0$,即点 $B_2(0, -3)$。
此时直线 $l$ 即为直线 $PB_2$。由于 $P(3, \frac{3}{2})$,$B_2(0, -3)$,
$k_{l} = \frac{-3 - \frac{3}{2}}{0 - 3} = \frac{-\frac{9}{2}}{-3} = \frac{3}{2}$。
直线 $l$ 方程为 $y = \frac{3}{2}x - 3 \implies 2y = 3x - 6 \implies 3x - 2y - 6 = 0$。
情形二:当 $m = -18$ 时,直线方程为 $x + 2y - 18 = 0$。
联立直线与椭圆方程:
$$ \begin{cases} x = 18 - 2y \\ \frac{x^2}{12} + \frac{y^2}{9} = 1 \end{cases} $$
代入消元:
$$ \frac{(18 - 2y)^2}{12} + \frac{y^2}{9} = 1 \implies \frac{4(9 - y)^2}{12} + \frac{y^2}{9} = 1 $$
$$ \frac{(9 - y)^2}{3} + \frac{y^2}{9} = 1 $$
两边同乘 9:
$$ 3(81 - 18y + y^2) + y^2 = 9 $$
$$ 243 - 54y + 3y^2 + y^2 = 9 $$
$$ 4y^2 - 54y + 234 = 0 \implies 2y^2 - 27y + 117 = 0 $$
判别式 $\Delta = (-27)^2 - 4 \times 2 \times 117 = 729 - 936 = -207 < 0$。
故该直线与椭圆无交点,舍去。
综上所述,直线 $l$ 的方程为 $x - 2y = 0$ 或 $3x - 2y - 6 = 0$。