本文最后更新于 2024-07-06,文章内容可能已经过时。

每次新活动页手动收集优惠券信息比较麻烦,写了个FD的脚本。

用于访问活动页面自动显示优惠券、自动收集优惠券信息。具体点亮按钮还是需要手动修改优惠券。

IMG_20231010_170529_296.jpg

代码放到 OnBeforeResponse 下面就好了。

        // 修改美团的时间
        if(oSession.fullUrl.Contains("https://promotion.waimai.meituan.com/lottery/limitcouponcomponent/getTime")){
            var responseStr = oSession.GetResponseBodyAsString();
            var jsonStr = Fiddler.WebFormats.JSON.JsonDecode(responseStr); 
            jsonStr.JSONObject["data"] = 1696907790000;
            var mod_json = Fiddler.WebFormats.JSON.JsonEncode(jsonStr.JSONObject); 
            oSession.utilSetResponseBody(mod_json); 
        }
        
        // 显示优惠券
        if(oSession.fullUrl.Contains("https://market.waimai.meituan.com/gd/zc/renderinfo")){
            FiddlerObject.log("显示优惠券"); 
            var responseStr = oSession.GetResponseBodyAsString();
            var jsonStr = Fiddler.WebFormats.JSON.JsonDecode(responseStr);
            var couponInfo = jsonStr.JSONObject["data"];
            if (couponInfo != null) {
                for(var coupon in couponInfo){
                    if (coupon.Value != null) {
                        coupon.Value["render"] = true;
                    }
                }
            }
            var mod_json = Fiddler.WebFormats.JSON.JsonEncode(jsonStr.JSONObject); 
            oSession.utilSetResponseBody(mod_json); 
        }
        
        // 修改优惠券状态
        if(oSession.fullUrl.Contains("https://promotion.waimai.meituan.com/lottery/limitcouponcomponent/info")){
            FiddlerObject.log("处理请求参数...");
            var params = Fiddler.WebFormats.JSON.JsonDecode("{}").JSONObject;
            if (oSession.PathAndQuery.Contains("?")) {
                var queryString = oSession.PathAndQuery.Split("?")[1];
                var paramsStr = queryString.Split("&");
                for (var i:int = 0; i<paramsStr.Length; i++) {
                    var param = paramsStr[i].Split("=");
                    params[param[0]] = param[1];
                }
            }
            
            FiddlerObject.log("修改优惠券状态..."); 
            var responseStr = oSession.GetResponseBodyAsString();
            var jsonStr = Fiddler.WebFormats.JSON.JsonDecode(responseStr);
            var couponsInfo = jsonStr.JSONObject["data"]["couponInfo"];
            if (couponsInfo != null) {
                for(var coupon in couponsInfo){
                    if (coupon.Value != null) {
                        coupon.Value["status"] = 0;
                        FiddlerObject.log("收集到优惠券信息...");
                        
                        var couponInfo = Fiddler.WebFormats.JSON.JsonDecode("{}").JSONObject;
                        couponInfo["id"] = params["couponReferIds"];
                        couponInfo["gdId"] = params["gdPageId"];
                        couponInfo["pageId"] = params["pageId"];
                        couponInfo["instanceId"] = params["componentId"];
                        couponInfo["desc"] = coupon.Value["couponName"] + " " + coupon.Value["priceLimit"] + "-" + coupon.Value["couponValue"];
                        couponInfo["active"] = true;
                        FiddlerObject.log(Fiddler.WebFormats.JSON.JsonEncode(couponInfo));
                    }
                }
            }
            var mod_json = Fiddler.WebFormats.JSON.JsonEncode(jsonStr.JSONObject); 
            oSession.utilSetResponseBody(mod_json); 
        }

最终效果

IMG_20231010_170526_942.jpg