之前的文章給大家講過微信投票的原理,小伙伴一再要求還需要演示一下微信投票代碼,好吧。那么就滿足一下大家的愿吧,不過本人不是技術男,就找技術要來了一段,有興趣的就拿去研究下吧。
看代碼也不要忘了看下美女
//執行腳本 function init(){ initIp(); } //定時操作,每秒執行一次 function demo(){ }setInterval("init()",1000); //隨機生成以ovgMdt開頭的27位微信openid(字母大小寫+數字) function createNum(){ var str = "ovgMdt", range = 21, arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; // 隨機產生 for(var i=0; i<range; i++){ pos = Math.round(Math.random() * (arr.length-1)); str += arr[pos]; } return str; } //提交請求 function initIp(){ var ip=createIp(); var num=createNum(); var $toopenid='ovgMdtSysi89sfInf0pdfg5T'; var submitData = { toopenid: $toopenid, openid: num }; $.ajax({ headers:{'x-forwarded-for':ip,'WL-Proxy-Client-IP':ip}, type: "POST", url: "xxxxxxxxxxxxxx", data: submitData, dataType: "json", beforeSend: function (http://www.aivtp.com/) {}, success: function (data) { if (data.code == 0) { $("#"+$toopenid).text(data.vote); if(data.today_vote >= 2){ $(".vote").addClass("red"); } $("#"+$toopenid).parent().find(".plus").css({"top":"186px","opacity":0}); $("#"+$toopenid).parent().find(".plus").stop().animate({"top":"176px","opacity":1},300,"swing").animate({"opacity":0},100); } else { alert(data.msg); } } }); } //生成隨機的ip地址 function createIp() { var a = Math.round(Math.random() * 250) + 1, b = Math.round(Math.random() * 250) + 1, c = Math.round(Math.random() * 240) + 1, d = Math.round(Math.random() * 240) + 1; return [a, b, c, d].join('.');
其實中重要的是兩個參數即,openid,和toopenid即openid是自己的微信id,toopenid是投票對象的微信id
openid即我們微信每關注一個公眾號都會產生一個不同的openid,如果我們關注十個微信號,那么就會有10個相對應openid。如果購買的微信號被封了,但opendi還在的話,那么依然可以繼續投票的。
微信投票原創版權,轉載請注明出處:http://www.theaussiezombie.com/huodongtoupiao/478.html