PITTSBURGH — Last summer, a woman in northern Alabama who law enforcement officials said was a prostitute typed a message to a doctor: “Can u get any Xanax.”

The doctor replied: “What makes you think I know a Xanax source?” Just below, he added a smiley face, and then described his home as the “Fun House.”

The doctor was one of the scores of medical professionals across seven states who were charged by federal prosecutors on Wednesday with schemes to illegally distribute millions of pain pills. Opioid prescriptions were exchanged for sex in some cases, and for cash with an added “concierge fee” in others. One doctor was accused of routinely prescribing opioids to friends on Facebook.

Prosecutors said the doctor in northern Alabama “recruited prostitutes and other young women with whom he had sexual relationships” to become his patients. He also opened his home to people using heroin, methamphetamine, cocaine and marijuana, they said, in a criminal complaint, adding that police officers had been to the house several times concerning overdoses and other complaints.