外观
加密信封
Open POST 请求和平台加密响应都使用同一种信封结构:
json
{
"encrypted_key": "base64(RSA-OAEP(public_key, content_key))",
"biz_content": "base64(aes_gcm_nonce || aes_gcm_ciphertext || aes_gcm_tag)"
}算法
| 项目 | 算法 |
|---|---|
| 内容密钥 | 每次消息随机生成 32 字节 content_key。 |
| 非对称加密 | RSA-OAEP 加密 content_key。 |
| 业务内容加密 | AES-256-GCM 加密业务 JSON。 |
| 编码 | encrypted_key 和 biz_content 均使用 Base64。 |
请求加密
商户调用 Open POST 接口时:
- 生成业务 JSON。
- 随机生成 32 字节
content_key。 - 使用平台公钥
platform_public_keyRSA-OAEP 加密content_key,得到encrypted_key。 - 使用
content_keyAES-256-GCM 加密业务 JSON。 - 将
nonce || ciphertext || tag拼接后 Base64,得到biz_content。 - 对最终信封 JSON 计算签名并发送。
响应解密
Open POST 成功响应的 data 是平台返回给商户的加密信封。商户处理顺序:
- 校验响应
X-Signature。 - 使用商户私钥
merchant_private_key解密data.encrypted_key得到content_key。 - 使用
content_key解密data.biz_content。 - 解析解密后的业务 JSON。
明文 POST 不支持
当前协议不接受明文 POST 业务 JSON。明文调用会返回业务错误,例如:
json
{
"code": 11015,
"msg": "Open API 请求体必须是加密信封",
"data": null
}GET 不加密
GET 查询类接口只签名、不加密。平台不会在 GET 响应中返回收款账号、证件号、手机号等敏感原文。