//*******首登奖励********* */ //*********************** */ public setUserSetting(key, value) { if (value != null) { value = value.toString(); value = encodeURI(value); value = CryptoTS.encodeBase64(value); } egret.localStorage.setItem(key, value); } public getUserSetting(key, value?): any { var val = egret.localStorage.getItem(key); if (val == null || '' == val) { if (null != value) { val = value; } } else { val = CryptoTS.decodeBase64(val); val = decodeURI(val); if (val == "true") { return true; } if (val == "false") { return false; } } return val; } private oneDayFunction(saveName): boolean { let lastDay = this.getUserSetting(saveName, "") let today = new Date().getDate(); let isSameDay = lastDay == today; if (!isSameDay) { this.setUserSetting(saveName, today) return true; } return false; } /** * 每日登陆领取设置 */ private everyDayLogin() { this.isFirst = this.oneDayFunction("isFirst"); egret.log("是否是首次登陆????" + this.isFirst) if (this.isFirst) { //是首次登陆 } }
上述代码可在没有服务器的情况下实现首登奖励,你只需要在你需要的地方调用everyDayLogin这个方法即可。代码中的CryptoTS为MD5加密算法,也可不要,但是为了安全还是加上好,文件下载请点击右侧加群自行下载。