oapi-sdk-go
oapi-sdk-go copied to clipboard
使用新版卡片回调消息格式不匹配,反序列化错误
使用新版卡片回调消息格式不匹配,反序列化错误。
CardAction struct
格式为v1格式,请问什么时候支持新版消息格式?
近期卡片新特性较多,人力比较紧张,还在推进中。 可以继续使用旧版的卡片回传交互使用。
卡片回调一直报这个错误 json: cannot unmarshal string into Go struct field CardAction.Header of type []string]
这个问题非常影响使用呀!
@sbaby1997 升级最新版 v3.3.0,然后卡片回传交互选“卡片回传交互(旧)”
All right. 鉴于官方还没修,我这里提出一个临时解决方法,大家可以参考:
在 package larkcard
文件中
- 修改
model.go
中的CardAction
type CardAction struct {
*larkevent.EventReq
Schema string `json:"schema"`
Header struct {
EventID string `json:"event_id"`
Token string `json:"token"`
CreateTime string `json:"create_time"`
EventType string `json:"event_type"`
TenantKey string `json:"tenant_key"`
AppID string `json:"app_id"`
} `json:"header"`
Challenge string `json:"challenge"`
Token string `json:"token"`
Type string `json:"type"`
Event struct {
Operator struct {
TenantKey string `json:"tenant_key"`
UserID string `json:"user_id"`
OpenID string `json:"open_id"`
UnionID string `json:"union_id"`
} `json:"operator"`
Token string `json:"token"`
Action struct {
Tag string `json:"tag"`
Timezone string `json:"timezone"`
FormValue map[string]string `json:"form_value"`
Name string `json:"name"`
} `json:"action"`
Host string `json:"host"`
Context struct {
OpenMessageID string `json:"open_message_id"`
OpenChatID string `json:"open_chat_id"`
} `json:"context"`
} `json:"event"`
}
- 修改
card.go
中的VerifySign
方法,使用 eventEncryptKey
if h.eventEncryptKey == "" {
return nil
}
...
targetSign := Signature(requestTimestamp, requestNonce,h.eventEncryptKey,string(req.Body))
- 修改
card.go
中的Signature
方法,使用 sha256加密
h := sha256.New()
新的改成event事件承载了 v3代码示例
.OnP2CardActionTrigger(func(ctx context.Context, event *callback.CardActionTriggerEvent) (*callback.CardActionTriggerReponse, error) {
fmt.Println("receive card action")
fmt.Println(larkcore.Prettify(event))
return nil, nil
})