feat(chat): handle credit-gated send responses
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
这次新增/补齐的主要是这些字段,都是给前端判断“能不能继续发、当前内容锁不锁、扣了多少积分”用的。
|
||||
{
|
||||
"canSendMessage": false,
|
||||
"cannotSendReason": "insufficient_credits",
|
||||
"creditBalance": 0,
|
||||
"creditsCharged": 0,
|
||||
"requiredCredits": 2,
|
||||
"shortfallCredits": 2
|
||||
}
|
||||
字段含义
|
||||
canSendMessage
|
||||
用户是否还能继续发普通聊天消息。
|
||||
如果是 false,前端应该禁用输入框/发送按钮,提示充值。
|
||||
cannotSendReason
|
||||
不能继续发送消息的原因。
|
||||
目前主要是:
|
||||
insufficient_credits
|
||||
表示免费聊天次数用完,并且积分也不够继续发消息。
|
||||
creditBalance
|
||||
本次接口处理后的用户积分余额。
|
||||
比如原来 100,发了一条会员普通消息扣 2,这里返回 98。
|
||||
creditsCharged
|
||||
本次实际扣掉的积分。
|
||||
例如:
|
||||
普通聊天扣 2
|
||||
照片扣 40
|
||||
语音消息扣 20
|
||||
私密消息扣 10
|
||||
没有扣费就是 0
|
||||
requiredCredits
|
||||
本次动作理论上需要多少积分。
|
||||
比如用户想看照片,需要 40,就返回 40。
|
||||
如果免费额度内,通常是 0。
|
||||
shortfallCredits
|
||||
用户还差多少积分。
|
||||
比如照片需要 40,用户只有 15,则:
|
||||
{
|
||||
"requiredCredits": 40,
|
||||
"creditBalance": 15,
|
||||
"shortfallCredits": 25
|
||||
}
|
||||
和旧字段的关系
|
||||
blocked
|
||||
当前这条回复/内容是否被锁住。比如照片、语音、私密消息积分不够时是 true。
|
||||
blockReason
|
||||
当前内容被锁的原因,比如:
|
||||
insufficient_credits
|
||||
image_paywall
|
||||
voice_message
|
||||
private_message
|
||||
lockDetail
|
||||
给前端展示锁定卡片/充值提示的详细信息。
|
||||
里面也会带 requiredCredits/currentCredits/shortfallCredits,方便前端直接渲染弹窗。
|
||||
Reference in New Issue
Block a user