diff --git a/inMsg.go b/inMsg.go
index 1d7b1db..fd1be8f 100644
--- a/inMsg.go
+++ b/inMsg.go
@@ -41,14 +41,14 @@ type VideoMsg struct {
}
//short video
-type ShortVideo struct {
+type ShortVideoMsg struct {
MeidaId string
ThumbMediaId string
MsgId int64
}
//Location Info
-type Location struct {
+type LocationMsg struct {
Location_X float64
Location_Y float64
Scale int
@@ -69,3 +69,46 @@ func ReadCommonHeader(s string) CommonHeader {
xml.Unmarshal([]byte(s), &r)
return r
}
+
+//ReadTextMsg extract text message
+func ReadTextMsg(s string) TextMsg {
+ var r = TextMsg{}
+ xml.Unmarshal([]byte(s), &r)
+ return r
+}
+
+//ReadPicMsg extract text message
+func ReadPicMsg(s string) PicMsg {
+ var r = PicMsg{}
+ return r
+}
+
+//ReadVoiceMsg extract text message
+func ReadVoiceMsg(s string) VoiceMsg {
+ var r = VoiceMsg{}
+ return r
+}
+
+//ReadVideoMsg extract text message
+func ReadVideoMsg(s string) VideoMsg {
+ var r = VideoMsg{}
+ return r
+}
+
+//ReadShortVideoMsg extract text message
+func ReadShortVideoMsg(s string) ShortVideoMsg {
+ var r = ShortVideoMsg{}
+ return r
+}
+
+//ReadLocationMsg extract text message
+func ReadLocationMsg(s string) LocationMsg {
+ var r = LocationMsg{}
+ return r
+}
+
+//ReadLinkMsg extract text message
+func ReadLinkMsg(s string) LinkMsg {
+ var r = LinkMsg{}
+ return r
+}
diff --git a/inMsg_test.go b/inMsg_test.go
index 1782463..3a7c7c2 100644
--- a/inMsg_test.go
+++ b/inMsg_test.go
@@ -18,12 +18,8 @@ func TestReadCommonHeader(t *testing.T) {
h := ReadCommonHeader(msg)
assertEqual(t, h.ToUserName, "gh_f09231355c68", "ToUserName failed")
assertEqual(t, h.FromUserName, "oUN420bxqFqlx0ZQHciUOesZO3PE", "FromUserName failed")
+ assertEqual(t, h.CreateTime, int64(1492972518), "CreateTime Failed")
assertEqual(t, h.MsgType, "event", "MsgType failed")
- //for weird reasons assertEqual does not work for integer
- if h.CreateTime != 1492972518 {
- errmsg := fmt.Sprintf("CreateTime should be 1492972518, not %d", h.CreateTime)
- t.Error(errmsg)
- }
}
@@ -37,3 +33,97 @@ func assertEqual(t *testing.T, a interface{}, b interface{}, message string) {
message = fmt.Sprintf("%v != %v", a, b)
t.Fatal(message)
}
+
+func TestTxtMsg(t *testing.T) {
+ msg := `
+
+
+ 1348831860
+
+
+ 1234567890123456
+ `
+ h := ReadCommonHeader(msg)
+ m := ReadTextMsg(msg)
+ assertEqual(t, m.Content, "this is a test", "Content is not right")
+ assertEqual(t, h.MsgType, "text", "")
+ assertEqual(t, m.MsgId, int64(1234567890123456), "")
+}
+
+/*
+func TestingPicMsg(t *testing.T) {
+ msg := `
+
+
+ 1348831860
+
+
+
+ 1234567890123456
+ `
+}
+
+func TestingVoiceMsg(t *testing.T) {
+ msg := `
+
+
+1357290913
+
+
+
+
+1234567890123456
+`
+}
+
+func TestingVideoMsg(t *testing.T) {
+ msg := `
+
+
+1357290913
+
+
+
+1234567890123456
+`
+}
+
+func TestingShortVideoMsg(t *testing.T) {
+ msg := `
+
+
+1357290913
+
+
+
+1234567890123456
+`
+}
+
+func TestingLocationMsg(t *testing.T) {
+ msg := `
+
+
+1351776360
+
+23.134521
+113.358803
+20
+
+1234567890123456
+`
+}
+
+func TestingLinkMsg(t *testing.T) {
+ msg := `
+
+
+1351776360
+
+
+
+
+1234567890123456
+`
+}
+*/