103 lines
3.1 KiB
Go
103 lines
3.1 KiB
Go
package xuexitong
|
|
|
|
//
|
|
//import (
|
|
// "context"
|
|
// "errors"
|
|
// "likedream-goframe/internal/application/recognizer/ddddocr"
|
|
// "likedream-goframe/internal/application/xuexitong/entity"
|
|
// "likedream-goframe/internal/framework/logger"
|
|
// "likedream-goframe/internal/utils"
|
|
// "strings"
|
|
//
|
|
// "github.com/bytedance/sonic"
|
|
// ort "github.com/yalue/onnxruntime_go"
|
|
// "resty.dev/v3"
|
|
//)
|
|
//
|
|
//const (
|
|
// ApiPullCourses = "https://mooc1-api.chaoxing.com/mycourse/backclazzdata"
|
|
//)
|
|
//
|
|
//type XuexitongCourse struct {
|
|
// client *resty.Client
|
|
//}
|
|
//
|
|
//func NewXuexitongCourse(client *resty.Client) *XuexitongCourse {
|
|
// return &XuexitongCourse{
|
|
// client: client,
|
|
// }
|
|
//}
|
|
//
|
|
//// PullCourseList 拉取学习通所有课程列表并返回
|
|
//func (c *XuexitongCourse) PullCourseList(ctx context.Context, retry int) (courseList []entity.XueXiTCourse, err error) {
|
|
// req := c.client.R()
|
|
// req.Header.Add("User-Agent", GetUA("mobile"))
|
|
// get, err := req.Get(ApiPullCourses)
|
|
// if err != nil {
|
|
// return nil, err
|
|
// }
|
|
// body := get.String()
|
|
// if strings.Contains(body, "很抱歉,您所浏览的页面不存在") && retry > 0 { //防止学习通抽风
|
|
// return c.PullCourseList(ctx, retry-1)
|
|
// }
|
|
// if strings.Contains(body, "请输入验证码") {
|
|
// logger.Logger.Warn("触发验证码,正在进行AI智能识别绕过.....")
|
|
// //todo ddddocr识别
|
|
// succ := false
|
|
// for i := 0; i < 5; i++ {
|
|
// codePath, err := ApiVerifyCode(c.client, 5)
|
|
// if err != nil {
|
|
// return nil, err
|
|
// }
|
|
// if codePath == "" { //如果path为空,那么可能是账号问题
|
|
// return nil, errors.New("无法正常获取学习通验证码,请检查对应url是否正常")
|
|
// }
|
|
// img, _ := utils.ReadImg(codePath) //读取验证码图片
|
|
// codeResult := ddddocr.SemiOCRVerification(img, ort.NewShape(1, 23))
|
|
// utils.DeleteFile(codePath) //删除验证码文件、
|
|
// if ApiPassVerifyCode(c.client, codeResult, 5) {
|
|
// succ = true
|
|
// break
|
|
// }
|
|
// }
|
|
// if !succ {
|
|
// return nil, errors.New("AI验证码识别失败,请检查对应url是否正常")
|
|
// }
|
|
// }
|
|
// var courseResult entity.XueXiTCourseJson
|
|
// err = sonic.Unmarshal([]byte(body), &courseResult)
|
|
// if err != nil {
|
|
// return nil, err
|
|
// }
|
|
// for _, channel := range courseResult.ChannelList {
|
|
// if channel.Content.Course.Data == nil {
|
|
// continue
|
|
// }
|
|
// for _, v := range channel.Content.Course.Data {
|
|
// flag := false
|
|
// course := entity.XueXiTCourse{
|
|
// Cpi: channel.Cpi,
|
|
// Key: strings.Split(strings.Split(v.CourseSquareUrl, "classId=")[1], "&userId")[0],
|
|
// CourseID: strings.Split(strings.Split(v.CourseSquareUrl, "courseId=")[1], "&personId")[0],
|
|
// CourseTeacher: v.Teacherfactor,
|
|
// CourseImage: v.Name,
|
|
// CourseDataID: v.Id,
|
|
// ContentID: channel.Content.Id,
|
|
// IsStart: channel.Content.Isstart,
|
|
// State: channel.Content.State,
|
|
// }
|
|
// for _, subCourse := range courseList {
|
|
// if subCourse.CourseID == course.CourseID {
|
|
// flag = true
|
|
// break
|
|
// }
|
|
// }
|
|
// if !flag {
|
|
// courseList = append(courseList, course)
|
|
// }
|
|
// }
|
|
// }
|
|
// return courseList, nil
|
|
//}
|