zpay — ZPay Python SDK
English | 中文
Async Python client for the ZPay payment gateway. Supports Alipay and WeChat Pay via redirect URLs, server-to-server API calls, order queries, refunds, and callback verification.
Installation
pip install zpay
Requirements: Python ≥ 3.10, aiohttp
Quick Start
import asyncio
from zpay import ZPayClient
async def main():
async with ZPayClient(pid="your_pid", key="your_key") as client:
# 1. Redirect URL (no HTTP request)
url = client.create_payment_url(
name="iPhone 17",
money="599.00",
out_trade_no="ORDER_001",
notify_url="https://yoursite.com/notify",
return_url="https://yoursite.com/return",
type="alipay",
)
print("Pay URL:", url)
# 2. API payment — returns payurl / qrcode / img
resp = await client.create_payment(
name="iPhone 17",
money="599.00",
out_trade_no="ORDER_002",
notify_url="https://yoursite.com/notify",
clientip="1.2.3.4",
type="wxpay",
)
print("QR Code:", resp.qrcode)
# 3. Query order
order = await client.query_order(out_trade_no="ORDER_002")
print("Status:", order.status)
# 4. Refund
refund = await client.refund(out_trade_no="ORDER_002", money="599.00")
print(refund.msg)
# 5. Verify callback notification
payload = client.verify_notification(request_params)
if payload.is_paid:
print("Payment confirmed!")
asyncio.run(main())
API Reference
ZPayClient(pid, key, base_url?, session?)
| Parameter | Type | Description |
|---|---|---|
pid |
str |
Merchant ID |
key |
str |
Merchant secret key |
base_url |
str |
API base URL (default: https://zpayz.cn) |
session |
aiohttp.ClientSession |
Optional existing session |
Methods
| Method | Returns | Description |
|---|---|---|
create_payment_url(...) |
str |
Build a signed redirect URL (no HTTP) |
create_payment(...) |
PaymentResponse |
Server-to-server payment API |
query_order(...) |
OrderResponse |
Query order status |
refund(...) |
RefundResponse |
Submit refund request |
verify_notification(params) |
NotificationPayload |
Validate and parse callback |
Payment Types
| Value | Channel |
|---|---|
"alipay" |
Alipay |
"wxpay" |
WeChat Pay |
License
MIT
zpay — ZPay Python SDK 中文
English | 中文
ZPay 支付网关的异步 Python 客户端,支持支付宝、微信支付的跳转收款、服务端 API 下单、订单查询、退款以及回调验签。
安装
pip install zpay
环境要求: Python ≥ 3.10,依赖 aiohttp
快速开始
import asyncio
from zpay import ZPayClient
async def main():
async with ZPayClient(pid="your_pid", key="your_key") as client:
# 1. 生成跳转收款 URL(不发起 HTTP 请求)
url = client.create_payment_url(
name="iPhone 17",
money="599.00",
out_trade_no="ORDER_001",
notify_url="https://yoursite.com/notify",
return_url="https://yoursite.com/return",
type="alipay",
)
print("支付链接:", url)
# 2. 服务端 API 下单(返回 payurl / qrcode / img)
resp = await client.create_payment(
name="iPhone 17",
money="599.00",
out_trade_no="ORDER_002",
notify_url="https://yoursite.com/notify",
clientip="1.2.3.4",
type="wxpay",
)
print("二维码:", resp.qrcode)
# 3. 查询订单
order = await client.query_order(out_trade_no="ORDER_002")
print("订单状态:", order.status)
# 4. 退款
refund = await client.refund(out_trade_no="ORDER_002", money="599.00")
print(refund.msg)
# 5. 验证异步回调通知
payload = client.verify_notification(request_params)
if payload.is_paid:
print("支付成功!")
asyncio.run(main())
API 说明
ZPayClient(pid, key, base_url?, session?)
| 参数 | 类型 | 说明 |
|---|---|---|
pid |
str |
商户 ID |
key |
str |
商户密钥 |
base_url |
str |
API 基础地址(默认:https://zpayz.cn) |
session |
aiohttp.ClientSession |
可选,传入已有的 Session |
方法列表
| 方法 | 返回值 | 说明 |
|---|---|---|
create_payment_url(...) |
str |
生成带签名的跳转收款 URL(不请求网络) |
create_payment(...) |
PaymentResponse |
服务端 API 下单 |
query_order(...) |
OrderResponse |
查询订单状态 |
refund(...) |
RefundResponse |
发起退款 |
verify_notification(params) |
NotificationPayload |
验签并解析回调参数 |
支付方式
| 值 | 渠道 |
|---|---|
"alipay" |
支付宝 |
"wxpay" |
微信支付 |
开源协议
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
zpay-0.1.1.tar.gz
(59.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
zpay-0.1.1-py3-none-any.whl
(8.7 kB
view details)
File details
Details for the file zpay-0.1.1.tar.gz.
File metadata
- Download URL: zpay-0.1.1.tar.gz
- Upload date:
- Size: 59.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31c6d6e2343aadd90932a3787093e7628776c476952c34fff1f3c9a339fbac84
|
|
| MD5 |
1f127f89f675bcf3e53790da2cb907fa
|
|
| BLAKE2b-256 |
3a65d70d40c5ee4d82f1a23f285f88bdab2e1cb33d0c841e3f2ebcaa9619aa2e
|
File details
Details for the file zpay-0.1.1-py3-none-any.whl.
File metadata
- Download URL: zpay-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a1ac67c0dd0d0cc803a575bce909998ecdbbb5450f0b30c13f1c4fd63c7dddc
|
|
| MD5 |
5f3b8f807bb5273b3befda95474c851a
|
|
| BLAKE2b-256 |
576346a40318c3c98960a8ad3f80e558f3819c2c7617f342bb461387ee099f5e
|