夢想妖夏

今天小米米粉节

2014-04-08

据说前几天有读者说看到博主会抢购,就叫博主帮忙,
囧,大错特错,博主本就一穷孩纸,根本没钱买手机,所谓抢购,
只是在上班空闲时间,看看网页js了解下知识而已,博主不是抢购的技术大牛加黄牛,
博主做的是实实在在的体力活工作啊,只是偶尔有时间玩电脑的,

好吧,灰话不多说,今天是小米米粉节,小米商城有连续6场抢购活动,(小米真心是销售牛X啊,抓住了消费者的心理)
群里面的一个小伙伴(貌似是一名中学生,叫我帮忙抢购电信红米一台和红米note一台)
其中,电信红米直接手抢(点点鼠标就抢到了,说了,RP才是第一嘛o(* ̄▽ ̄*)ゞ,神马代码都是浮云)

这次编号我也懒得打码了23333
dianxin_hongmi

hongmi_dingdan

接下来是抢购红米note页面,
进入http://p.www.xiaomi.com/zt/140408/www/chooseCommon.html?pro=note

看到里面的js文件,

var Tools = {
	getQueryString: function(a) {
		var b = new RegExp("(^|&)" + a + "=([^&]*)(&|$)", "i"),
			c = window.location.search.substr(1).match(b);
		return null !== c ? unescape(c[2]) : null
	},
	Cookie: function(a, b, c) {
		if (arguments.length > 1 && "[object Object]" !== String(b)) {
			if (c = jQuery.extend({}, c), (null === b || void 0 === b) && (c.expires = -1), "number" == typeof c.expires) {
				var d = c.expires,
					e = c.expires = new Date;
				e.setDate(e.getDate() + d)
			}
			return b = String(b), document.cookie = [encodeURIComponent(a), "=", c.raw ? b : encodeURIComponent(b), c.expires ? "; expires=" + c.expires.toUTCString() : "", c.path ? "; path=" + c.path : "", c.domain ? "; domain=" + c.domain : "", c.secure ? "; secure" : ""].join("")
		}
		c = b || {};
		var f, g = c.raw ? function(a) {
				return a
			} : decodeURIComponent;
		return (f = new RegExp("(?:^|; )" + encodeURIComponent(a) + "=([^;]*)").exec(document.cookie)) ? g(f[1]) : null
	}
}, productData = {
		dianyuan: {
			name: "5200mAh小米移动电源",
			pic: "http://img03.mifile.cn/webfile/images/hd/2014040801/www-choose/dianyuan-5200.jpg",
			desc: "全铝合金金属外壳,LG / 三星进口电芯",
			page: "http://www.xiaomi.com/minidianyuan",
			price: "¥39",
			sku: "2140800001",
			status: 1
		},
		mibox: {
			name: "小米盒子",
			pic: "http://img03.mifile.cn/webfile/images/hd/2014040801/www-choose/hezi.jpg",
			desc: "高性能网络机顶盒,性能提升4倍",
			page: "http://hezi.xiaomi.com/",
			price: "¥299",
			sku: "2134900002",
			status: 1
		},
		note: {
			name: "红米Note移动版",
			pic: "http://img03.mifile.cn/webfile/images/hd/2014040801/www-choose/note.jpg",
			desc: "八核1.4GHz处理器,5.5吋大屏全贴合",
			page: "http://www.xiaomi.com/note",
			price: "¥799",
			sku: "2141200012",
			status: 1
		},
		mijian: {
			name: "米键",
			pic: "http://img03.mifile.cn/webfile/images/hd/2014040801/www-choose/mijian.jpg",
			desc: "超好玩的智能按键,米粉节1元特价首发",
			page: "http://p.www.xiaomi.com/zt/2014032804/index.html",
			price: "",
			sku: "2141400064",
			status: 1
		},
		miniwifi: {
			name: "小米随身WIFI",
			pic: "http://img03.mifile.cn/webfile/images/hd/2014040801/www-choose/miniwifi.jpg",
			desc: "插入已上网电脑,免费连WiFi",
			page: "http://www.xiaomi.com/miniwifi",
			price: "¥9.9<del>原价¥19.9</del>",
			sku: {
				white: "2140800026",
				black: "2135200033",
				blue: "2140300001",
				green: "2140400001",
				orange: "2140600001",
				red: "2140700019"
			},
			colorName: {
				white: "白色",
				black: "黑色",
				blue: "蓝色",
				green: "黄绿色",
				orange: "橙色",
				red: "玫红色"
			},
			status: {
				2140800026: 1,
				2135200033: 1,
				2140300001: 1,
				2140400001: 1,
				2140600001: 1,
				2140700019: 1
			}
		},
		huosai: {
			name: "小米活塞耳机简装版",
			pic: "http://img03.mifile.cn/webfile/images/hd/2014040801/www-choose/huosai.jpg",
			desc: "与活塞耳机相同音质,黑白两色",
			page: "http://www.xiaomi.com/huosai-jianzhuang",
			price: "¥4.9",
			sku: {
				white: "2141000002",
				black: "2141000001"
			},
			colorName: {
				white: "白色",
				black: "黑色"
			},
			status: {
				2141000001: 1,
				2141000002: 1
			}
		}
	}, chooseProduct = {
		init: function() {
			this.proSku = "", this.config = {
				startDate: "2014/04/08 ",
				startTimeArr: ["10:00", "12:00", "14:00", "16:00", "18:00", "20:00"],
				endTime: new Date("2014/04/08 22:00").getTime() / 1e3,
				nextTime: "",
				proArr: ["dianyuan", "mibox", "miniwifi", "note", "mijian", "huosai"],
				productName: Tools.getQueryString("pro"),
				productInfo: ""
			}, this.urls = {
				home: "http://www.xiaomi.com",
				orderUrl: "http://order.xiaomi.com",
				timestamp: "http://tm.hd.xiaomi.com/gettimestamp?_=" + (new Date).getTime(),
				hdinfo: "http://tp.hd.xiaomi.com/hdinfo/cn?_=" + (new Date).getTime(),
				hdget: "http://tp.hd.xiaomi.com/hdget/cn?product={{SKU}}&addcart=1&m=1&_=" + (new Date).getTime(),
				shopCart: "/cart/add/{{SKU}}?source=bigtap&token={{TOKEN}}&_=" + (new Date).getTime(),
				nextUrl: "/cart",
				noteNext: "http://p.www.xiaomi.com/zt/140408/www/www-buy-phone-succ.html?pro={{SKU}}",
				login: "https://www.account.xiaomi.com/pass/static/minilogin.html?third=http%253A%252F%252Forder.xiaomi.com%252Flogin%252Fcallback%253Ffollowup%253Dhttp%25253A%25252F%25252Fwww.xiaomi.com%25252F%2526sign%253DMjk4NmVlYzNiOWY5YTkwMjExNzg5MjkyNzE3ZmIxOGM4YTBiMDk1Mg%252C%252C%26sid%3Deshop&sid=eshop&callback=http%253A%252F%252Forder.xiaomi.com%252Flogin%252Fcallback%253Ffollowup%253Dhttp%25253A%25252F%25252Fwww.xiaomi.com%25252F%2526sign%253DMjk4NmVlYzNiOWY5YTkwMjExNzg5MjkyNzE3ZmIxOGM4YTBiMDk1Mg%252C%252C&sign=f%252FKB8SAfmaLZ0s28kcLtBSmZlEM%253D&inframe=true&1395759758226&inframe=true"
			}, this.cookies = {
				siteDomain: ".xiaomi.com",
				userId: "userId",
				order: "xm_order_btauth"
			};
			var a = this;
			return Tools.Cookie(a.cookies.userId) && Tools.Cookie(a.cookies.order) ? (a.checkTime(), (!a.config.productName || $.inArray(a.config.productName, a.config.proArr) < 0) && (location.href = a.urls.home), $("[data-close-target]").on("click", function() {
				var b = $(this).attr("data-close-target");
				return a.hideBox(b), !1
			}), $(document).on("click", ".J_buyTigger", function() {
				return !a.proSku || $(this).hasClass("btn-disabled") ? (alert("报错"), !1) : (a.startQueue(), a.getDmSys(), !1)
			}), $(document).on("click", ".J_color", function() {
				return $(this).hasClass("item-sold") || ($(this).addClass("on").siblings(".J_color").removeClass("on"), a.proSku = $(this).attr("data-sku"), $(this).parent(".color-list").siblings(".active").find(".btn").removeClass("btn-disabled").addClass("btn-primary J_buyTigger")), !1
			}), void $("#boxCacheBtn").on("click", function() {
				$(".J_buyTigger").trigger("click")
			})) : (this.showBox("Login"), !1)
		},
		checkTime: function() {
			var a = this;
			$.ajax({
				type: "GET",
				url: a.urls.timestamp,
				dataType: "jsonp",
				error: function() {},
				success: function() {}
			}), window.listenServerTime = setInterval(function() {
				if ("undefined" != typeof servertime && servertime) {
					var b = new Date(a.config.startDate + a.config.startTimeArr[0]).getTime() / 1e3,
						c = a.config.endTime;
					b > servertime || servertime > c ? location.href = a.urls.home : (a.getHdInfo(), a.checkNextTime()), clearInterval(window.listenServerTime), clearTimeout(window.listenTimeout)
				}
			}, 500), window.listenTimeout = setTimeout(function() {
				clearInterval(window.listenServerTime), a.getHdInfo()
			}, 5e3)
		},
		checkNextTime: function() {
			for (var a, b, c = this.config.startTimeArr.length, d = 0; c > d; d += 1) {
				if (a = new Date(this.config.startDate + this.config.startTimeArr[d]).getTime() / 1e3, !(5 > d)) {
					this.config.nextTime = this.config.startTimeArr[d];
					break
				}
				if (b = new Date(this.config.startDate + this.config.startTimeArr[d + 1]).getTime() / 1e3, servertime > a && b > servertime) {
					this.config.nextTime = this.config.startTimeArr[d + 1];
					break
				}
			}
		},
		getHdInfo: function() {
			var a = this;
			$.ajax({
				type: "GET",
				url: a.urls.hdinfo,
				dataType: "jsonp",
				jsonp: "jsonpcallback",
				jsonpCallback: "hdinfo",
				timeout: 3e4,
				error: function() {
					a.getInfoError()
				},
				success: function(b) {
					b && a.checkStatus(b.status)
				}
			})
		},
		getInfoError: function() {
			$(".J_loading").html('<p>抱歉,网络拥堵无法连接服务器。由于访问人数太多导致服务器压力山大,请<a href="javascript:location.reload();">刷新</a>页面重试~</p>')
		},
		checkStatus: function(a) {
			if (this.config.productInfo = productData[this.config.productName], $("#selectedProductName").html(this.config.productInfo.name), this.changeTitle(), "mijian" === this.config.productName || "huosai" === this.config.productName) return this.buildProductSale(), !1;
			if ("miniwifi" === this.config.productName) {
				var b = !0;
				for (k in this.config.productInfo.sku) a[this.config.productInfo.sku[k]].hdstart === !0 && a[this.config.productInfo.sku[k]].hdstop === !1 ? b = !1 : this.config.productInfo.status[k] = 0;
				b === !0 ? this.buildProductSold() : this.buildProductSale()
			} else a[this.config.productInfo.sku].hdstart === !0 && a[this.config.productInfo.sku].hdstop === !1 ? this.buildProductSale() : (this.buildProductSold(), this.config.productInfo.status = 0);
			this.changeTitle()
		},
		changeTitle: function() {
			document.title = "小米官网——购买" + this.config.productInfo.name
		},
		buildProductSale: function() {
			var a = $('<div class="product-box ' + this.config.productName + '"></div>'),
				b = $('<div class="product-pic"><img src="' + this.config.productInfo.pic + '" alt=""></div>'),
				c = $('<div class="product-info"></div>'),
				d = $('<h1 class="title">购买' + this.config.productInfo.name + "</h1>"),
				e = $('<p class="desc">' + this.config.productInfo.desc + "</p>"),
				f = $('<p class="price">' + this.config.productInfo.price + "</p>"),
				g = "",
				h = $('<p class="active"><button  class="btn btn-primary J_buyTigger">立即购买</button><br><a href="http://www.xiaomi.com">返回活动首页</a> <a href="' + this.config.productInfo.page + '" target="_blank">了解产品</a></p>');
			if ("miniwifi" === this.config.productName || "huosai" === this.config.productName) {
				g = $('<div class="color-list"><h5>请选择颜色</h5></div>');
				var i;
				for (k in this.config.productInfo.sku) i = 1 !== this.config.productInfo.status[this.config.productInfo.sku[k]] ? "item-sold" : "", g.append('<a class="item ' + i + '  J_color" data-sku="' + this.config.productInfo.sku[k] + '">' + this.config.productInfo.colorName[k] + "</a>");
				h.find(".btn").removeClass("btn-primary J_buyTigger").addClass("btn-disabled"), c.append(d, e, f, g, h)
			} else c.append(d, e, f, h);
			a.append(b, c), $("#chooseBox").html(a), this.proSku = this.config.productInfo.sku
		},
		buildProductSold: function() {
			var a = $('<div class="product-over-tip"></div>'),
				b = $("<h3>本轮<span>" + this.config.productInfo.name + "</span>已售罄</h3>"),
				c = $('<p class="txt">下一轮将在<span class="next-time">' + this.config.nextTime + "</span>准时开始<br>您可以稍后再来试试或者尝试购买其他产品</p>"),
				d = $('<p><a href="http://www.xiaomi.com" class="btn btn-primary">返回活动首页</a></p>');
			("mijian" === this.config.productName || "huosai" === this.config.productName) && (c = $('<p class="txt">您可以尝试购买其他产品</p>'));
			var e = new Date(this.config.startDate + this.config.startTimeArr[5]).getTime() / 1e3;
			servertime > e && ("note" === this.config.productName ? (c = $('<p class="txt">成功购买用户请在2小时内下单支付<br>没买到的用户也可预约4月15日下轮开放购买。</p>'), d = $('<p><a href="http://www.xiaomi.com" class="btn btn-primary">返回活动首页</a><a href="http://p.www.xiaomi.com/open/index.html#goodsList" target="_blank" class="btn btn-primary">预约开放购买</a></p>')) : c = $('<p class="txt">成功购买用户请在2小时内下单支付,逾期将取消订单。</p>')), a.append(b, c, d), $("#chooseBox").html(a)
		},
		getDmSys: function() {
			var a = this,
				b = "";
			b = a.urls.hdget.replace("{{SKU}}", a.proSku), $.ajax({
				type: "GET",
				url: b,
				dataType: "jsonp",
				jsonp: "jsonpcallback",
				jsonpCallback: "hdcontrol",
				timeout: 3e4,
				error: function() {
					return a.inTheQueue ? (a.hideBox("Queue"), void a.showBox("Cache")) : !1
				},
				success: function(b) {
					var c = b.status,
						d = c[a.proSku].hdurl,
						e = c[a.proSku].hdstart === !1 && c[a.proSku].hdstop === !0 ? !0 : !1,
						f = b.d22a51 ? 1e3 * b.d22a51 : 5e3;
					return a.inTheQueue ? b.login === !1 ? (a.hideBox("Queue"), a.showBox("Login"), !1) : e === !0 ? (a.setOverInfo(), !1) : (a.getDmTimer && clearInterval(a.getDmTimer), void(d ? a.getShopCart(d) : (a.inTheQueue || a.startQueue(), a.getDmTimer = setInterval(function() {
						a.getDmSys()
					}, f)))) : !1
				}
			})
		},
		setOverInfo: function() {
			var a = this;
			a.hideBox("Queue"), a.showBox("Tip"), a.buildProductSold(), a.proSku = "", $(".J_buyTrigger").addClass("btn-disabled").prop("disabled", !0)
		},
		getShopCart: function(a) {
			if (!a) return !1;
			var b = this,
				c = b.urls.orderUrl + b.urls.shopCart.replace("{{SKU}}", b.proSku).replace("{{TOKEN}}", a);
			$.ajax({
				type: "GET",
				url: c,
				dataType: "jsonp",
				jsonp: "jsonpcallback",
				success: function(a) {
					if (b.hideBox("Queue"), 1 === a.code) {
						var c = "";
						c = "note" !== b.config.productName ? b.urls.orderUrl + b.urls.nextUrl : b.urls.noteNext.replace("{{SKU}}", b.proSku), location.href = c
					} else b.errorTip(2003009 === a.code ? a.message + '<a href="http://order.xiaomi.com/cart">查看购物车</a>' : a.message)
				}
			})
		},
		startQueue: function() {
			var a = this;
			a.hideBox("Cache"), a.showBox("Queue"), a.queueAnimate(), a.inTheQueue = !0
		},
		stopQueue: function() {
			this.inTheQueue = !1, this.getDmTimer && clearInterval(this.getDmTimer), window.queueAnimateTimer && clearInterval(queueAnimateTimer)
		},
		queueAnimate: function() {
			var a = 0,
				b = 200,
				c = function() {
					a -= 90, -900 >= a && (a = 0), $("#queueAnimate").css({
						"background-position": a + "px 0"
					})
				};
			window.queueAnimateTimer = setInterval(c, b)
		},
		showBox: function(a) {
			var b = $("#box" + a),
				c = $("body").outerWidth(),
				d = $("body").outerHeight() > $(window).height() ? $("body").outerHeight() : $(window).height();
			$("#boxBg").css({
				width: c,
				height: d
			}).show(), b.show()
		},
		hideBox: function(a) {
			$("#boxBg").hide(), $("#box" + a).hide(), "Queue" === a && this.inTheQueue === !0 && this.stopQueue()
		},
		setCookie: function(a, b, c) {
			var d = {
				path: "/",
				domain: ".xiaomi.com",
				expires: 1
			};
			$.extend(d, c), Tools.Cookie(a, b, d)
		},
		errorTip: function(a) {
			$("#box-error-tip").html(a), this.showBox("Error")
		}
	};
