def parse_payment_result(self, xml):
try:<EOL><INDENT>data = xmltodict.parse(xml)<EOL><DEDENT>except (xmltodict.ParsingInterrupted, ExpatError):<EOL><INDENT>raise InvalidSignatureException()<EOL><DEDENT>if not data or '<STR_LIT>' not in data:<EOL><INDENT>raise InvalidSignatureException()<EOL><DEDENT>data = data['<STR_LIT>']<EOL>sign = data.pop('<STR_LIT>', None)<EOL>real_sign = calculate_signature(data, self.api_key if not self.sandbox else self.sandbox_api_key)<EOL>if sign != real_sign:<EOL><INDENT>raise InvalidSignatureException()<EOL><DEDENT>for key in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>if key in data:<EOL><INDENT>data[key] = int(data[key])<EOL><DEDENT><DEDENT>data['<STR_LIT>'] = sign<EOL>return data<EOL>
解析微信支付结果通知