mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-10 15:52:26 +08:00
fix: 序列化 xml 时添加 cdata 标签
This commit is contained in:
@@ -148,10 +148,10 @@ type MixMessage struct {
|
|||||||
UnionID string `xml:"UnionId"`
|
UnionID string `xml:"UnionId"`
|
||||||
|
|
||||||
// 内容审核相关
|
// 内容审核相关
|
||||||
IsRisky bool `xml:"isrisky"`
|
IsRisky bool `xml:"isrisky"`
|
||||||
ExtraInfoJSON string `xml:"extra_info_json"`
|
ExtraInfoJSON string `xml:"extra_info_json"`
|
||||||
TraceID string `xml:"trace_id"`
|
TraceID string `xml:"trace_id"`
|
||||||
StatusCode int `xml:"status_code"`
|
StatusCode int `xml:"status_code"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//EventPic 发图事件推送
|
//EventPic 发图事件推送
|
||||||
@@ -178,20 +178,28 @@ type ResponseEncryptedXMLMsg struct {
|
|||||||
// CommonToken 消息中通用的结构
|
// CommonToken 消息中通用的结构
|
||||||
type CommonToken struct {
|
type CommonToken struct {
|
||||||
XMLName xml.Name `xml:"xml"`
|
XMLName xml.Name `xml:"xml"`
|
||||||
ToUserName string `xml:"ToUserName"`
|
ToUserName CDATA `xml:"ToUserName"`
|
||||||
FromUserName string `xml:"FromUserName"`
|
FromUserName CDATA `xml:"FromUserName"`
|
||||||
CreateTime int64 `xml:"CreateTime"`
|
CreateTime int64 `xml:"CreateTime"`
|
||||||
MsgType MsgType `xml:"MsgType"`
|
MsgType MsgType `xml:"MsgType"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CDATA string
|
||||||
|
|
||||||
|
func (c CDATA) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
||||||
|
return e.EncodeElement(struct {
|
||||||
|
string `xml:",cdata"`
|
||||||
|
}{string(c)}, start)
|
||||||
|
}
|
||||||
|
|
||||||
//SetToUserName set ToUserName
|
//SetToUserName set ToUserName
|
||||||
func (msg *CommonToken) SetToUserName(toUserName string) {
|
func (msg *CommonToken) SetToUserName(toUserName string) {
|
||||||
msg.ToUserName = toUserName
|
msg.ToUserName = CDATA(toUserName)
|
||||||
}
|
}
|
||||||
|
|
||||||
//SetFromUserName set FromUserName
|
//SetFromUserName set FromUserName
|
||||||
func (msg *CommonToken) SetFromUserName(fromUserName string) {
|
func (msg *CommonToken) SetFromUserName(fromUserName string) {
|
||||||
msg.FromUserName = fromUserName
|
msg.FromUserName = CDATA(fromUserName)
|
||||||
}
|
}
|
||||||
|
|
||||||
//SetCreateTime set createTime
|
//SetCreateTime set createTime
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ package message
|
|||||||
//Text 文本消息
|
//Text 文本消息
|
||||||
type Text struct {
|
type Text struct {
|
||||||
CommonToken
|
CommonToken
|
||||||
Content string `xml:"Content"`
|
Content CDATA `xml:"Content"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//NewText 初始化文本消息
|
//NewText 初始化文本消息
|
||||||
func NewText(content string) *Text {
|
func NewText(content string) *Text {
|
||||||
text := new(Text)
|
text := new(Text)
|
||||||
text.Content = content
|
text.Content = CDATA(content)
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user