It is a new approach to identify legal or illegal use of morphine through information on municipal wastewater. However, the sources of morphine in wastewater are complex, and distinguishing the contribution of different sources has become a key issue. A total of 262 influent samples from 61 representative wastewater treatment plants in a typical city were collected from October 2022 to March 2023. The concentrations of morphine, codeine, thebaine, papaverine, noscapine, and monoacetylmorphine were analyzed in wastewater and poppy straws. Combined with the proportion of alkaloids in poppy straws, the source analysis of alkaloids in wastewater was analyzed using the ratio method and positive matrix factorization model (PMF). Only five alkaloids were detected in wastewater, and monoacetylmorphine, a metabolite of heroin, was not detected. The concentrations of morphine and codeine were significantly higher than those of noscapine, papaverine, and thebaine. By constructing the ratios of codeine/(morphine + codeine) and noscapine/(noscapine + codeine), the source of poppy straw could be qualitatively distinguished. The PMF results showed that three sources of morphine for medical use, poppy straw, and codeine contributed 44.9%, 43.7%, and 9.4%, respectively. The different sources varied in these months due to the COVID-19 and influenza A outbreaks, in which the use of drugs containing poppy straws and codeine was the main source, whereas the use of morphine analgesics remained relatively stable. Inventory analysis further demonstrated the reliability of the source contributions from the PMF model, and morphine was not abused in this city.