$(document).ready(function() {
	chooseProduct.init()
});

浏览器控制台调用里面的方法;
chooseProduct.buildProductSale()

到点的时候,直接点击抢购按钮,或者用博主前几篇文章提到过的js定时器,让js自动提交请求,RP第一,多开几个标签吧2333
2014.04.08_03h42m32s_001_

控制台脚本

var tSeconds=0;
var tMinutes=0;
var tHours=0;
var timer=null;
function schedule(hours,minutes,seconds){
   tHours = hours;
   tMinutes = minutes;
   tSeconds = seconds;
   //TODO check..
   run();
}
function run(){
        var date=new Date();
        if((date.getMinutes()-tMinutes==0)
                &&(date.getSeconds()-tSeconds==0)
                &&(date.getHours()-tHours==0)){
                toDo();
                window.clearTimeout(timer);
        }else{
                timer = window.setTimeout("run()",1);
        }
}
function toDo(){
//ec.getStatus(1);$('btn-go').click();//要执行的代码
//Util.showBox('phone');
setInterval(function(){chooseProduct.buildProductSale();
$(".J_buyTigger").trigger("click");},300);
}
schedule(17,59,50);//在HHMMSS执行

意思是17:59:50开始,每隔300ms进行一次抢购请求,这都不行的话,完全是rp啦

