zoukankan      html  css  js  c++  java
  • egret之每日登陆奖励

        //*******首登奖励********* */
        //*********************** */
        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加密算法,也可不要,但是为了安全还是加上好,文件下载请点击右侧加群自行下载。

  • 相关阅读:
    nowcoderD Xieldy And His Password
    Codeforces681D Gifts by the List
    nowcoder80D applese的生日
    Codeforces961E Tufurama
    Codeforces957 Mahmoud and Ehab and yet another xor task
    nowcoder82E 无向图中的最短距离
    nowcoder82B 区间的连续段
    Codeforces903E Swapping Characters
    Codeforces614C Peter and Snow Blower
    Codeforces614D Skills
  • 原文地址:https://www.cnblogs.com/shirln/p/9680232.html
Copyright © 2011-2022 走看看