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.2.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.2-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: xfcloudcard-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 87d6be7194435efb33c2094de675785389818a9c95d1da0920d28f94513fb4b8
MD5 0acce1f524ecf525f4efe1001ec44bc8
BLAKE2b-256 1c92fabb3f5e130adc882ae3ec50394336d4d7a8ba84159510d409ef7940bed2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xfcloudcard-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 11.2 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3861d2d9eb8779a1ba654e6e1bfb063d82b256657222ea9ab0b11b7c0fd6d504
MD5 525109380db2a7fb6f1624fe10599bd9
BLAKE2b-256 08819bf7e79fee198cc8c8ff302a8b19247932d165d84d548536fbc30090aa5a

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