标签:

Related Posts

24 Comments

  1. 好厉害支持

    2014.04.9 at 17:32
    #1  
  2. RP真好呀,点点鼠标就抢到了

    2014.04.10 at 14:53
    #2  
  3. 早知道就不用这么麻烦了。

    2014.04.10 at 15:09
    #3  
    • 啊?

      2014.04.10 at 15:34
      #31
      • 米粉节的时候宿舍的舍友抢得头破血流,最后还没抢到,如果早知道有这个,还何苦手动!

        2014.04.10 at 15:36
        #32
        • 这个也没用的,RP才是第一啊(>_<)

          2014.04.11 at 08:03
          #33
  4. 没钱再买手机,只能看看了

    2014.04.11 at 15:26
    #4  
  5. 没钱再买手机,只能看看了

    2014.04.12 at 14:06
    #5  
    • 我对手机配置不感冒,还是比较喜欢电脑配置

      2014.04.12 at 21:29
      #51
  6. 这个 楼主实验过没哦

    2014.04.16 at 10:22
    #6  
  7. maillot radioshack

    唔,就没有打算抢

    2014.04.16 at 11:28
    #7  
  8. 博主 能给我做一个抢小米4的么??

    2014.07.16 at 18:44
    #9  
  9. 路过瞅瞅,很早收藏的

    2014.10.10 at 13:37
    #10  
  10. 学习了

    2015.04.12 at 15:42
    #11  
  11. 学习了 

    2015.04.13 at 13:51
    #12  
  12. 顶一个 赞一个

    2015.05.1 at 15:17
    #13  
  13. 2015.06.18 at 13:15
    #14