wxparse

package
v1.6.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package wxparse extracts structured info from wechat XML payloads stored in transfer / red-packet / favorite tables. Standalone parsers — no dep on the message_content enrich pipeline.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FavoriteInfo

func FavoriteInfo(content string) (title, desc, url string, err error)

FavoriteInfo extracts (title, description, url) from a favorite XML. Picks whichever inner item shape is populated. Non-nil err = parser drift.

func RedPacketInfo

func RedPacketInfo(content string) (wishing, sceneText string, err error)

RedPacketInfo extracts (wishing, sceneText) from a red-packet XML. Non-nil err = parser drift; empty fields with nil err = legitimately absent.

func StripMsgPrefix

func StripMsgPrefix(raw string) string

StripMsgPrefix trims the "wxid_xxx:\n" sender prefix WeChat prepends to group message content so xml.Unmarshal sees a clean XML document.

func TransferInfo

func TransferInfo(content string) (amount, des, memo string, err error)

TransferInfo extracts (amount, description, memo) from a transfer message XML. Returns a non-nil error on parse failure so callers can distinguish "no transfer payload in this message" (all fields empty, err nil) from "parser drifted on this WeChat schema" (err set).

Types

type ForwardItem

type ForwardItem struct {
	DataType         int              `json:"datatype"`
	DataID           string           `json:"dataid,omitempty"`
	SourceName       string           `json:"sourcename,omitempty"`
	SourceHeadURL    string           `json:"sourceheadurl,omitempty"`
	SourceTime       string           `json:"sourcetime,omitempty"`
	DataTitle        string           `json:"datatitle,omitempty"`
	DataDesc         string           `json:"datadesc,omitempty"`
	DataFmt          string           `json:"datafmt,omitempty"`
	FullMD5          string           `json:"fullmd5,omitempty"`
	DataSize         int64            `json:"datasize,omitempty"`
	CDNThumbURL      string           `json:"cdnthumburl,omitempty"`
	CDNThumbKey      string           `json:"cdnthumbkey,omitempty"`
	ThumbFullMD5     string           `json:"thumbfullmd5,omitempty"`
	ThumbSize        int64            `json:"thumbsize,omitempty"`
	CDNDataURL       string           `json:"cdndataurl,omitempty"`
	CDNDataKey       string           `json:"cdndatakey,omitempty"`
	SrcMsgLocalID    int64            `json:"src_msg_localid,omitempty"`
	SrcMsgCreateTime int64            `json:"src_msg_create_time,omitempty"`
	MessageUUID      string           `json:"messageuuid,omitempty"`
	FromNewMsgID     string           `json:"fromnewmsgid,omitempty"`
	Link             *ForwardLink     `json:"link,omitempty"`
	ReferMsg         *ForwardReferMsg `json:"refermsg,omitempty"`
	NestedItems      []ForwardItem    `json:"nested_items,omitempty"`
	// ParseError surfaces nested-forward (datatype=17) parse failure on this
	// item without losing the rest of the outer forward. Outer-XML parser
	// drift propagates as ForwardItems' returned error instead.
	ParseError string `json:"parse_error,omitempty"`
}

ForwardItem is a JSON-serializable view of one forwarded sub-message. Only populated fields are emitted (omitempty) so text items don't carry file-specific keys. NestedItems is set for datatype=17 (合并转发 nested).

func ForwardItems

func ForwardItems(content string, depth int) ([]ForwardItem, error)

ForwardItems extracts structured sub-messages from a forward_chat (subtype=19) XML. depth bounds nested-forward recursion (pass ≥1 to include nested; 0 keeps datatype=17 items but without NestedItems). Non-nil err = parser drift. Empty slice with nil err = legitimately not a forward / empty datalist. Binary/media payloads (cdndataurl / aeskey) are intentionally dropped — encrypted CDN pointers unusable without the WeChat client.

type ForwardLink struct {
	URL               string `json:"url,omitempty"`
	Title             string `json:"title,omitempty"`
	ThumbURL          string `json:"thumb_url,omitempty"`
	SourceUsername    string `json:"source_username,omitempty"`
	SourceDisplayName string `json:"source_display_name,omitempty"`
}

type ForwardReferMsg

type ForwardReferMsg struct {
	Type        int    `json:"type,omitempty"`
	SvrID       string `json:"svrid,omitempty"`
	DisplayName string `json:"displayname,omitempty"`
	Content     string `json:"content,omitempty"`
	ReferDesc   string `json:"referdesc,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL