Skip to main content

云控卡密验证客户端库 - 支持 AES+HMAC 加密通信、心跳保活、离线上报

Project description

xfcloudcard

云控卡密验证客户端库,支持 AES-256-CBC + HMAC-SHA256 加密通信、心跳保活、卡密过期回调

安装

pip install xfcloudcard

快速开始

方式一:with 上下文管理器(推荐)

from xfcloudcard import CardClient

def on_expire():
    print("卡密已过期!")

# 传入 card_key,自动验证并启动心跳
with CardClient(card_key="CARD-XXXX-...", on_expire=on_expire) as client:
    # 验证通过,直接写业务代码
    pass
# 退出时自动停止心跳 + 发送离线通知

方式二:@require_card 装饰器

from xfcloudcard import require_card

@require_card(card_key="CARD-XXXX-...")
def main():
    # 验证通过后才执行
    pass

main()

方式三:只验证不心跳

from xfcloudcard import CardClient

client = CardClient()
result = client.verify_only("CARD-XXXX-...")
print(result['success'], result['message'])

API

CardClient 参数

参数 说明
card_key 卡密(传入则 with 进入时自动验证)
server_url 服务端地址,默认 http://localhost:8000
key 加密密钥,默认内置
heartbeat_interval 心跳间隔秒数,默认 60
on_expire 卡密过期时的回调函数

CardClient 方法

方法 说明
verify(card_key) 验证卡密,成功后自动启动心跳
verify_only(card_key) 只验证,不启动心跳
close() 停止心跳并发送离线通知
is_online() 返回心跳是否运行中

require_card() 参数

参数 说明
card_key 卡密(直接传入,无需交互)
exit_on_fail 验证失败是否直接退出,默认 True
on_expire 卡密过期时的回调函数

依赖

  • requests >= 2.25.0
  • pycryptodome >= 3.15.0

许可

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

xfcloudcard-1.0.3.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

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

xfcloudcard-1.0.3-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file xfcloudcard-1.0.3.tar.gz.

File metadata

  • Download URL: xfcloudcard-1.0.3.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for xfcloudcard-1.0.3.tar.gz
Algorithm Hash digest
SHA256 29054c1738725331165a1461d81d74325242959d58501fc1646e6f0ee2810cc7
MD5 4719cc00e3bef2e81b66f91dfd6bbd82
BLAKE2b-256 7bf91948d0ac5050132365cc64a4e3e2a6b547f05ece9bdc5de9b7cf9a7f28e8

See more details on using hashes here.

File details

Details for the file xfcloudcard-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: xfcloudcard-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for xfcloudcard-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 350e0554daf8e612eeaa81df45fa1ec8934e9d97371c97af2f6a2868777124ef
MD5 a25801a08becb3c72ca8395b673ffcd2
BLAKE2b-256 a73d5d2ed3c7434c1017879ae253af6f71b38319b98cfa37f60c235eace4ead6

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