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)

特别感谢

贡献与支持

觉得好用可以给这个项目点个 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.0.tar.gz (14.8 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.0-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nonebot_adapter_afdian-0.2.0.tar.gz
  • Upload date:
  • Size: 14.8 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.0.tar.gz
Algorithm Hash digest
SHA256 514e50eb7d94fcf318891f44ed52df55cabec41dd707afbdeb248354b92f95a2
MD5 2a1a2fd5ca20533e6a1cc7d182168df6
BLAKE2b-256 93e1f27d0b8ef85586c27b49855b15c7d58324e8151e2f7bea78cbe183c38588

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nonebot_adapter_afdian-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1b45b38d642179bab76044bc14830fe6a5482adcc34ade38f1e0c9579a6af8b2
MD5 9ffcd46b66f51b70c244ea11a1ae8421
BLAKE2b-256 5c5519194112f81cf7a88d239e89d85b07404d1248b02f9ca072e964aee3a31c

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.1

2 files

This release

0.2.0 This release

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