This Test

Posted 生产队的驴.

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了This Test相关的知识,希望对你有一定的参考价值。

程序使用C#语言开发,解决网课起床打卡的烦恼,所有完整代码都在下方,都有注释,大概500行左右

效果

封装好的类

using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _91窗口版

    internal static class _91Class
    
        static CookieContainer Cookie = new CookieContainer();

        public static string localCookie =string.Empty;//本地cookie
     
        public static string NetRequest(string str)
        
            var Beg = (HttpWebRequest)WebRequest.Create(str);

            if (localCookie == string.Empty)
            
                Beg.CookieContainer = Cookie;
                //扫码登录
                if (str == "https://service3.91suke.com/u/info")
                    Save(Beg.CookieContainer.GetCookieHeader(Beg.RequestUri));
                    //首次登录

            
            Beg.Headers.Add("Cookie", localCookie);//本地登录

            var Ret = Beg.GetResponse();
            var image = new StreamReader(Ret.GetResponseStream());
            string url = image.ReadToEnd();
            Ret.Dispose();

            return url;
        
        //发起请求 

        public static void Login(out string imageUrl, out string token)
        
            string json = NetRequest("https://orgservice.91suke.com/sk/wx/qrcode");
            JObject Ob = JObject.Parse(json);
            imageUrl = Ob["obj"]["url"].ToString();//二维码
            token = Ob["obj"]["ticket"].ToString();//效验码

            //登录

        

        public static void Save(string cookie)
        

        File.WriteAllText("user.lu",cookie);
            //保存登录信息
        
        

        public static bool LoginToken(string token)
        
            string json = NetRequest("https://service3.91suke.com/sk/check/login?ticket=" + token);
            if (json.Contains("操作成功")) return true;
            return false;//是否已经扫码
        


        public static void UserMessage(out string name, out string headImg,out string phone)
        

            string json = NetRequest("https://service3.91suke.com/u/info");
            JObject Obj = JObject.Parse(json);
            if (Obj["code"].ToString() == "200")
            
                //登录成功
                name = Obj["obj"]["nickName"].ToString();//m名字
                headImg = Obj["obj"]["headImg"].ToString();//头像
                phone = Obj["obj"]["phone"].ToString();//手机号

            
            else 
                name = null;
                headImg = null;
                phone = null;
            
            //登录个人信息
        

        public static void ClassList(out List<string> name,out List<string>  id)
        
        string json = NetRequest("https://service3.91suke.com/microclass/my/list?pageNo=1&pageSize=20&beyond=2&t="+ DateTimeOffset.UtcNow.ToUnixTimeMilliseconds());
            JObject Obj = JObject.Parse(json);
            JArray Arr = (JArray)Obj["list"]; 
           List<string>  ClassList=new List<string>(20);//名字
            List<string> ReportList = new List<string>(20);//班级ID         
            for (int i = 0; i < Arr.Count; i++)
            
                ClassList.Add(Arr[i]["courseName"].ToString());///名字
                ReportList.Add( Arr[i]["code"].ToString());//班级ID
            
            name = ClassList;
            id = ReportList;
            //课程表
        
        public static List<string> ReportList(string code)
        
            List<string> List = new List<string>(25);
            string json = NetRequest($"https://service3.91suke.com/microclass/teachingLog/list/code?pageNo=1&pageSize=15&order=2&t=DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()");
            JObject Obj = JObject.Parse(json);
            JArray Arr = (JArray)Obj["list"];
            for (int i = 0; i < Arr.Count; i++)
            
                if (Arr[i]["logType"].ToString() != "Checkin") continue;//判断签到 还是 作业

                DateTime dt = new DateTime(new DateTime(1970, 1, 1, 8, 0, 0).Ticks + Convert.ToInt64(Arr[i]["createTime"]) * 10000);

                List.Add(dt.ToString("MM-dd HH:mm:ss   ")+ Arr[i]["isComplete"]) ;
            

            return List;
            //签到状态列表
        

        public static List<string> ReportState(string code)
        
            List<string> List = new List<string>(10);
            string json = NetRequest($"https://service3.91suke.com/microclass/teachingLog/list/code?pageNo=1&pageSize=5&order=2&t=DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()");
            JObject Obj = JObject.Parse(json);
            JArray Arr = (JArray)Obj["list"];
            for (int i = 0; i < Arr.Count; i++)
                   
                  DateTime dt = new DateTime(new DateTime(1970, 1, 1, 8, 0, 0).Ticks + Convert.ToInt64(Arr[i]["createTime"]) * 10000);
                if (Arr[i]["isComplete"].ToString() == "False" && Arr[i]["logType"].ToString() == "Checkin"&&dt.Minute<50)               
                    List.Add(Arr[i]["target"].ToString());      
            

            return List;
        //返回未签到列表
        
        
        public static bool  Checkin(string id)
            
           try
            
                byte[] array = Encoding.UTF8.GetBytes($"id=id&status=0");
                var Beg = (HttpWebRequest)WebRequest.Create("https://service3.91suke.com/microclass/checkin/");
                Beg.Timeout = 1000 * 10;
                Beg.Method = "POST";
                Beg.ContentLength = array.Length;

                if (localCookie == string.Empty) Beg.CookieContainer = Cookie;
                Beg.Headers.Add("Cookie", localCookie);//本地登录

                Beg.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
                Stream st = Beg.GetRequestStream();
                st.Write(array, 0, array.Length);

                var Ret = Beg.GetResponse();
                var json = new StreamReader(Ret.GetResponseStream()).ReadToEnd();

       //     MessageBox.Show(json);

                if (json.Contains("操作成功")) return true;
                st.Dispose();
                Ret.Dispose();
           
           catch  
            return false ;
                  
        //签到



