diff --git a/sdk/SDKTools.ts b/sdk/SDKTools.ts index 187b09c..f58853d 100644 --- a/sdk/SDKTools.ts +++ b/sdk/SDKTools.ts @@ -358,11 +358,6 @@ export class SDKTools { static behavior() { return WXSDK.game.behavior() } - //修改用户属性 ptm 是否累计玩游戏300秒,1是 - static attributePtm() { - return WXSDK.stat.attributePtm() - } - } diff --git a/sdk/shareTools.ts b/sdk/shareTools.ts index f611dc7..f5a76af 100644 --- a/sdk/shareTools.ts +++ b/sdk/shareTools.ts @@ -93,5 +93,4 @@ export class ShareTools { export enum ShareKey { - } diff --git a/wxsdk/WXSDK.ts b/wxsdk/WXSDK.ts index cd78228..21a507b 100644 --- a/wxsdk/WXSDK.ts +++ b/wxsdk/WXSDK.ts @@ -45,6 +45,7 @@ export default class WXSDK { ShareVideoService.I.preloadVideo(); }, 2000); } + DataService.I.updateTodayOnlineTime(); await this.game.env(); if (this.isWx) { ShareVideoService.I.init(); diff --git a/wxsdk/base/SDKConst.ts b/wxsdk/base/SDKConst.ts index 72fe49a..e1ec0db 100644 --- a/wxsdk/base/SDKConst.ts +++ b/wxsdk/base/SDKConst.ts @@ -35,7 +35,7 @@ export const GAMEDATA = { // sdk版本 -export const SDKVersion = 'v1.0.1'; +export const SDKVersion = 'v1.0.2'; // 是否打印 export const __LOG__ = false; diff --git a/wxsdk/service/DataService.ts b/wxsdk/service/DataService.ts index f1af658..e00bd9d 100644 --- a/wxsdk/service/DataService.ts +++ b/wxsdk/service/DataService.ts @@ -518,6 +518,56 @@ export default class DataService { // return LocalService.I.getDayAllVideoNum(); // } + private timeInterval + public updateTodayOnlineTime() { + let dot = StorageUtils.I.get("pcsdk_today_online_time_300") || 0; + if (dot === 1) { + this.setPtm(1) + // 定时重启 + let expiration = +((this.nextDay() - Date.now()) / 1000).toFixed(0); + setTimeout(() => { + this.updateTodayOnlineTime(); + }, expiration * 1000); + return; + } else { + this.setPtm(0) + this.timeInterval = setInterval(this.stayFun.bind(this), 5000); + } + } + private stayFun() { + let expiration = +((this.nextDay() - Date.now()) / 1000).toFixed(0); + let time = StorageUtils.I.get("pcsdk_today_online_time") || 0; + time += 5; + StorageUtils.I.set("pcsdk_today_online_time", time, expiration) + let dot = StorageUtils.I.get("pcsdk_today_online_time_300") || 0; + if (dot === 1) { + this.setPtm(1) + clearInterval(this.timeInterval); + // 定时重启 + setTimeout(() => { + this.updateTodayOnlineTime(); + }, expiration * 1000); + return; + } + // console.log("newUserTime", newUserTime, newUserDot) + if (time >= 300 && dot == 0) { + StorageUtils.I.set("pcsdk_today_online_time_300", 1, expiration); + this.setPtm(1) + clearInterval(this.timeInterval); + // 定时重启 + setTimeout(() => { + this.updateTodayOnlineTime(); + }, expiration * 1000); + } + } + + public nextDay() { + var str = new Date(); + var str2 = str.getFullYear() + "/" + + (str.getMonth() + 1) + "/" + str.getDate(); + return new Date(str2).getTime() + 24 * 60 * 60 * 1000 + } + private static instance: DataService; static get I(): DataService { return this.instance || (this.instance = new DataService()); diff --git a/wxsdk/service/LogService.ts b/wxsdk/service/LogService.ts index cfcab3a..3ef6ab9 100644 --- a/wxsdk/service/LogService.ts +++ b/wxsdk/service/LogService.ts @@ -221,7 +221,7 @@ export default class LogService { ...this.buildParams() }) this.checkLogin(fun); - // 30秒 计时 和 300秒计时 打点 + // 30秒 计时 this.startStay() } @@ -299,16 +299,11 @@ export default class LogService { newUserTime++; StorageUtils.I.set("newUserTime", newUserTime) let newUserDot = StorageUtils.I.get("newUserDot") || 0; - if (newUserDot === 2) clearInterval(this.stayInterval); + if (newUserDot === 1) clearInterval(this.stayInterval); // console.log("newUserTime", newUserTime, newUserDot) if (newUserTime >= 30 && newUserDot == 0) { StorageUtils.I.set("newUserDot", 1); this.loadingFinishStay(30); - } - if (newUserTime >= 300) { - StorageUtils.I.set("newUserDot", 2); - // this.loadingFinishStay(300);// 300秒计时 - this.attributePtm(); clearInterval(this.stayInterval); } } @@ -327,17 +322,17 @@ export default class LogService { * 修改用户属性 ptm 是否累计玩游戏300秒,1是 * @returns */ - attributePtm() { - let pkv = SDKVersion; - let uid = DataService.I.UserId; - let token = DataService.I.Token; - return SDKApi.attribute({ - pkv, - uid, - token, - ptm: 1 - }) - } + // attributePtm() { + // let pkv = SDKVersion; + // let uid = DataService.I.UserId; + // let token = DataService.I.Token; + // return SDKApi.attribute({ + // pkv, + // uid, + // token, + // ptm: 1 + // }) + // } /** diff --git a/wxsdk/service/entity/SdkData.ts b/wxsdk/service/entity/SdkData.ts index e9072df..12a6d1d 100644 --- a/wxsdk/service/entity/SdkData.ts +++ b/wxsdk/service/entity/SdkData.ts @@ -39,10 +39,10 @@ export default class SdkData { public logindays: number; // 登录天数 public amount: number; // 充值金额 public pon: number; // 用户类型:1微信投放2抖音3自然量0未知 - public ptm:number; + public ptm:number; // 当天是否300s public cule_token: string; // 用户通过广告调起微信小游戏的唯一编码 - public creative_id: string; //创意ID - public advertister_id: string; //广告账户ID + public creative_id: string; // 创意ID + public advertister_id: string; // 广告账户ID public request_id: string; // 请求下发ID diff --git a/wxsdk/utils/StorageUtils.ts b/wxsdk/utils/StorageUtils.ts index aad06df..2275cf6 100644 --- a/wxsdk/utils/StorageUtils.ts +++ b/wxsdk/utils/StorageUtils.ts @@ -26,6 +26,13 @@ export default class StorageUtils { return +(new Date().getTime() / 1000).toFixed(0); } + /** + * + * @param key + * @param value + * @param expiration 距离目标(下一天)多少秒 + * @returns + */ set(key: string, value: Object, expiration = 0) { const entity = { timestamp: this.timestamp, @@ -58,6 +65,7 @@ export default class StorageUtils { // 已过期 if (this.__isExpired(entity)) { this.remove(key); + // console.log("过期了",key); return null; } else { return entity.value; diff --git a/wxsdk/wx/WxLogin.ts b/wxsdk/wx/WxLogin.ts index 5776fcc..9c269d8 100644 --- a/wxsdk/wx/WxLogin.ts +++ b/wxsdk/wx/WxLogin.ts @@ -94,7 +94,7 @@ export default class WxLogin { if (data) { // 设置登录信息 if (data.data) { - let { channel, uid, firstlogin, token, reftoken, openid, expire, isnew, gameconfig,logindays,amount,pon,ptm } = data.data; + let { channel, uid, firstlogin, token, reftoken, openid, expire, isnew, gameconfig,logindays,amount,pon} = data.data; LogService.I.setLogind({ channel, userId: uid, @@ -106,8 +106,7 @@ export default class WxLogin { expire, logindays, amount, - pon, - ptm + pon }); OnlineService.I.setData(gameconfig) LogService.I.active(); -- libgit2 0.21.0