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.1.tar.gz (9.9 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.1-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: xfcloudcard-1.0.1.tar.gz
  • Upload date:
  • Size: 9.9 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.1.tar.gz
Algorithm Hash digest
SHA256 23168033f3904a7687631f65d8497e825cb0001fcda68679ab9a5a0cd0a445f5
MD5 f9d878a0d4f1075cc1b3da7c3bcd2778
BLAKE2b-256 04c81fe3acc4a6ba162ed3cf6425c8a776a8efa9dee326a80ff9d6d75df00609

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xfcloudcard-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.6 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9838335af12420277baaa57bdba37b266fff1c520d7c80ba3dda6b0ad8fbcbf7
MD5 da03d18f3aa645d4772f039a7d809917
BLAKE2b-256 ca9384b5a8bcfc20191e65681361bb4d6e84c4af8deab1c306f6df420b42bad4

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