123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- var arrTime=[],token='',signDay=''//弹框提示内容;
- // 首次进入firstTime---true
- // var cid='1005',imei='865224035649367',androidId='6c735b635fe943c852e8392152f20ac8',version='1.5.4',secretkey='3d0e4b94e04b8dcca1cedb9c33051173',goldCount='',gameId=''//金币数;
- var cid='',imei='',androidId='',version='',goldCount='',gameId='',//金币数;
- exchangeMinCoin='',//最小兑换数
- lastTime='',//剩余时间
- secretkey='3d0e4b94e04b8dcca1cedb9c33051173',
- hasGame=false,
- data={},
- token1="";
- var id = parseQueryString("id")?parseQueryString("id"):false;// 游戏id
- var firstTime = parseQueryString("firstTime")?parseQueryString("firstTime"):false// 判断是否是首次进入
- // 弹框:1.获取金币 2.未到时段 3.游戏完成获取金币 4.兑换弹框
- $().ready(function(){
- getToken();
- })
- function getToken() {
- try {
- data=JSON.parse(taskObj.jsGetToken());
- cid=data.cid,imei=data.imei,androidId=data.androidId,version=data.version,token1=data.token
- // 获取金币
- getList();
- if(!id&&firstTime=='false'||!firstTime) {
- startInit()
- }
- if(id) {
- getNew();
- }
- }catch(e) {
- getList();
- if(firstTime=='false'||!firstTime) {
- startInit();
- }
- if(id) {
- hasGame=true;
- getNew();
- }
- }
- }
- function getNew() {
- var time1=new Date().getTime();
- sign=md5("time="+time1+'3d0e4b94e04b8dcca1cedb9c33051173')
- $.ajax({
- type: 'post',
- url: '/api/V3/getTaskAddCoin',
- headers:{
- token:token1,
- cid:cid,//渠道号暂时写死
- imei:imei,
- time:time1,
- sign:sign,
- androidId:androidId
- },
- success: function (res) {
- var res=JSON.parse(res)
- if (res && res.code == 0) {
- hasGame=true
- coin=res.res.totalCoin
- initGold(2)
- // id不包含999或者id不等于-1
- if(id.indexOf("999")==-1) {
- if(id!=-1) {
- taskObj.has_game_done(Number(res.res.addCoin),Number(coin))
- }
- // }else {
- // initGold(1)
- }
- }else {
- showMsg(res.message)
- }
- },
- error: function () {
- showMsg('网络错误,请稍后再试!')
- }
- })
- }
- function getList() {
- var time1=new Date().getTime();
- sign=md5("time="+time1+'3d0e4b94e04b8dcca1cedb9c33051173')
- $.ajax({
- type: 'post',
- url: '/api/V3/gameList',
- headers:{
- token:token1,
- cid:cid,//渠道号暂时写死
- imei:imei,
- time:time1,
- sign:sign,
- androidId:androidId
- },
- success: function (res) {
- var res=JSON.parse(res)
- if (res && res.code == 0) {
- var conHtml=''
- for(var i in res.res) {
- if(res.res[i].top==0) {
- conHtml+='<li onclick=toGame("'+escape(res.res[i].url)+","+escape(res.res[i].id)+'")><img src="'+res.res[i].icon+'" alt=""><div class="text"><div class="luck">'+res.res[i].title+'</div><p>'+res.res[i].desc+'</p></div><div class="get">'+res.res[i].button+'</div></li>'
- }else {
- var otherCon='<img src="'+res.res[i].icon+'" alt=""><div class="text"><div class="luck">'+res.res[i].title+'</div><p>'+res.res[i].desc+'</p></div><div class="get">领取</div><div class="notice-text"><img class="guide" src="./img/guide.png" alt=""><div><p>全新赚钱模块上线</p><p>快速赚到<span>30元</span>零钱</p></div></div>'
- $(".award").html(otherCon)
- }
- if(res.res[i].top==1) {
- gameId=res.res[i].id
- }
- }
- $("ul").html(conHtml)
- checkShow();
- }else {
- showMsg(res.message)
- }
- },
- error: function () {
- showMsg('网络错误,请稍后再试!')
- }
- })
- }
- // 签到
- function initGold(type) {
- var time1=new Date().getTime();
- arr=["type="+type,"time="+time1]
- data= {
- type: type,
- }
- var sign=arr.join("&")
- sign=md5(sign+secretkey)
- $.ajax({
- type: 'post',
- url: '/api/V3/getUserAdvertStatus',
- headers:{
- token:token1,
- cid:cid,//渠道号暂时写死
- imei:imei,
- time:time1,
- sign:sign,
- androidId:androidId
- },
- data: data,
- success: function (res) {
- var res=JSON.parse(res)
- if (res && res.res.success == 1) {
- goldCount=res.res.coin;
- if(!id||id.indexOf("999")!=-1) {
- getGold(type)
- }
- }else {
- if(type==1) {
- initGold(2)//判断是否可以领取时段奖励
- }else if(type==2){
- if(res.res.seconds) {
- count_down(res.res.seconds,".text-wrapper div")
- lastTime=res.res.seconds
- $(".timeRange").show();
- }
- if(!id) {
- taskObj.excess_time(lastTime)//倒计时
- }else if(id.indexOf("999")!=-1) {
- taskObj.has_game_done(Number(0),Number(coin))
- }
- }else {
- getGold(type)
- }
- }
- },
- error: function () {
- showMsg('网络错误,请稍后再试!')
- }
- })
- }
- // 领取金币
- function getGold(type) {
- var time1=new Date().getTime();
- var arr=[]
- if(parseQueryString("question_id")) {
- arr=["question_id="+parseQueryString("question_id"),"type="+parseQueryString("id"),"time="+time1]
- data={
- type: type,
- question_id: parseQueryString("question_id")?parseQueryString("question_id"):''
- }
- }else {
- arr=["type="+type,"time="+time1]
- data= {
- type: type
- }
- }
- var sign=arr.join("&")
- sign=md5(sign+secretkey)
- $.ajax({
- type: 'post',
- url: '/api/V3/getAdvertCoin',
- headers:{
- token:token1,
- cid:cid,//渠道号暂时写死
- imei:imei,
- time:time1,
- sign:sign,
- androidId:androidId,
- version:version,
- },
- data:data,
- success:function (res) {
- var res=JSON.parse(res)
- if (res && res.code==0) {
- if(type==1||type==2) {
- taskObj.time_envelope(Number(res.res.days),Number(res.res.coin),Number(type))
- }else {
- taskObj.money_total(Number(res.res.gold))
- }
- }else {
- if(type==1) {
- getGold(2)//判断是否可以领取时段奖励
- }else if(type==2){
- $(".timeRange").show();
- count_down(res.res.seconds,".text-wrapper div");
- lastTime=res.res.seconds
- }
- }
- },
- error: function () {
- showMsg('网络错误,请稍后再试!')
- }
- })
- }
- function startInit() {
- var time1=new Date().getTime();
- sign=md5("time="+time1+secretkey)
- $.ajax({
- type: 'post',
- url: '/api/V3/getUserCoin',
- headers:{
- cid:cid,//渠道号暂时写死
- version:version,
- imei:imei,
- time:time1,
- sign:sign,
- token:token1,
- androidId:androidId
- },
- success: function (res) {
- var res=JSON.parse(res)
- if(res&&res.code==0) {
- var res=res.res
- $(".notice span").text(res.signMsg)
- $(".all .number").text(res.gold?res.gold:'0')
- $(".today .number").text(res.todayGold?res.todayGold:'0')
- $(".prize span").text(res.money?res.money:'0')
- $(".notice div").text(parseInt(res.signMoney))
- signDay=res.signDay
- exchangeMinCoin=res.exchangeMinCoin
- if(!id) {
- initGold(2);//先判断是否是签到
- }
- taskObj.h5_allTotal(Number(res.gold))
- }
- },
- error: function () {
- showMsg('网络错误,请稍后再试!')
- }
- })
- }
- $(".timeRange").on("click",function(){
- var target=$(".text-wrapper div").text().split(":");
- taskObj.excess_time(parseInt(target[0]*60)+parseInt(target[1]))
- })
- $(".right button").on("click",function(){
- taskObj.cash_money(parseInt($(".all .number").text()),parseInt(exchangeMinCoin),parseInt($(".today .number").text()))
- })
- function checkShow() {
- if(firstTime==='false'||!firstTime) {
- $(".award").removeClass("active");
- // $(".notice-text").hide();
- $(".bottom").hide();
- $("body").attr("style","")
- $(".mask").hide();
- // 进入默认奖励金币弹框
- // getToken();
- }else {
- $(".award").addClass("active");
- $(".notice-text").show();
- $(".notice-text").attr("style","display:block!important;")
- $(".mask").show();
- $("body").attr("style","overflow:hidden");
- $(".bottom").show();
- }
- }
- function hideAlert() {
- if(firstTime=='true') {
- firstTime=false
- checkShow()
- getToken();
- }
- }
- function adSize(){
- taskObj.onLayoutAdSize(351,88)
- }
- $(".prize").on("click",function(){
- taskObj.h5_wallet();
- })
- function toGame(data) {
- if(firstTime!='true') {
- var url=data.split(",")[0]
- var id=data.split(",")[1]?data.split(",")[1]:gameId
- id=id?id:gameId
- window.location.href=unescape(url)+"?id="+id
- }
- }
- function count_down(sec,time_html){
- //倒计时封装;
- var time = setTimeout(function(){count_down(sec,time_html)},1000);
- arrTime.push(time);//每次生成的定时器都单独有一个数组里的位置,避免了冲突
- var datatime=/^[\d]{4}-[\d]{1,2}-[\d]{1,2}( [\d]{1,2}:[\d]{1,2}(:[\d]{1,2})?)?$/ig,str='',conn,s;
- sec--;
- sec=Number(sec)
- if(sec == 0 || sec < 0){
- //倒计时结束时----都为0
- for (var i = arrTime.length - 1; i >= 0; i--) {
- clearInterval(arrTime[i]);//清除所有的定时器
- };
- $(".timeRange").hide();
- // initGold(2);
- }else{
- s={'分':Math.floor(sec/60),'秒':Math.floor(sec%60)};
- for(i in s){
- if(s[i] < 10){s[i] = '0' + s[i]};
- if(i != '秒'){
- str += s[i] + ":";
- }else {
- str += s[i] ;
- }
- }
- var html = str
- $(time_html).html(html)
- return html;
- // clearInterval(time);//清除所有的定时器
- }
- }
- function parseQueryString(variable) {
- var query = window.location.search.substring(1);
- var vars = query.split("&");
- for (var i=0;i<vars.length;i++) {
- var pair = vars[i].split("=");
- if(pair[0] == variable){return pair[1];}
- }
- return(false);
- }
|