65 lines
1.8 KiB
Python
65 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
请求提现测试接口:固定用户提现 1 元(默认),无需 admin_session。
|
|
用法:
|
|
python test_withdraw.py
|
|
python test_withdraw.py https://soul.quwanzhi.com
|
|
python test_withdraw.py http://localhost:8080 2
|
|
"""
|
|
|
|
import json
|
|
import sys
|
|
from urllib.request import Request, urlopen
|
|
from urllib.error import URLError, HTTPError
|
|
from urllib.parse import urlencode
|
|
|
|
DEFAULT_BASE = "http://localhost:8080"
|
|
DEFAULT_USER_ID = "ogpTW5fmXRGNpoUbXB3UEqnVe5Tg"
|
|
DEFAULT_AMOUNT = "1"
|
|
|
|
|
|
def main():
|
|
base = DEFAULT_BASE
|
|
amount = DEFAULT_AMOUNT
|
|
args = [a for a in sys.argv[1:] if a]
|
|
if args:
|
|
if args[0].startswith("http://") or args[0].startswith("https://"):
|
|
base = args[0].rstrip("/")
|
|
args = args[1:]
|
|
if args:
|
|
amount = args[0]
|
|
|
|
path = "/api/withdraw-test"
|
|
if not base.endswith(path):
|
|
base = base.rstrip("/") + path
|
|
url = f"{base}?{urlencode({'userId': DEFAULT_USER_ID, 'amount': amount})}"
|
|
|
|
req = Request(url, method="GET")
|
|
req.add_header("Accept", "application/json")
|
|
|
|
print(f"GET {url}")
|
|
print("-" * 50)
|
|
|
|
try:
|
|
with urlopen(req, timeout=15) as resp:
|
|
raw = resp.read().decode("utf-8", errors="replace")
|
|
try:
|
|
print(json.dumps(json.loads(raw), ensure_ascii=False, indent=2))
|
|
except Exception:
|
|
print(raw)
|
|
except HTTPError as e:
|
|
raw = e.read().decode("utf-8", errors="replace")
|
|
try:
|
|
print(json.dumps(json.loads(raw), ensure_ascii=False, indent=2))
|
|
except Exception:
|
|
print(raw)
|
|
print(f"HTTP {e.code}", file=sys.stderr)
|
|
except URLError as e:
|
|
print(f"请求失败: {e.reason}", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|