增加可通过名片消息获取微信号功能
This commit is contained in:
parent
42ea1237ff
commit
ebf78902a7
@ -39,6 +39,10 @@ func TestMessage(t *testing.T) {
|
|||||||
if msg.IsMedia() {
|
if msg.IsMedia() {
|
||||||
fmt.Println(msg.Content)
|
fmt.Println(msg.Content)
|
||||||
}
|
}
|
||||||
|
if msg.IsCard() {
|
||||||
|
c, _ := msg.Card()
|
||||||
|
fmt.Println(c.Alias)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err := bot.Login(); err != nil {
|
if err := bot.Login(); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
42
message.go
42
message.go
@ -2,6 +2,7 @@ package openwechat
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/xml"
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -213,6 +214,17 @@ func (m *Message) GetFile() (*http.Response, error) {
|
|||||||
return nil, errors.New("unsupported type")
|
return nil, errors.New("unsupported type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取card类型
|
||||||
|
func (m *Message) Card() (*Card, error) {
|
||||||
|
if !m.IsCard() {
|
||||||
|
return nil, errors.New("card message required")
|
||||||
|
}
|
||||||
|
var card Card
|
||||||
|
content := XmlFormString(m.Content)
|
||||||
|
err := xml.Unmarshal([]byte(content), &card)
|
||||||
|
return &card, err
|
||||||
|
}
|
||||||
|
|
||||||
// 往消息上下文中设置值
|
// 往消息上下文中设置值
|
||||||
// goroutine safe
|
// goroutine safe
|
||||||
func (m *Message) Set(key string, value interface{}) {
|
func (m *Message) Set(key string, value interface{}) {
|
||||||
@ -315,12 +327,26 @@ type RecommendInfo struct {
|
|||||||
VerifyFlag int
|
VerifyFlag int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Article struct {
|
// 名片消息内容
|
||||||
}
|
type Card struct {
|
||||||
|
XMLName xml.Name `xml:"msg"`
|
||||||
func xmlFormString(text string) string {
|
BigHeadImgUrl string `xml:"bigheadimgurl,attr"`
|
||||||
lt := strings.ReplaceAll(text, "<", "<")
|
SmallHeadImgUrl string `xml:"smallheadimgurl,attr"`
|
||||||
gt := strings.ReplaceAll(lt, ">", ">")
|
UserName string `xml:"username,attr"`
|
||||||
br := strings.ReplaceAll(gt, "<br/>", "\n")
|
NickName string `xml:"nickname,attr"`
|
||||||
return strings.ReplaceAll(br, "&amp;", "&")
|
ShortPy string `xml:"shortpy,attr"`
|
||||||
|
Alias string `xml:"alias,attr"` // Note: 这个是名片用户的微信号
|
||||||
|
ImageStatus int `xml:"imagestatus,attr"`
|
||||||
|
Scene int `xml:"scene,attr"`
|
||||||
|
Province string `xml:"province,attr"`
|
||||||
|
City string `xml:"city,attr"`
|
||||||
|
Sign string `xml:"sign,attr"`
|
||||||
|
Sex int `xml:"sex,attr"`
|
||||||
|
Certflag int `xml:"certflag,attr"`
|
||||||
|
Certinfo string `xml:"certinfo,attr"`
|
||||||
|
BrandIconUrl string `xml:"brandIconUrl,attr"`
|
||||||
|
BrandHomeUr string `xml:"brandHomeUr,attr"`
|
||||||
|
BrandSubscriptConfigUrl string `xml:"brandSubscriptConfigUrl,attr"`
|
||||||
|
BrandFlags string `xml:"brandFlags,attr"`
|
||||||
|
RegionCode string `xml:"regionCode,attr"`
|
||||||
}
|
}
|
||||||
|
@ -37,3 +37,10 @@ func getWebWxDataTicket(cookies []*http.Cookie) string {
|
|||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func XmlFormString(text string) string {
|
||||||
|
lt := strings.ReplaceAll(text, "<", "<")
|
||||||
|
gt := strings.ReplaceAll(lt, ">", ">")
|
||||||
|
br := strings.ReplaceAll(gt, "<br/>", "\n")
|
||||||
|
return strings.ReplaceAll(br, "&amp;", "&")
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user