-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmadan.go
204 lines (164 loc) · 4.57 KB
/
madan.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strings"
"github.com/PuerkitoBio/goquery"
"github.com/robertkrimen/otto"
)
var (
strFromMsgID string
strUin string
strKey string
strBiz string
strPassTicket string
sharehtmlAddress string
)
func main() {
// data := readfile("test.json")
// var txtJSON Wxjson
// err := json.Unmarshal(data, &txtJSON)
// if err != nil {
// fmt.Println("cuole")
// }
// var contentJSON General_msg_json
// err = json.Unmarshal([]byte(txtJSON.General_msg_list), &contentJSON)
// if err != nil {
// fmt.Println("cuole2")
// }
// for _, jst := range contentJSON.List {
// // fmt.Println(Jlist)
// if jst.Comm_msg_info.Type == 49 {
// htmlurl := strings.Replace(jst.App_msg_ext_info.Content_url, `amp;`, ``, -1)
// fmt.Println(htmlurl)
// }
// }
configSet();
if sharehtmlAddress != ""{
getWXDataHtml(sharehtmlAddress);
}
doForJsonData()
// dd := strings.Replace(cc, `amp;`, ``, -1)
}
type Wxjson struct {
Ret int64
Errmsg string
General_msg_list string
Bizuin_code string
Uin_code string
Key string
Is_friend int64
Is_continue int64
Count int64
}
type General_msg_json struct {
List []*Jlist
}
type Jlist struct {
Comm_msg_info *Comm_msg_json
App_msg_ext_info *App_msg_ext_json
Image_msg_ext_info *Image_msg_ext_Json
}
type Comm_msg_json struct {
Id int64
Type int64
Datetime int64
Fakeid string
Status int64
Content string
}
type Image_msg_ext_Json struct {
Length int64
Fileid int64
Mediaid int64
}
type App_msg_ext_json struct {
Title string
Digest string
Content string
Fileid int64
Content_url string
Source_url string
Cover string
Subtype int64
Is_multi int64
Multi_app_msg_item_list []string
Author string
}
func configSet() {
fi, err := os.Open("config.txt")
if err != nil {
fmt.Println("呃...")
} else {
temp, _ := ioutil.ReadAll(fi)
sharehtmlAddress =string(temp)
fmt.Println(sharehtmlAddress)
}
}
func getWXDataHtml(urlstr string) {
//通过GOquery获取内容,并取得第一个msgid,然后调用循环获取jsondata方法
doc, err := goquery.NewDocument(urlstr)
if err != nil {
fmt.Println(err)
return
}
// fmt.Println(doc.Html())
vm := otto.New()
vm.Run(doc)
uin,_ := vm.Get("uin")
key,_:=vm.Get("key")
biz,_:=vm.Get("biz")
passTicket,_:=vm.Get("pass_ticket")
formMsgID,_:=vm.Get("frmMsgId")
strUin,_ = uin.ToString()
strKey,_ = key.ToString()
strBiz,_ = biz.ToString()
strPassTicket,_ = passTicket.ToString()
strFromMsgID,_ = formMsgID.ToString()
fmt.Println(strUin)
fmt.Println(strKey)
fmt.Println(strBiz)
fmt.Println(strPassTicket)
fmt.Println(strFromMsgID)
// wxjsonAdd:=`https://mp.weixin.qq.com/mp/getmasssendmsg?__biz=`+ strBiz+`&uin=`+strUin+`&key=`+strKey+`&f=json&frommsgid=`+strFromMsgID+`&count=10&uin=`+strUin+`&key=`+strKey+`&pass_ticket=`+strPassTicket+`&wxtoken=&x5=0`
// doForJsonData()
}
func doForJsonData() {
jsonHtml :=`https://mp.weixin.qq.com/mp/getmasssendmsg?__biz=`+ strBiz+`&uin=`+strUin+`&key=`+strKey+`&f=json&frommsgid=`+strFromMsgID+`&count=10&uin=`+strUin+`&key=`+strKey+`&pass_ticket=`+strPassTicket+`&wxtoken=&x5=0`
doc, err := goquery.NewDocument(jsonHtml)
if err != nil {
fmt.Println(err)
return
}
var txtJSON Wxjson
err = json.Unmarshal([]byte(doc.Text()), &txtJSON)
if err != nil {
fmt.Println("cuole")
}
var contentJSON General_msg_json
err = json.Unmarshal([]byte(txtJSON.General_msg_list), &contentJSON)
if err != nil {
fmt.Println("cuole2")
}
for index, jst := range contentJSON.List {
// fmt.Println(Jlist)
if jst.Comm_msg_info.Type == 49 {
htmlurl := strings.Replace(jst.App_msg_ext_info.Content_url, `amp;`, ``, -1)
fmt.Println(htmlurl)
}
if index == len(contentJSON.List) -1{
strFromMsgID = string(jst.Comm_msg_info.Id)
}
}
}
func readfile(path string) []byte {
fi, err := os.Open(path)
if err != nil {
panic(err)
}
defer fi.Close()
fd, _ := ioutil.ReadAll(fi)
return fd
}