larksuite / oapi-sdk-go

larksuite oapi sdk by golang
MIT License
417 stars 85 forks source link

使用新版卡片回调消息格式不匹配,反序列化错误 #130

Open lxitgto opened 7 months ago

lxitgto commented 7 months ago

使用新版卡片回调消息格式不匹配,反序列化错误。

CardAction struct格式为v1格式,请问什么时候支持新版消息格式?

maemual commented 7 months ago

近期卡片新特性较多,人力比较紧张,还在推进中。 可以继续使用旧版的卡片回传交互使用。

Martin2877 commented 4 months ago

卡片回调一直报这个错误 json: cannot unmarshal string into Go struct field CardAction.Header of type []string]

sbaby1997 commented 2 months ago

这个问题非常影响使用呀!

maemual commented 2 months ago

@sbaby1997 升级最新版 v3.3.0,然后卡片回传交互选“卡片回传交互(旧)”

Martin2877 commented 2 months ago

All right. 鉴于官方还没修,我这里提出一个临时解决方法,大家可以参考:

package larkcard 文件中

  1. 修改 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"`
}
  1. 修改card.go中的 VerifySign方法,使用 eventEncryptKey
    if h.eventEncryptKey == "" {
            return nil
        }

...

      targetSign := Signature(requestTimestamp, requestNonce,h.eventEncryptKey,string(req.Body))
  1. 修改card.go中的 Signature 方法,使用 sha256加密
    h := sha256.New()
crazykun commented 1 month ago

新的改成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
    })