DingTalkCallbackCrypto
public final class DingTalkCallbackCrypto
io/agentscope/extensions/channel/dingtalk/DingTalkCallbackCrypto.java:53–190DingTalk 回调 Crypto,把智能体接入外部消息渠道与企业平台。位于 io.agentscope.extensions.channel.dingtalk 包。核心成员包括 verify、decrypt、hasAesKey、DingTalkCallbackCrypto。
Implements DingTalk's HTTP-callback request verification and optional body decryption for robot message reception. See the DingTalk docs on verifying robot requests and callback body encryption.
Inputs:
-
appSecret— the enterprise-internal app secret. Used as the HMAC key for request signature verification: each callback carriestimestampandsignheaders, wheresign = Base64(HmacSHA256(appSecret, timestamp + "\n" + appSecret))and the timestamp is a millisecond epoch DingTalk requires to be no older than one hour; timestamps ahead of local time are tolerated only within a clock-skew allowance. -
aesKey— optional 43-character base64 (no padding). When the robot is configured with encryption, the callback body is a{"encrypt": ...}envelope instead of plain JSON, and this key (decoded with an appended"="to 32 bytes, its first 16 bytes also used as the CBC IV) decrypts it. May benullfor robots configured without encryption.
Instances are immutable and thread-safe; #verify and #decrypt may be invoked
concurrently from multiple request threads.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public DingTalkCallbackCrypto(String appSecret, String aesKey) | 初始化 `DingTalkCallbackCrypto` 实例。 Creates a new instance. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public boolean verify(String timestamp, String sign) | 执行 `verify` 方法。 Verifies the `timestamp`/`sign` request headers of a callback: the timestamp must
be a millisecond epoch no older than `#MAX_TIMESTAMP_AGE_MS` and no further ahead of
local time than `#MAX_FUTURE_TIMESTAMP_MS`, and `sign` must equal `
Base64(HmacSHA256(appSecret, timestamp + "\n" + appSecret))`. |
public String decrypt(String encryptBase64) | 设置该参数。 Decrypts the `encrypt` body field and returns the inner JSON payload as a UTF-8 string. |
public boolean hasAesKey() | 判断是否具有 `hasAesKey`。 Returns whether this channel is configured with an `aesKey` (encrypted callbacks). |
构造器详情Constructor Detail
DingTalkCallbackCrypto
public DingTalkCallbackCrypto(String appSecret, String aesKey)
初始化 DingTalkCallbackCrypto 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
appSecret | String | 应用密钥(类型 `String`)。The app secret. |
aesKey | String | aes 键(类型 `String`)。The aes key. |
io/agentscope/extensions/channel/dingtalk/DingTalkCallbackCrypto.java:69–90方法详情Method Detail
verify
public boolean verify(String timestamp, String sign)
执行 verify 方法。
Verifies the timestamp/sign request headers of a callback: the timestamp must be a millisecond epoch no older than #MAX_TIMESTAMP_AGE_MS and no further ahead of local time than #MAX_FUTURE_TIMESTAMP_MS, and sign must equal ` Base64(HmacSHA256(appSecret, timestamp + "\n…
| 名称Name | 类型Type | 说明Description |
|---|---|---|
timestamp | String | 时间戳(类型 `String`)。The timestamp. |
sign | String | sign(类型 `String`)。The sign. |
booleanio/agentscope/extensions/channel/dingtalk/DingTalkCallbackCrypto.java:98–125decrypt
public String decrypt(String encryptBase64)
设置该参数。
Decrypts the encrypt body field and returns the inner JSON payload as a UTF-8 string.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
encryptBase64 | String | encrypt 基类 64(类型 `String`)。The encrypt base 64. |
Stringio/agentscope/extensions/channel/dingtalk/DingTalkCallbackCrypto.java:139–166hasAesKey
public boolean hasAesKey()
判断是否具有 hasAesKey。
Returns whether this channel is configured with an aesKey (encrypted callbacks).
booleanio/agentscope/extensions/channel/dingtalk/DingTalkCallbackCrypto.java:169–171