A generalization of Rademacher's reciprocity law