minhdevtry/Reverse-web-api
GitHub: minhdevtry/Reverse-web-api
该项目是一个对 PG Bank 网银系统进行 HTTP 逆向分析后封装的非官方 Python API 库,用于实现自动化银行操作和支付集成。
Stars: 0 | Forks: 0
# PGBank 非官方 API (个人账户)
## ✨ 功能
- **自定义自动支付免费**,自定义订单链接、QR,跟踪 Description 作为订单代码,可实现自定义不同方法。
- 🔔 **Webhook dispatcher** — Zalo, Telegram, Google Sheet 自定义 HTTP,可配置以接收转账通知,将资金接收到其他系统。
- 🔐 **Authentication** 与 OTP flow + session persistence
- 👥 **Multi-account management** 每个账户灵活使用 proxy/BrowserID
- ⏰ **Auto-payment scheduler** — 安排定期转账、cron、conditional
- 📊 **Transaction history** 带有高级 query、categorization、导出 Excel/CSV/JSON
- 📈 **Real-time monitoring** — 余额阈值警报,交易检测
- 🔄 **Sync + Async API** 并行
- 💻 **CLI tool** (`pgbank` 命令)
- 🗄️ **Storage abstraction** — SQLite 默认,可切换至 Redis/Postgres
## 📦 安装
```
# (尚未推送到库),暂时 clone 到本地。
pip install pgbank-unofficial
```
## 🚀 快速入门
```
from pgbank_unofficial import PGBankManager, Account
from decimal import Decimal
# 设置 multi-account manager
mgr = PGBankManager()
# 添加账户(proxy 可选,browser_id 必填)
mgr.add_account(Account(
username="alice",
password="your_password",
browser_id="your_browser_id", # Required
proxy="http://proxy1:8080", # Optional
nickname="alice-personal",
))
mgr.add_account(Account(
username="bob",
password="bob_password",
browser_id="shared_browser_id", # Có thể share browser_id
proxy="http://proxy2:8080", # Proxy khác nhau
nickname="bob-personal",
))
# 健康检查所有账户
status = mgr.health_check()
print(status)
# {'alice-personal': , 'bob-personal': }
# 获取所有余额
balances = mgr.get_all_balances()
for account_id, balance in balances.items():
print(f"{account_id}: {balance.available:,.0f} VND")
```
## 💾 Session 存储 (Pluggable Backends)
默认情况下,sessions 存储在 JSON 文件中。如果要将 sessions 持久化到不同的 backend(SQLite、Supabase、Redis、内存中或其他任何后端),请实现 `BaseSessionStorage` 接口:
```
from pgbank_unofficial import PGBankClient, BaseSessionStorage, MemorySessionStorage
# ── 内置 backends ───────────────────────────────────────────
# 1. Default:单个 JSON 文件(旧版 `session_path=` 样式)
client = PGBankClient(
username="alice", password="...", browser_id="...",
session_path="./session.json",
)
# 2. 目录中每个用户名对应一个文件(非常适合 multi-account 设置)
from pgbank_unofficial import DirSessionStorage
client = PGBankClient(
username="alice", password="...", browser_id="...",
session_storage=DirSessionStorage("./sessions"),
)
# 3. In-memory(测试、临时环境)
client = PGBankClient(
username="alice", password="...", browser_id="...",
session_storage=MemorySessionStorage(),
)
# ── 自定义 backend:SQLite ──────────────────────────────────────
import sqlite3, json
class SQLiteSessionStorage(BaseSessionStorage):
def __init__(self, db_path: str = "sessions.sqlite3"):
self._conn = sqlite3.connect(db_path)
self._conn.execute(
"create table if not exists sessions "
"(username text primary key, data text not null, updated_at text not null)"
)
def save_session(self, username, data):
self._conn.execute(
"insert or replace into sessions(username, data, updated_at) "
"values (?, ?, datetime('now'))",
(username, json.dumps(data)),
)
self._conn.commit()
def load_session(self, username):
row = self._conn.execute(
"select data from sessions where username=?", (username,)
).fetchone()
return json.loads(row[0]) if row else None
def delete_session(self, username):
self._conn.execute("delete from sessions where username=?", (username,))
self._conn.commit()
client = PGBankClient(
username="alice", password="...", browser_id="...",
session_storage=SQLiteSessionStorage("pgbank.sqlite3"),
)
# ── 自定义 backend:Supabase / PostgreSQL ───────────────────────
# 相同模式:继承 BaseSessionStorage 并实现
# save_session(username, data) -> 写入数据
# load_session(username) -> 返回 dict 或 None
# delete_session(username) -> 删除记录
```
同样的 `session_storage` 参数也适用于 `AsyncPGBankClient`。
## ⏰ 自动支付示例
```
from pgbank_unofficial.scheduler import AutoPaymentScheduler, Job, CronTrigger
from decimal import Decimal
scheduler = AutoPaymentScheduler(mgr)
# 每月5号早上9点给妈妈转账500k
scheduler.add_job(Job(
name="Mẹ - tiền điện hàng tháng",
trigger=CronTrigger("0 9 5 * *"),
action=lambda ctx: ctx.client("alice-personal").transfer(
from_account="alice_main",
to_account="MOM_ACCOUNT",
amount=Decimal("500000"),
message="Tien dien thang {month}",
),
))
scheduler.start() # Chạy background
```
## 📊 交易历史
```
from pgbank_unofficial.history import HistoryQuery, export_to_excel
from datetime import date
history = mgr.history()
# 查询
txns = history.query(HistoryQuery(
from_date=date(2026, 6, 1),
to_date=date(2026, 6, 23),
min_amount=Decimal("1000000"),
))
# 导出 Excel
export_to_excel(txns, output_path="transactions_June.xlsx")
```
## 💻 CLI
```
pgbank account add --username alice --password xxx --browser-id bid_xxx
pgbank balance
pgbank history --from 2026-06-01 --to 2026-06-23 --export xlsx
pgbank schedule add --name "..." --cron "0 9 5 * *" --account alice --to MOM_ACC --amount 500000
```
## 📖 文档
- [入门指南](docs/getting-started.md) (即将推出)
- [OpenSpec specs](openspec/specs/pgbank-unofficial/spec.md)
- [API 参考](docs/api-reference.md) (即将推出)
## ⚠️ 免责声明
这是一个**非官方**项目,与 PGBank 无关。使用它可能违反银行条款并导致账户被锁定。您需自行承担风险。
## 📄 许可证
MIT 许可证 — 参见 [LICENSE](LICENSE)。
## Minhdevtry
标签:API, StruQ, Webhook, 云资产清单, 力导向图, 搜索引擎查询, 测试用例, 网络调试, 自动化, 逆向工具, 逆向工程, 银行系统