From 93af2f8c62b9132b87a95ed8f2653fc6da005084 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 17 Jul 2026 13:45:11 +0800 Subject: [PATCH] debug(transfer): add detailed logging for email scanning and data extraction --- unipay/providers/transfer.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/unipay/providers/transfer.py b/unipay/providers/transfer.py index b75ae91..1237167 100644 --- a/unipay/providers/transfer.py +++ b/unipay/providers/transfer.py @@ -118,20 +118,30 @@ class TransferGateway(Gateway): return None def get_transfer_data(self, mail): + debug(f'get_transfer_data: from={mail.mailfrom} to={mail.mailto} expect_to={self.email}') if mail.mailfrom != '95555@message.cmbchina.com': + debug(f'get_transfer_data: wrong sender') return None if mail.mailto != self.email: + debug(f'get_transfer_data: mailto mismatch: {mail.mailto} != {self.email}') return None if not mail.body.startswith('动账业务通知'): + debug(f'get_transfer_data: body not start with 动账业务通知, head={mail.body[:30]}') return None ns = DictObject() match = re.search(r'交易金额\s*[::]?\s*(\d+(?:\.\d+)?)', mail.body) if match: ns.amount = float(match.group(1)) + debug(f'get_transfer_data: amount={ns.amount}') match = re.search(r'摘要[::]\s*(\d{7})(?!\d)', mail.body) if match: ns.code = match.group(1) - if not hasattr(ns, 'amount') or not hasattr(ns, 'code'): + debug(f'get_transfer_data: code={ns.code}') + if not hasattr(ns, 'amount'): + debug(f'get_transfer_data: no amount found, body={mail.body[:200]}') + return None + if not hasattr(ns, 'code'): + debug(f'get_transfer_data: no code found, body={mail.body[:200]}') return None return ns @@ -231,16 +241,23 @@ class TransferGateway(Gateway): for i in range(count, 0, -1): try: mail = ec.get_mail(i) + debug(f'check_transfer: mail[{i}] from={mail.mailfrom} body_head={mail.body[:20]}') if mail.mailfrom != '95555@message.cmbchina.com': + debug(f'check_transfer: mail[{i}] skipped, wrong sender') continue if not mail.body.startswith('动账业务通知'): + debug(f'check_transfer: mail[{i}] skipped, not 动账业务通知') continue data = self.get_transfer_data(mail) if data is None: + debug(f'check_transfer: mail[{i}] get_transfer_data returned None') continue + debug(f'check_transfer: mail[{i}] code={data.code} amount={data.amount}, looking for {tcode}') if str(data.code) == tcode: matched = data + debug(f'check_transfer: mail[{i}] MATCHED!') break + debug(f'check_transfer: mail[{i}] code mismatch: {data.code} != {tcode}') except Exception as e: debug(f'check_transfer: skip mail {i}: {e}')