Skip to main content

nonebot-adapter-afdian

基于 NoneBot2 的爱发电适配器

使用

  1. 安装

    pip install nonebot-adapter-afdian
    
  2. 启用

    adapters = [
        { name = "Afdian", module_name = "nonebot.adapter.afdian" }
    ]
    
  3. 配置

    • NoneBot2

      DRIVER=~fastapi+~httpx
      HOST=0.0.0.0
      AFDIAN_HOOK_SECRET='<Your Secret>'
      AFDIAN_BOTS='[
          {
              "user_id": "<Your User Id>",
              "token": "<Your Token>"
          }
      ]'
      # 可选:Webhook 签名验证公钥(PEM),留空使用内置平台公钥
      AFDIAN_WEBHOOK_PUBLIC_KEY=''
      
    • 爱发电开发者控制台

      http://<IP>:<PORT>/afdian/webhooks/<user_id>
      

      or

      https://<IP>:<PORT>/afdian/<Your Secret>/webhooks/<user_id>
      

Webhook 签名验证

2025-07-01 起爱发电 Webhook 推送携带 sign 签名字段,适配器会使用内置平台公钥自动进行本地验签(RSA-SHA256),无需额外配置。

如平台更换公钥,可通过 AFDIAN_WEBHOOK_PUBLIC_KEY 配置自定义 PEM 公钥覆盖。未携带签名的旧版推送仍走订单回查验证。

API

from nonebot import on_notice
from nonebot.adapters.afdian import OrderNotifyEvent, Bot

test_afd = on_notice()


@test_afd.handle()
async def handle_afd(bot: Bot, event: OrderNotifyEvent):
    print("订单:" + event.data.order)

    result1 = await bot.query_order_by_page(page=1)
    print(result1)

    result2 = await bot.query_order_by_out_trade_no(
        out_trade_no="202308200000000000000000001"
        )
    print(result2)

    result3 = await bot.query_order_by_order_list(
        order_list=["202308200000000000000000000", "202308200000000000000000001"]
        )
    print(result3)

    result4 = await bot.query_sponsor(page=1)
    print(result4)

    result5 = await bot.query_sponsor(page=1, per_page=20) # 查询第一页,每页20个
    print(result5)

    # 根据订单号查询随机自动回复
    result6 = await bot.query_random_reply(
        out_trade_no="202308200000000000000000001"
        )
    print(result6)

    # 通过 API 填入自动回复(可用于补货、发码等场景)
    result7 = await bot.update_plan_reply(
        plan_id="<Your Plan Id>",  # 与 sku_id 二选一
        auto_random_reply="<New Code>",
        update_random_reply_type="overwrite",  # append 追加 / overwrite 覆盖
        )
    print(result7)

    # 发送私信(平台限频 10 次/秒 和 1000 次/小时)
    result8 = await bot.send_msg(recipient="<User Id>", content="<Content>")
    print(result8)

    # 查看方案详情
    result9 = await bot.query_plan(plan_id="<Your Plan Id>")
    print(result9)

    # 查询创作者的所有方案(非官方 Web API,无需签名,仅含已上架的公开方案)
    result10 = await bot.query_creator_plans()  # 默认查询当前 Bot 的 user_id
    result11 = await bot.query_creator_plans(user_id="<User Id>")  # 也可以查别人
    print(result10, result11)

特别感谢

贡献与支持

觉得好用可以给这个项目点个 Star 或者去 爱发电 投喂我。

有意见或者建议也欢迎提交 Issues 和 Pull requests 。

开源许可

本项目使用 MIT 作为开源许可证。

Metadata

Release files for nonebot-adapter-afdian 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nonebot-adapter-afdian 0.2.1
File Size Uploaded Provenance
nonebot_adapter_afdian-0.2.1.tar.gz 15.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for nonebot-adapter-afdian 0.2.1
File Interpreter ABI Platform
nonebot_adapter_afdian-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 33.1 kB

Release files / nonebot_adapter_afdian-0.2.1.tar.gz

Download URL nonebot_adapter_afdian-0.2.1.tar.gz
Size 15.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ef3abf8f764433b2505a5795827fe61c69a9a89e57a9c0c774b76375568f6bd7
BLAKE2b-256 checksum
How to use checksums
1711470e8c4544cbe62d03d0435d896800583c15723173abef1fc230b68e7ef9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.8 {"installer":{"name":"uv","version":"0.12.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / nonebot_adapter_afdian-0.2.1-py3-none-any.whl

Download URL nonebot_adapter_afdian-0.2.1-py3-none-any.whl
Size 17.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3cc3f2a82813d8ebde67b442dc44bcb3c02b4228d991ff04ba42f01f4a79c0c6
BLAKE2b-256 checksum
How to use checksums
093b25ff5303fde8008bd038ed94b050af7a060ce6f0a534fb56b98c1a17c829
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.8 {"installer":{"name":"uv","version":"0.12.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for nonebot-adapter-afdian 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page