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 或者去 爱发电 投喂我。

有意见或者建议也欢迎提交 IssuesPull requests

开源许可

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

Download files

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

Source Distribution

nonebot_adapter_afdian-0.2.1.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

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

nonebot_adapter_afdian-0.2.1-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file nonebot_adapter_afdian-0.2.1.tar.gz.

File metadata

  • Download URL: nonebot_adapter_afdian-0.2.1.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for nonebot_adapter_afdian-0.2.1.tar.gz
Algorithm Hash digest
SHA256 ef3abf8f764433b2505a5795827fe61c69a9a89e57a9c0c774b76375568f6bd7
MD5 94eaf21a7263559c6c459ef63178bc2d
BLAKE2b-256 1711470e8c4544cbe62d03d0435d896800583c15723173abef1fc230b68e7ef9

See more details on using hashes here.

File details

Details for the file nonebot_adapter_afdian-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: nonebot_adapter_afdian-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for nonebot_adapter_afdian-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3cc3f2a82813d8ebde67b442dc44bcb3c02b4228d991ff04ba42f01f4a79c0c6
MD5 467221a5e0079b29959210c17a36869c
BLAKE2b-256 093b25ff5303fde8008bd038ed94b050af7a060ce6f0a534fb56b98c1a17c829

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 files

0.2.0

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

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