silenceper / wechat

WeChat SDK for Go (微信SDK:简单、易用)
https://silenceper.com/wechat/
Apache License 2.0
4.79k stars 1.08k forks source link

fix CallbackMessage open_kfid and SyncMsg error #672

Closed popstk closed 1 year ago

popstk commented 1 year ago
  1. open_kfid xml Unmarshal error
    
    const exp = `<xml>
    <ToUserName><![CDATA[ww12345678910]]></ToUserName>
    <CreateTime>1348831860</CreateTime>
    <MsgType><![CDATA[event]]></MsgType>
    <Event><![CDATA[kf_msg_or_event]]></Event>
    <Token><![CDATA[ENCApHxnGDNAVNY4AaSJKj4Tb5mwsEMzxhFmHVGcra996NR]]></Token>
    <OpenKfId><![CDATA[wkxxxxxxx]]></OpenKfId>
    </xml>`

type CallbackMessage struct { ToUserName string json:"to_user_name" // 微信客服组件ID CreateTime int json:"create_time" // 消息创建时间,unix时间戳 MsgType string json:"msgtype" // 消息的类型,此时固定为 event Event string json:"event" // 事件的类型,此时固定为 kf_msg_or_event Token string json:"token" // 调用拉取消息接口时,需要传此token,用于校验请求的合法性 OpenKfID string json:"open_kfid" xml:"OpenKfId" // 有新消息的客服帐号。可通过sync_msg接口指定open_kfid获取此客服帐号的消息 }

var ret CallbackMessage if err := xml.Unmarshal([]byte(exp), &ret); err != nil { panic(err) }

    fmt.Printf("%+v", ret)
if ret.OpenKfID != "wkxxxxxxx" {
    fmt.Println("err")
}


2.  'syncMsg: field `open_kfid` unexpected empty string. invalid Request Parameter'

open_kfid 没有默认值,因此空值需要忽略整个key,不然会报错