Skip to main content

Single-file utility module for payment and QingLong environment operations.

Project description

autman-huawei

一个单文件 Python 工具模块,主要提供以下三类能力:

  • 二维码链接生成
  • 支付配置读取与码支付订单操作
  • 青龙环境变量管理

安装

pip install -U autman-huawei

导入方式

import autman_huawei

或者:

from autman_huawei import (
    MaPayClient,
    QingLongClient,
    generate_qrcode_url,
    get_pay_config,
)

功能概览

  • 生成二维码图片链接
  • 读取运行时支付配置
  • 管理青龙环境变量
  • 创建码支付订单
  • 查询码支付订单状态
  • 在没有 middleware 时安全降级导入

使用说明

1. 生成二维码链接

from autman_huawei import generate_qrcode_url

url = generate_qrcode_url("https://example.com")
print(url)

示例输出:

https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=https%3A//example.com

2. 读取支付配置

get_pay_config() 会从 dd_sign_config 数据桶读取支付相关配置,并返回整理后的字典。

from autman_huawei import get_pay_config

config = get_pay_config()
print(config)

示例输出:

{
    "ma_pay_switch": False,
    "qr_pay_switch": True,
    "zsm": "example text",
    "pay_types": {
        "alipay": "支付宝",
        "wxpay": "微信支付",
    },
}

3. 使用青龙客户端

QingLongClient 用于创建、更新、启用和删除青龙环境变量。

3.1 默认初始化

from autman_huawei import QingLongClient

client = QingLongClient("JD_COOKIE")
print(client.is_configured())

默认会从以下位置读取青龙配置:

  • bucket:G_AUTMAN
  • key:ql_config

配置格式:

host丨client_id丨client_secret

3.2 自定义 bucket 和 key

这是 1.3.0 新增能力。

from autman_huawei import QingLongClient

client = QingLongClient(
    "JD_COOKIE",
    config_bucket="MY_BUCKET",
    config_key="my_ql_config",
)
print(client.is_configured())

3.3 直接传青龙配置字符串

from autman_huawei import QingLongClient

client = QingLongClient(
    "JD_COOKIE",
    "http://127.0.0.1:5700丨client_id丨client_secret",
)
print(client.is_configured())

3.4 更新或创建环境变量

from autman_huawei import QingLongClient

client = QingLongClient("JD_COOKIE")
ok = client.update_env(
    username="demo_user",
    env_value="pt_key=xxx;pt_pin=demo;",
    remark="demo_user",
)
print(ok)

3.5 删除环境变量

from autman_huawei import QingLongClient

client = QingLongClient("JD_COOKIE")
ok = client.delete_env("demo_user")
print(ok)

4. 使用码支付客户端

MaPayClient 可以创建订单并查询支付状态。

4.1 默认初始化

from autman_huawei import MaPayClient

client = MaPayClient()
print(client.is_configured())

4.2 直接传配置

from autman_huawei import MaPayClient

client = MaPayClient(
    gateway="https://pay.example.com",
    pid="10001",
    key="your_key",
    notify_url="https://example.com/notify",
    return_url="https://example.com/return",
)
print(client.is_configured())

4.3 创建订单

from autman_huawei import MaPayClient

client = MaPayClient(
    gateway="https://pay.example.com",
    pid="10001",
    key="your_key",
)

result = client.create_order(
    amount=10.5,
    pay_type="alipay",
    out_trade_no="order_10001",
    subject="测试订单",
    param="custom_data",
)
print(result)

示例成功输出:

{
    "trade_no": "202603160001",
    "pay_url": "https://pay.example.com/pay/202603160001",
    "raw": {...},
}

4.4 查询订单状态

from autman_huawei import MaPayClient

client = MaPayClient(
    gateway="https://pay.example.com",
    pid="10001",
    key="your_key",
)

result = client.check_order("order_10001")
print(result)
print(client.is_paid("order_10001"))

配置说明

middleware 数据桶

本模块通过宿主环境提供的 middleware.bucketGet API 读取运行时配置。

青龙配置默认位置

  • bucket:G_AUTMAN
  • key:ql_config

示例值:

http://127.0.0.1:5700丨abcdef丨123456

支付配置数据桶

  • bucket:dd_sign_config

支持的键:

  • ma_pay_switch
  • qr_pay_switch
  • zsm
  • pay_types
  • ma_pay_gateway
  • ma_pay_pid
  • ma_pay_key
  • ma_pay_notify_url
  • ma_pay_return_url

pay_types 示例:

alipay:支付宝,wxpay:微信支付,qqpay:QQ钱包

行为说明

  • 如果 middleware 不存在,模块仍可安全导入
  • 缺失的 bucket 配置会回退为空字符串或 False 风格结果
  • MaPayClient(...).is_configured() 在支付配置不完整时返回 False
  • QingLongClient(...).is_configured() 在青龙 host、client_id、client_secret 缺失时返回 False
  • QingLongClient("JD_COOKIE") 老写法继续兼容
  • QingLongClient(..., config_bucket="MY_BUCKET", config_key="my_ql_config") 支持自定义读取位置

快速测试

import autman_huawei

print(autman_huawei.__version__)
print(autman_huawei.generate_qrcode_url("https://example.com"))
print(autman_huawei.MaPayClient(gateway="", pid="", key="").is_configured())
print(autman_huawei.QingLongClient("JD_COOKIE", "").is_configured())

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autman_huawei-1.3.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

autman_huawei-1.3.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file autman_huawei-1.3.0.tar.gz.

File metadata

  • Download URL: autman_huawei-1.3.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for autman_huawei-1.3.0.tar.gz
Algorithm Hash digest
SHA256 d08f6eccabcbf01850e3622b09531e07d1d96b3682810e0d6887807e193b68ea
MD5 00d5ea4b32c446031b26df1d7cbd1277
BLAKE2b-256 f63ce5362e69b1a1bad5eb6b247efe965fe3a34de8d5b8b1214daeb32ee9efe7

See more details on using hashes here.

File details

Details for the file autman_huawei-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: autman_huawei-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for autman_huawei-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 60fae34fcdaf252b3719ccd1627c1e39df813d85146ad730c092d3b0ec5ce2ea
MD5 2d3ed6546c7accd6757987375f900c83
BLAKE2b-256 4cec7e7f6c840f0895ed2e9631b4263da95a73bc0b9f4ab5422e61a2ad69e6bc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page