登录界面

using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _91窗口版

    public partial class UserLogin : Form
    
        public UserLogin()
        
            InitializeComponent();
        

        string imageUrl = string.Empty;
        string token = string.Empty;
        string phone=string.Empty;
       static string cookie=string.Empty;
        private void pictureBox1_Click(object sender, EventArgs e)
        
            _91Class.Login(out imageUrl, out token);
            pictureBox1.ImageLocation = imageUrl;
        

      

        private void Form1_Load(object sender, EventArgs e)
        
            _91Class.Login(out imageUrl, out token);//获取登录的二维码 和 token 
            pictureBox1.ImageLocation = imageUrl;
                    
          if(  File.Exists("user.lu"))
                
               cookie = File.ReadAllText("user.lu");
                if (cookie.Length > 50)
                                  

                    LoginLable.Text = "回到上次登录";
                 
                  
           
        

       

     

     

        private void Login_Tick(object sender, EventArgs e)
        
            if (_91Class.LoginToken(token))
            
                Login.Stop();

                var name = string.Empty;
                var headImg =string.Empty;
               
                
                _91Class.UserMessage(out name ,out headImg,out phone);
                UserUi u = new UserUi(name, headImg, phone);
                u.Show();
                this.Hide();

            

            //这里计时器
        

        private void LoginLable_Click(object sender, EventArgs e)
        
            _91Class.localCookie = cookie;

            var name = string.Empty;
            var headImg = string.Empty;
            _91Class.UserMessage(out name, out headImg,out phone);
           
            UserUi u = new UserUi(name, headImg,phone);
            u.Show();
            this.Hide();

            //点击上次 登录

        
    

登录成功

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _91窗口版

    public partial class UserUi : Form
    
        public UserUi() 
               
          InitializeComponent();
        

        public UserUi(string user,string headimg,string phone) : this()
        
            UsName .Text=user;
            HeadImg.ImageLocation = headimg;
            Phone.Text=phone;

        


        List<string> ClassName;
        //课程列表
        List<string> ClassId;
        //课程ID

        private void UserUi_Load(object sender, EventArgs e)
        
      //      HeadImg.ImageLocation = headurl;
            GraphicsPath gp = new GraphicsPath();
            gp.AddEllipse(HeadImg.ClientRectangle);
            Region region = new Region(gp);
            HeadImg.Region = region;//赋值
            gp.Dispose();//释放资源
            region.Dispose();//释放资源
                             //圆形头像框


           _91Class.ClassList(out ClassName,out ClassId);
            //课程列表

          for(int i =0;i<ClassName.Count;i++)
                ClassList.Items.Add(ClassName[i]);



        

       

        private void UserUi_FormClosing(object sender, FormClosingEventArgs e)
        
            //取消关闭窗口
            e.Cancel = true;
            //最小化主窗口
            this.WindowState = FormWindowState.Minimized;
           
        

        private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
        
                
                if (this.WindowState == FormWindowState.Minimized)              
                    //还原窗体
                    this.WindowState = FormWindowState.Normal;
                   
                
                //激活窗体
                this.Activate();
            
        

       

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        
            Environment.Exit(0);
        

     
        private void StartBut_Click(object sender, EventArgs e)
        
            if (StartBut.Text == "开启签到监听")
            以上是关于This Test的主要内容,如果未能解决你的问题,请参考以下文章

我的班级的属性正在改变自己[关闭]

JS实现统一社会信用代码的效验(组织机构代码效验)

iview-form内table修改字段效验

Element-ui的使用(二):Form表单(基本效验)

自定义validate的效验规则

python 效验数据是否符合json格式