var oauthCode = getUrlParam("code"); // alert("当前地址:"+currentUrl); var openid = null; //进入openid处理流程 $.ajax({ url: api+"marketing/weixin/openidProcess", async: false, data: { abbreviationName: abbreviationName, oauthCode: oauthCode }, success: function (res) { if (res.code == 1) { hrefIndex(); } else { openid = res.data; } } }); //页面结构加载完成后执行 $(function() { //判断活动是否过期 if (!activityIsExpired()) { return false; } //获取并显示码对应的奖励,如果return false,就不继续向下执行 if (!showReward()) { return false; } //绑定单击事件 $("#receiveReward").on("click",function () { receiveReward(); }); //获取js-sdk签名 createJsapiSignature(currentUrl); //config信息验证成功后会执行ready方法 wx.ready(function() { getLocation( function (latitude,longitude) { scanRecord(latitude,longitude); }, function () { scanRecord('0.0','0.0'); } ); }); //config信息验证失败后会执行error方法 wx.error(function(res){ alert("获取凭据失败:"+res); }); }); //判断活动是否过期 function activityIsExpired(){ var flag = true; $.ajax({ url: api+"marketing/weixin/activityIsExpired", async: false, data: { abbreviationName: abbreviationName, activityId: activityId }, success: function (res) { //活动未开始或已结束 if (res.code != 0) { $.toast(res.msg, "cancel"); flag = false; } } }) return flag; } //获取并显示码对应的奖励 function showReward() { var flag = true; $.ajax({ url: api+"marketing/weixin/calculateReward", async: false, data: { abbreviationName: abbreviationName, qrCode: qrCode, openid: openid }, success: function (res) { if (res.code == 0) { $("#reward").text(res.data); //码被其他用户扫描过 } else if (res.code == 1){ $.toast(res.msg, "cancel"); flag = false; //码对应奖励已发放 } else if (res.code == 2){ $.toast(res.msg, "cancel"); flag = false; } } }) return flag; } //记录活动(扫码)事件 function scanRecord(latitude,longitude) { // alert("记录扫码事件"); $.ajax({ url: api+"marketing/weixin/scanRecord", type: "POST", data: { abbreviationName: abbreviationName, latitude: latitude, longitude:longitude, openid: openid, activityId:activityId, qrValue:qrCode } }) } //领取奖励,如果return false,就不继续向下执行 function receiveReward() { if (!userIsSubscribeApp()) { // alert("未关注"); location.href = "http://ws.js-dctech.com/qrcode.html"; return false; } if (!userIsRegister()) { // alert("未注册"); var url = spliceUrl("http://ws.js-dctech.com/register.html?openid="+openid+"&"); location.href = url; return false; } redpackProcess(); } //用户是否关注公众号 function userIsSubscribeApp() { var userIsSubscribeApp; $.ajax({ url : api+"marketing/weixin/userIsSubscribeApp", async: false, data: { abbreviationName: abbreviationName, openid: openid }, success: function (data) { userIsSubscribeApp = data; } }) return userIsSubscribeApp; } //用户是否注册(即含地理位置信息) function userIsRegister() { var userIsRegister; $.ajax({ url : api+"marketing/weixin/userIsRegister", async: false, data: { abbreviationName: abbreviationName, openid: openid }, success: function (data) { userIsRegister = data; } }) return userIsRegister; } //红包处理流程 function redpackProcess() { $.showLoading('红包发放中'); getLocation( function (latitude,longitude) { $.ajax({ url : api+"marketing/weixin/redpackProcess", async: false, data: { abbreviationName: abbreviationName, openid:openid, activityId:activityId, qrCode: qrCode, latitude: latitude, longitude: longitude }, success: function (res) { $.hideLoading(); if (res.code == 0) { $.toast(res.msg); } else { $.toast(res.msg, "cancel"); } //TODO 跳转到对应领取成功页面 }, error: function (res) { $.hideLoading(); $.toast("请求失败", "cancel"); } }) } ); }