Skip to content

Commit 69934b2

Browse files
committed
修复问题
1 parent 05b051c commit 69934b2

File tree

2 files changed

+42
-41
lines changed

2 files changed

+42
-41
lines changed

main.go

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"io"
99
"log"
1010
"net/http"
11+
"net/url"
1112
"strconv"
12-
"unsafe"
1313
"zyjs-lngbzx/utils"
1414
)
1515

@@ -28,8 +28,8 @@ type SaveViewRequest struct {
2828
}
2929

3030
type StartWatch struct {
31-
Id string `json:"id"`
32-
Status string `json:"status"`
31+
Id int `json:"id"`
32+
Status int `json:"status"`
3333
}
3434

3535
type Pages struct {
@@ -41,6 +41,7 @@ func Welcome() {
4141
fmt.Println("========================================================================")
4242
fmt.Println("欢迎使用辽宁-专业技术人员继续教育-观看软件!请先登录,完成选课,并拿到 Cookie !")
4343
fmt.Println("Cookie的获取可通过打开F12并随意找到此网站的一个请求 --> Headers --> Request Headers --> Cookie")
44+
fmt.Println("本软件仅供学习交流使用!")
4445
fmt.Println("========================================================================")
4546

4647
fmt.Println("请输入Cookie值(以 JSESSIONID= 开头)")
@@ -57,18 +58,16 @@ func main() {
5758
for i := 1; i <= page; i++ {
5859
fmt.Println("**********************************************")
5960
fmt.Println("开始观看第" + strconv.Itoa(i) + " 页")
60-
var resq = &Pages{PageNo: i, PageSize: 12}
61-
Len := unsafe.Sizeof(resq)
62-
testB := &SliceMock{
63-
addr: uintptr(unsafe.Pointer(resq)),
64-
cap: int(Len),
65-
len: int(Len),
66-
}
67-
data := *(*[]byte)(unsafe.Pointer(testB))
68-
docMain := utils.BuildHttp(mainUrl, cookieId, "POST", bytes.NewBuffer(data))
61+
//var pageData Pages
62+
pageData := url.Values{}
63+
pageData.Set("pageNo", strconv.Itoa(i))
64+
pageData.Set("pageSize", strconv.Itoa(12))
65+
pageDataString := pageData.Encode()
66+
pageDataByte := []byte(pageDataString)
67+
docMain := utils.BuildHttp(mainUrl, cookieId, "POST", bytes.NewReader(pageDataByte), true)
6968
idList := utils.GetClassList(docMain)
7069
for k, v := range idList {
71-
doc := utils.BuildHttp("https://zyjs.lngbzx.gov.cn/study/resource/info/"+k+"/"+v, cookieId, "GET", nil)
70+
doc := utils.BuildHttp("https://zyjs.lngbzx.gov.cn/study/resource/info/"+k+"/"+v, cookieId, "GET", nil, false)
7271
GetClassDetail(doc)
7372
}
7473
}
@@ -106,46 +105,45 @@ func GetClassDetail(doc *goquery.Document) {
106105
}
107106

108107
func WatchVideo(value, title, length, id string) {
109-
url := "https://zyjs.lngbzx.gov.cn/study/resource/saveview"
110-
var resq = &SaveViewRequest{json: "{'cid':" + id + ",'source': " + value + ",'position': '','percent': '0'}"}
111-
Len := unsafe.Sizeof(resq)
112-
testB := &SliceMock{
113-
addr: uintptr(unsafe.Pointer(resq)),
114-
cap: int(Len),
115-
len: int(Len),
116-
}
117-
data := *(*[]byte)(unsafe.Pointer(testB))
118-
req, err := http.NewRequest("POST", url, bytes.NewBuffer(data))
108+
videoUrl := "https://zyjs.lngbzx.gov.cn/study/resource/saveview"
109+
videoData := url.Values{}
110+
videoData.Set("json", "{'cid':"+id+",'source': "+value+",'position': '','percent': '0'}")
111+
videoDataString := videoData.Encode()
112+
videoDataByte := []byte(videoDataString)
113+
client := http.Client{}
114+
req, err := http.NewRequest("POST", videoUrl, bytes.NewReader(videoDataByte))
119115
if err != nil {
120116
log.Fatal("观看视频:" + title + " 失败!")
121117
}
122-
defer req.Body.Close()
123-
//fmt.Println(req.Body)
124-
body, err := io.ReadAll(req.Body)
118+
req.Header.Add("Cookie", cookieId)
119+
req.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
120+
res, err := client.Do(req)
121+
defer res.Body.Close()
122+
//fmt.Println(res, res.Body)
123+
body, err := io.ReadAll(res.Body)
125124
var sw StartWatch
126125
_ = json.Unmarshal(body, &sw)
126+
//fmt.Println(body, sw)
127127
randomId := sw.Id
128-
EndWatch(randomId, id, title, length)
128+
EndWatch(strconv.Itoa(randomId), id, title, length)
129129
}
130130

131131
func EndWatch(randomId string, id string, title string, length string) {
132-
url := "https://zyjs.lngbzx.gov.cn/study/resource/saveview"
133-
var resq = &SaveViewRequest{
134-
json: "{'cid':" + id + ",'historyId': " + randomId + ",'position': " + length + ",'len': " + length + ",'position':" + "'822.07' }",
135-
}
136-
Len := unsafe.Sizeof(resq)
137-
testB := &SliceMock{
138-
addr: uintptr(unsafe.Pointer(resq)),
139-
cap: int(Len),
140-
len: int(Len),
141-
}
142-
data := *(*[]byte)(unsafe.Pointer(testB))
143-
req, err := http.NewRequest("POST", url, bytes.NewBuffer(data))
132+
endUrl := "https://zyjs.lngbzx.gov.cn/study/resource/saveview"
133+
videoData := url.Values{}
134+
videoData.Set("json", "{'cid':"+id+",'historyId': "+randomId+",'position': "+length+",'len': "+length+",'position':"+"'822.07' }")
135+
videoDataString := videoData.Encode()
136+
videoDataByte := []byte(videoDataString)
137+
client := http.Client{}
138+
req, err := http.NewRequest("POST", endUrl, bytes.NewReader(videoDataByte))
139+
req.Header.Add("Cookie", cookieId)
140+
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
141+
res, err := client.Do(req)
142+
defer res.Body.Close()
144143
if err != nil {
145144
log.Fatal("观看视频:" + title + " 失败!")
146145
} else {
147146
fmt.Println("观看 " + title + " 完成!")
148147
fmt.Println("=============================")
149148
}
150-
defer req.Body.Close()
151149
}

utils/buildhttp.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ import (
77
"net/http"
88
)
99

10-
func BuildHttp(url string, cookieId string, method string, body io.Reader) *goquery.Document {
10+
func BuildHttp(url string, cookieId string, method string, body io.Reader, formData bool) *goquery.Document {
1111
client := http.Client{}
1212
req, err := http.NewRequest(method, url, body)
1313
if err != nil {
1414
log.Fatal(err)
1515
}
1616
req.Header.Add("Cookie", cookieId)
17+
if formData {
18+
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
19+
}
1720
res, err := client.Do(req)
1821
if err != nil {
1922
log.Fatal(err)

0 commit comments

Comments
 (0)