钉钉云课堂快速学习

https://www.cnblogs.com/1024th/p/12330849.html代码已经失效,在此基础上研究改进

public static var imPwd:String = "b18b6e42-b9a1-4c71-a721-e1ffbe82be48";
        
    public static RulesOption("自动学习")
    
        
    var m_AutoLearn: boolean = true;
    
    static function OnBeforeResponse(oSession: Session) {
        if (m_Hide304s && oSession.responseCode == 304) {
            oSession["ui-hide"] = "true";
        }
        oSession.utilDecodeResponse();
        try {
            // 只处理特定 URL 的请求
            if (oSession.fullUrl == "https://tbdx-saas-center-free.cn-hangzhou.log.aliyuncs.com/logstores/tbdx-saas-pc-web/track") {
                // 解码响应
                oSession.utilDecodeResponse();
                
                // 获取响应体
                var responseBody = oSession.GetRequestBodyAsString();
                FiddlerApplication.Log.LogString("响应体内容: " + responseBody);
                // 使用字符串方法提取 imPwd
                var imPwdKey = '\\"imPwd\\":\\"';
                var keyStartIndex = responseBody.IndexOf(imPwdKey);
                if (keyStartIndex >= 0) {
                    var valueStartIndex = keyStartIndex + imPwdKey.Length;
                    var valueEndIndex = responseBody.IndexOf("\",", valueStartIndex);
                    if (valueEndIndex > valueStartIndex) {
                        var    extractedImPwd = responseBody.Substring(valueStartIndex, valueEndIndex - valueStartIndex-1);
                        imPwd=extractedImPwd
                        FiddlerApplication.Log.LogString("成功提取 imPwd: " + extractedImPwd);
                    } else {
                        FiddlerApplication.Log.LogString("未找到 imPwd 结束引号");
                    }
                } else {
                    FiddlerApplication.Log.LogString("未找到 imPwd 字段");
                }
            }
        } catch (ex) {
            FiddlerApplication.Log.LogString("处理请求时出错: " + ex.Message);
        }


        if (m_AutoLearn && !oSession.GetRequestBodyAsString().Contains("\"courseTime\":9990,\"learnTime\":60,\"type\":2")
        && oSession.hostname == "saas.daxue.dingtalk.com" && oSession.PathAndQuery == "/dingtalk/course/record.jhtml"){
            FiddlerApplication.Log.LogString("FOUND!!!");
        
            // 固定参数(循环外)
            var method = oSession.RequestMethod;
            var url = oSession.fullUrl;
            var protocol = "HTTP/1.1";
            var body = oSession.GetRequestBodyAsString();
        
            // 1. 修改请求体(仅需一次)
            body = body.replace(/"courseTime":\d+,"learnTime":\d+,"type":\d+/g,"\"courseTime\":9990,\"learnTime\":60,\"type\":2");
        
            // 2. 提取ulcookie(仅需一次)
            var ulcookie = oSession.oRequest["ulcookie"];

        
            // 3. 发送10次请求(每次使用新时间戳)
            for (var j = 0; j < 10; j++) {
                // 每次循环生成新的时间戳
                var now = System.DateTime.UtcNow;
                var startTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
                var saastime = (now - startTime).TotalMilliseconds.ToString("F0");
            
                // 每次计算新的签名
                var saassign = "";
                if (ulcookie !== "") {
                    var input = imPwd + saastime + ulcookie;
                    var md5 = System.Security.Cryptography.MD5.Create();
                    var inputBytes = System.Text.Encoding.UTF8.GetBytes(input);
                    var hashBytes = md5.ComputeHash(inputBytes);
                    var sb = new System.Text.StringBuilder();
                    for (var k = 0; k < hashBytes.Length; k++) {
                        sb.Append(hashBytes[k].ToString("x2"));
                    }
                    saassign = sb.ToString();
                    FiddlerApplication.Log.LogString("请求 #" + (j+1) + " 签名: saastime=" + saastime + " → saassign=" + saassign);
                }
            
                // 每次构建新的请求
                var raw = method + " " + url + " " + protocol + "\r\n";
                var foundContentLength = false;
            
                // 构建请求头
                for (var i = 0; i < oSession.oRequest.headers.Count(); i++) {
                    var header = oSession.oRequest.headers[i].ToString();
                
                    // 跳过已有的签名头
                    if (header.StartsWith("saastime:", StringComparison.OrdinalIgnoreCase) || 
                    header.StartsWith("saassign:", StringComparison.OrdinalIgnoreCase)) {
                        continue;
                    }
                
                    // 更新Content-Length
                    if (header.StartsWith("Content-Length:", StringComparison.OrdinalIgnoreCase)) {
                        header = "Content-Length: " + body.Length;
                        foundContentLength = true;
                    }
                
                    raw += header + "\r\n";
                }
            
                // 添加新的签名头
                raw += "saastime: " + saastime + "\r\n";
                raw += "saassign: " + saassign + "\r\n";
            
                // 确保有Content-Length
                if (!foundContentLength && body.Length > 0) {
                    raw += "Content-Length: " + body.Length + "\r\n";
                }
            
                raw += "\r\n" + body;
            
                // 发送请求
                try {
                    FiddlerObject.utilIssueRequest(raw);
                    FiddlerApplication.Log.LogString("请求 #" + (j+1) + " 已发送");
                
                    // 等待5秒(但避免最后一次等待)
                    if (j < 9) System.Threading.Thread.Sleep(5000);
                } catch (e) {
                    FiddlerApplication.Log.LogString("请求 #" + (j+1) + " 发送失败: " + e.Message);
                }
            }
        }
    }

 

posted @ 2025-06-06 10:16  Xpand  阅读(12)  评论(0)    收藏  举报