The global prevalence of abuse of benzodiazepines (BZDs) and designer benzodiazepines (DBZDs) has witnessed a significant increase in recent years. To effectively monitor and control the presence of benzodiazepines in a specific region, a method combining solid phase extraction (SPE), ultra-performance liquid chromatography (UPLC), and triple quadrupole mass spectrometry (MS/MS) was developed. The optimization process involved the pretreatment process and UPLC-MS/MS parameter adjustments. The pretreatment optimization encompassed the selection of appropriate SPE column types, flushing and elution conditions, as well as resolution conditions. Subsequently, this method was applied to analyze the influent samples from six wastewater treatment plants in Beijing. The results showed that: (1) The most favorable outcomes were achieved using the Cleanert PCX extraction column, along with 2 mL of 2% (V
) formic acid aqueous solution, 2 mL of methanol for flushing, 4 mL of 5% (V
) methanol ammonia solution for elution, and 500 μL of a 50% (V
) methanol-water solution for residue redissolution after evaporation. (2) By employing these optimized conditions, the recovery rates of 25 target compounds spanning various concentration ranges, were found to be between 85.7% to 115%, matrix effect, limits of detection and quantification, linear relationship, precision, and other performance indicators all met validation criteria. (3) The real influent samples revealed the detection and quantification of 18 out of the 25 target compounds, with concentrations ranging from 0.03 to 22.4 ng/L. The results indicated that the developed method enabled the detection of both BZDs and DBZDs in wastewater samples, which can serve as a valuable tool for further investigations on BZDs and DBZDs using wastewater-based epidemiology.