You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1130 lines
38 KiB
1130 lines
38 KiB
import { screen } from "cc";
|
|
import { PlatformCommonDefine } from "../Common/PlatformCommonDefine";
|
|
import PlatformData from "../Data/PlatformData";
|
|
import PlatformManagerProxy from "../PlatformManagerProxy";
|
|
import DefaultRecordManager from "../Record/DefaultRecordManager";
|
|
import ShareManagerAKhgfawgsda from "../ShareManager";
|
|
import { EPlatformType } from "../T/EPlatformType";
|
|
import IPlatform from "../T/IPlatform";
|
|
import IRecordManager from "../T/IRecordManager";
|
|
import { ShareInfo } from "../T/ShareInfo";
|
|
import { TDAnalyticsMgr } from "../../Mgr_Ge/TDAnalyticsMgr";
|
|
import { Recommend } from "../Recommend/Recommend";
|
|
import { WXRecommend } from "../Recommend/WXRecommend";
|
|
import CsvMgr from "../../Mgr_CSV/CsvMgr";
|
|
import { PlatformEnum_WX } from "../Data/PlatformEnum";
|
|
import { MainConfig } from "db://assets/Launch/_MainConfig";
|
|
import PlatformManager from "../PlatformManager";
|
|
import { TXSDKMgr } from "../../Mgr_Ge/TXSDKMgr";
|
|
import LocalStorage from "../../Mgr_LocalData/LocalStorage";
|
|
import { GEData, GEType } from "../../Mgr_Ge/GeDifine";
|
|
import { Console } from "console";
|
|
import { GEAnalyticsMgr } from "../../Mgr_Ge/GEAnalyticsMgr";
|
|
|
|
/**
|
|
* 微信平台实例
|
|
*/
|
|
export default class WXPlatform implements IPlatform {
|
|
isSliderBar: boolean;
|
|
isAddShortcut: boolean;
|
|
IsLeaderboardsEnable: boolean=false;
|
|
base: any;
|
|
platformData: PlatformData;
|
|
onPause: Function;
|
|
appId: string;
|
|
platform: EPlatformType = EPlatformType.WX;
|
|
safeArea: PlatformCommonDefine.SafeArea = null;
|
|
lauchOption: PlatformCommonDefine.LaunchOption;
|
|
loginState: PlatformCommonDefine.LoginState;
|
|
onLoginEnd: Function;
|
|
onResume: Function;
|
|
recordManager: IRecordManager = new DefaultRecordManager();
|
|
systemInfo: any;
|
|
loginCode: string = null;
|
|
/**
|
|
* 是否支持直接跳转到其他小程序
|
|
*/
|
|
isSupportJumpOther: boolean = true;
|
|
|
|
protected _data: PlatformData;
|
|
|
|
protected _bannerAd;
|
|
protected _rewardVideo;
|
|
protected _intersitialAd;
|
|
|
|
protected _isBannerLoaded: boolean = false;
|
|
protected _isVideoLoaded: boolean = false;
|
|
protected _isInterstitialLoaded: boolean = false;
|
|
protected _videoFailedCount: number;
|
|
protected _interstitalFailedCount: number;
|
|
|
|
protected _rewardSuccessed: Function;
|
|
protected _rewardSkipped: Function;
|
|
protected loadFail: Function;
|
|
|
|
protected _cacheScreenScale: number;
|
|
|
|
protected _shareVideoBtn;
|
|
protected _userInfoBtn;
|
|
|
|
protected _base: any;
|
|
|
|
|
|
protected _cacheVideoAD: boolean = true;
|
|
|
|
protected openIDUrl:string = "https://game-api.lvzhouyouxi.com/getOpenId_line_wx";
|
|
protected clickId;
|
|
/**推荐功能 */
|
|
mRecommend:Recommend;
|
|
|
|
Init(platformData: PlatformData,callBack:Function) {
|
|
this._base = window["wx"];
|
|
if (this._base == null) {
|
|
console.warn("平台初始化错误", PlatformManagerProxy.platformStr);
|
|
return;
|
|
}
|
|
this.platformData = platformData;
|
|
this.isAddShortcut = true;
|
|
this.recordManager.Platform = this;
|
|
this.mRecommend = new WXRecommend();
|
|
switch (this.platformData.appId) {
|
|
default:
|
|
break;
|
|
}
|
|
this.mRecommend.init(platformData);
|
|
this._InitLauchOption();
|
|
this._Login(callBack);
|
|
this._InitShareInfo();
|
|
this._InitSystemInfo();
|
|
this._CreateBannerAd();
|
|
this._CreateVideoAd();
|
|
window["iplatform"] = this;
|
|
}
|
|
|
|
_InitABTest() {
|
|
this._data = PlatformManager.instance.platData;
|
|
ConsoleEx.Log("_InitABTest PlatformManager.instance.platData:",PlatformManager.instance.platData);
|
|
let abtest = PlatformManager.instance.platData.ABTest;
|
|
for(const type in abtest){
|
|
const key = abtest[type].key;
|
|
const res = this._base.getExptInfoSync([key]);
|
|
if(key === 'expt_1772086195'){
|
|
// if (res.expt_1772086195 === undefined || res.expt_1772086195 !== '1') {
|
|
// abtest[type].v = 10;
|
|
// } else if (res.expt_1772086195 == '1') {
|
|
// /* 实验组1业务逻辑 */
|
|
// abtest[type].v = 10;
|
|
// }
|
|
abtest[type].v = 10;
|
|
TDAnalyticsMgr.ins.userABSet(res.expt_1772086195);
|
|
ConsoleEx.Com(`ABTest:${type},key:${key},state:${abtest[type].v}`);
|
|
}else if(key === 'expt_1773922135'){
|
|
if (res.expt_1773922135 === undefined || res.expt_1773922135 == '0') {
|
|
abtest[type].v = 0;
|
|
} else {
|
|
abtest[type].v = Number(res.expt_1773922135);
|
|
}
|
|
if(abtest[type].v > 3){
|
|
abtest[type].v = 0;
|
|
}
|
|
TDAnalyticsMgr.ins.userABSet(res.expt_1773922135);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**AB测试生成 */
|
|
|
|
|
|
_CheckUpdate() {
|
|
let updateManager = this._base.getUpdateManager();
|
|
if (updateManager == null) return;
|
|
|
|
updateManager.onCheckForUpdate(function (res) {
|
|
// 请求完新版本信息的回调
|
|
console.log("onCheckForUpdate", res.hasUpdate);
|
|
if (res.hasUpdate) {
|
|
this._base.showToast({
|
|
title: "即将有更新请留意"
|
|
});
|
|
}
|
|
});
|
|
|
|
updateManager.onUpdateReady(() => {
|
|
this._base.showModal({
|
|
title: "更新提示",
|
|
content: "新版本已经准备好,是否立即使用?",
|
|
success: function (res) {
|
|
if (res.confirm) {
|
|
// 调用 applyUpdate 应用新版本并重启
|
|
updateManager.applyUpdate();
|
|
} else {
|
|
this._base.showToast({
|
|
icon: "none",
|
|
title: "小程序下一次「冷启动」时会使用新版本"
|
|
});
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
updateManager.onUpdateFailed(() => {
|
|
this._base.showToast({
|
|
title: "更新失败,下次启动继续..."
|
|
});
|
|
});
|
|
}
|
|
_InitShareList(){
|
|
if(this.platformData.shareId && this.platformData.shareId.length > 0){
|
|
this.platformData.shareId.forEach((value)=>{
|
|
ShareManagerAKhgfawgsda.instance.AddShareInfo({
|
|
shareID:value.shareID,
|
|
shareImg:value.shareImg,
|
|
shareTitle:value.shareTitle,
|
|
});
|
|
})
|
|
}
|
|
}
|
|
protected _Login(callBack:Function) {
|
|
this.loginState = {
|
|
isLogin: false,
|
|
code: "",
|
|
openid:"",
|
|
};
|
|
let loginData = {} as PlatformCommonDefine.LoginData;
|
|
loginData.success = (res) => {
|
|
this.loginCode = res.code;
|
|
this._OnLoginSuccess(res, callBack);
|
|
console.warn(this.loginState);
|
|
// callBack && callBack();
|
|
};
|
|
loginData.fail = (res) => {
|
|
console.warn(PlatformManagerProxy.platformStr, "登录失败", res);
|
|
this.loginState.isLogin = false;
|
|
this.loginState.code = "";
|
|
};
|
|
loginData.complete = () => {
|
|
if (this.onLoginEnd != null) {
|
|
this.onLoginEnd();
|
|
}
|
|
};
|
|
this._base.login(loginData);
|
|
}
|
|
public GetStorage(key: string): any {
|
|
if (this.base && this.base.getStorageSync && key) {
|
|
try {
|
|
return this.base.getStorageSync(key);
|
|
} catch (error) {
|
|
console.log('getStorageSync error: ', JSON.stringify(error));
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
public SetStorage(key: string, data: any) {
|
|
if (this.base && this.base.getStorageSync && key) {
|
|
try {
|
|
return this.base.setStorageSync(key, data);
|
|
} catch (error) {
|
|
console.log('setStorageSync error: ', JSON.stringify(error));
|
|
}
|
|
}
|
|
}
|
|
|
|
protected _OnLoginSuccess(res: PlatformCommonDefine.LoginSuccessRes, callBack:Function) {
|
|
console.log(PlatformManagerProxy.platformStr, "登录成功", res);
|
|
this.loginState.isLogin = true;
|
|
this.loginState.code = res.code;
|
|
this._getWxID();
|
|
this.getOpenId(res.code, () => {
|
|
callBack && callBack();
|
|
}, 0);
|
|
this.checkFeedSubscribe((isOK:boolean)=>{
|
|
MainConfig.isFeedSubscribe = isOK;
|
|
ConsoleEx.Log("直玩订阅:",isOK);
|
|
});
|
|
}
|
|
|
|
protected _getWxID(){
|
|
let info = this._base.getLaunchOptionsSync()
|
|
console.log('微信登录信息', info)
|
|
let query = info.query;
|
|
if (query) {
|
|
let gdt_vid = query.gdt_vid;
|
|
let weixinadinfo = query.weixinadinfo;
|
|
let aid = 0
|
|
if (weixinadinfo) {
|
|
let weixinadinfoArr = weixinadinfo.split('.')
|
|
aid = weixinadinfoArr[0]
|
|
}
|
|
if (aid) {
|
|
this.loginState.weChatAdId = aid;
|
|
}
|
|
}
|
|
|
|
if (!this.loginState.weChatAdId && window["weChatAdId"]) {
|
|
this.loginState.weChatAdId = window["weChatAdId"];
|
|
}
|
|
ConsoleEx.Log("获取的wxID",this.loginState.weChatAdId)
|
|
}
|
|
|
|
/**获取OpenID */
|
|
getOpenId(code:any,callBack:Function,idx:number){
|
|
let data = {
|
|
code: code,
|
|
appid: this.platformData.appId,
|
|
appKey: this.platformData.appKey,
|
|
}
|
|
|
|
|
|
ConsoleEx.Warn("准备拉取OpenID",data)
|
|
|
|
MainConfig.openid = this.loginState.openid = localStorage.getItem("GamePlayerID") || "";
|
|
if (!this.loginState.openid || this.loginState.openid.length == 0) {
|
|
this._base.request({
|
|
url: this.openIDUrl, // 本地服务地址
|
|
method: 'POST',
|
|
data: data,
|
|
header: { 'Content-Type': 'application/json' },
|
|
success: (resp) => {
|
|
console.log('---------------', resp)
|
|
ConsoleEx.Warn("获取的数据", resp.data)
|
|
if (resp.data.openid) {
|
|
MainConfig.openid = this.loginState.openid = resp.data.openid;
|
|
localStorage.setItem("GamePlayerID", resp.data.openid);
|
|
} else {
|
|
setTimeout(() => {
|
|
this._Login(() => { })
|
|
}, 30 * 1000);
|
|
}
|
|
callBack && callBack();
|
|
},
|
|
fail: (errString) => {
|
|
ConsoleEx.Error(errString);
|
|
setTimeout(() => {
|
|
this._Login(() => { })
|
|
}, 30 * 1000);
|
|
},
|
|
complete: (message) => {
|
|
//console.log('请求完成:', message);
|
|
// if (!this.loginState.openid || this.loginState.openid.length == 0) {
|
|
// setTimeout(() => {
|
|
// this.getOpenId(code, callBack, idx++)
|
|
// }, 2 * 1000);
|
|
// }
|
|
}
|
|
|
|
|
|
|
|
});
|
|
}else{
|
|
callBack && callBack();
|
|
}
|
|
|
|
}
|
|
|
|
protected _InitLauchOption() {
|
|
// 绑定onShow事件
|
|
this._base.onShow(this._OnShow);
|
|
this._base.onHide(this._OnHide);
|
|
// 自动获取一次启动参数
|
|
let res = this._base.getLaunchOptionsSync() as PlatformCommonDefine.LaunchOption;
|
|
this._OnShow(res);
|
|
}
|
|
|
|
protected _InitShareInfo() {
|
|
this._base.showShareMenu({
|
|
withShareTicket: true,
|
|
success: (res) => {
|
|
console.log("InitShareSuccess", res);
|
|
},
|
|
fail: (res) => {
|
|
console.log("InitShareFailed", res);
|
|
},
|
|
complete: (res) => {
|
|
console.log("InitShareComplete", res);
|
|
}
|
|
});
|
|
this._base.onShareAppMessage && this._base.onShareAppMessage(
|
|
() => {
|
|
TXSDKMgr.ins.onShareAppMessage();
|
|
let shareInfo = ShareManagerAKhgfawgsda.instance.GetShareInfo();
|
|
return this._WrapShareInfo(shareInfo);
|
|
}
|
|
);
|
|
|
|
this._base.onShareTimeline && this._base.onShareTimeline(
|
|
() => {
|
|
TXSDKMgr.ins.onShareTimeline();
|
|
let shareInfo = ShareManagerAKhgfawgsda.instance.GetShareInfo();
|
|
return this._WrapShareInfo(shareInfo);
|
|
}
|
|
);
|
|
}
|
|
|
|
protected _WrapShareInfo(shareInfo: ShareInfo) {
|
|
let shareObj = {};
|
|
|
|
|
|
if (shareInfo.shareTitle) {
|
|
shareObj["title"] = shareInfo.shareTitle;
|
|
}
|
|
|
|
if (shareInfo.shareID) {
|
|
shareObj["imageUrlId"] = shareInfo.shareID;
|
|
}
|
|
|
|
if (shareInfo.shareImg) {
|
|
shareObj["imageUrl"] = shareInfo.shareImg;
|
|
}
|
|
|
|
if (shareInfo.sharePath) {
|
|
shareObj["query"] = {};
|
|
let pathSplit = shareInfo.sharePath.split("?");
|
|
let params = pathSplit[1].split("&");
|
|
for (let getParam of params) {
|
|
let splitParam = getParam.split("=");
|
|
shareObj["query"][splitParam[0]] = splitParam[1];
|
|
}
|
|
}
|
|
|
|
return shareObj;
|
|
}
|
|
|
|
protected _InitSystemInfo() {
|
|
this.base = this._base;
|
|
try {
|
|
this.systemInfo = this._base.getSystemInfoSync();
|
|
console.log("系统信息已获取", this.systemInfo);
|
|
|
|
this.safeArea = this.systemInfo.safeArea as PlatformCommonDefine.SafeArea;
|
|
|
|
this._cacheScreenScale = this.systemInfo.screenWidth / screen.windowSize.width;
|
|
} catch (e) {
|
|
console.warn(e);
|
|
console.warn("获取设备信息失败,执行默认初始化");
|
|
this.safeArea = null;
|
|
}
|
|
}
|
|
|
|
protected _CreateInterstitalAd() {
|
|
if (!this.platformData.interstitialId) {
|
|
console.log("无有效的插页广告ID,取消加载");
|
|
return;
|
|
}
|
|
this._interstitalFailedCount = 0;
|
|
let intAdObj = {};
|
|
intAdObj["adUnitId"] = this.platformData.interstitialId;
|
|
this._intersitialAd = this._base.createInterstitialAd(intAdObj);
|
|
if (!this._intersitialAd)
|
|
return;
|
|
this._intersitialAd.onLoad(() => {
|
|
console.log("插页广告加载成功");
|
|
this._isInterstitialLoaded = true;
|
|
});
|
|
this._intersitialAd.onError((err) => {
|
|
this._interstitalFailedCount++;
|
|
console.warn("插页广告加载失败", err);
|
|
if (this._interstitalFailedCount > 10) {
|
|
console.log("第", this._interstitalFailedCount, "次重新加载插页广告");
|
|
// 失败自动加载广告
|
|
this._intersitialAd.load();
|
|
}
|
|
});
|
|
}
|
|
|
|
protected _CreateVideoAd() {
|
|
console.log('vedio ad id', this.platformData.rewardVideoId)
|
|
if (!this._cacheVideoAD) {
|
|
console.log("当前策略为不缓存视频广告");
|
|
return;
|
|
}
|
|
let createRewardedVideoAd = this._base["createRewardedVideoAd"];
|
|
if (createRewardedVideoAd == null) {
|
|
console.warn("无createRewardedVideoAd方法,跳过初始化");
|
|
return;
|
|
}
|
|
if (!this.platformData.rewardVideoId) {
|
|
console.log("无有效的视频广告ID,取消加载");
|
|
return;
|
|
}
|
|
this._videoFailedCount = 0;
|
|
let videoObj = {};
|
|
videoObj["adUnitId"] = this.platformData.rewardVideoId;
|
|
this._rewardVideo = createRewardedVideoAd(videoObj);
|
|
this._rewardVideo.onLoad(() => {
|
|
console.log("视频广告加载成功");
|
|
this._isVideoLoaded = true;
|
|
});
|
|
this._rewardVideo.onError((res) => {
|
|
this._videoFailedCount++;
|
|
console.warn("视频广告加载失败", res);
|
|
if (this._videoFailedCount > 10) {
|
|
console.log("第", this._videoFailedCount, "次重新加载视频广告");
|
|
// 失败自动加载广告
|
|
this._rewardVideo.load();
|
|
}
|
|
});
|
|
this._rewardVideo.onClose((res) => {
|
|
console.log("视频回调", res);
|
|
let isEnd = res["isEnded"] as boolean;
|
|
if (isEnd) {
|
|
if (this._rewardSuccessed) this._rewardSuccessed();
|
|
} else {
|
|
if (this._rewardSkipped) this._rewardSkipped();
|
|
}
|
|
});
|
|
}
|
|
|
|
protected _CreateBannerAd() {
|
|
if (!this.platformData.bannerId) {
|
|
console.log("无有效的banner广告ID,取消加载");
|
|
return;
|
|
}
|
|
let windowWidth = this._base.getSystemInfoSync().windowWidth;
|
|
let windowHeight = this._base.getSystemInfoSync().windowHeight;
|
|
let bannerObj = {};
|
|
bannerObj["adUnitId"] = this.platformData.bannerId; // "";
|
|
// bannerObj["adUnitId"] = '4gr6k32h08j7j9a72g'; // "";
|
|
console.log(' 自己改的 id@@', this.platformData.bannerId);
|
|
|
|
bannerObj["adIntervals"] = 30;
|
|
let styleObj = {};
|
|
styleObj["left"] = 0;
|
|
styleObj["top"] = 0;
|
|
styleObj["width"] = 300;
|
|
bannerObj["style"] = styleObj;
|
|
|
|
this._bannerAd = this._base.createBannerAd(bannerObj);
|
|
this._isBannerLoaded = false;
|
|
|
|
this._bannerAd.onLoad(() => {
|
|
console.log("banner加载成功");
|
|
this._isBannerLoaded = true;
|
|
this._bannerAd.style.top = windowHeight - this._bannerAd.style.realHeight;
|
|
this._bannerAd.style.left = (windowWidth - this._bannerAd.style.realWidth) / 2;
|
|
});
|
|
|
|
this._bannerAd.onError((res) => {
|
|
console.warn("banner广告加载失败", res);
|
|
});
|
|
}
|
|
|
|
IsBannerAvaliable() {
|
|
return this._isBannerLoaded;
|
|
}
|
|
IsVideoAvaliable() {
|
|
return this._isVideoLoaded;
|
|
}
|
|
IsInterstitalAvaliable() {
|
|
return this._isInterstitialLoaded;
|
|
}
|
|
ShowBannerAd() {
|
|
if (!this.IsBannerAvaliable()) {
|
|
return;
|
|
}
|
|
this._bannerAd.show();
|
|
}
|
|
HideBannerAd() {
|
|
this._bannerAd.hide();
|
|
}
|
|
|
|
protected _DoCacheShowVideo(onSuccess: Function, onSkipped: Function) {
|
|
if (!this._isVideoLoaded) {
|
|
console.warn("视频广告尚未加载好");
|
|
return;
|
|
}
|
|
this._rewardSuccessed = onSuccess;
|
|
this._rewardSkipped = onSkipped;
|
|
//this._isVideoLoaded = false;
|
|
this._rewardVideo.show().then(()=>{
|
|
TXSDKMgr.ins.AD_IMPRESSION(1);
|
|
});
|
|
}
|
|
|
|
protected _DoNoCacheShowVideo(onSuccess: Function, onSkipped: Function, loadFail: Function) {
|
|
this._rewardSuccessed = onSuccess;
|
|
this._rewardSkipped = onSkipped;
|
|
this.loadFail = loadFail;
|
|
if (!this.platformData.rewardVideoId) {
|
|
console.log("无有效的视频广告ID,取消加载");
|
|
onSkipped();
|
|
return;
|
|
}
|
|
let createRewardedVideoAd = this._base["createRewardedVideoAd"];
|
|
if (createRewardedVideoAd == null) {
|
|
console.warn("无createRewardedVideoAd方法,跳过初始化");
|
|
onSkipped();
|
|
return;
|
|
}
|
|
this._videoFailedCount = 0;
|
|
let videoObj = {};
|
|
videoObj["adUnitId"] = this.platformData.rewardVideoId; // "adunit-5631637236cf16b6";
|
|
if (this._rewardVideo) {
|
|
this._rewardVideo.offClose(this.onVideoClose);
|
|
}
|
|
this._rewardVideo = createRewardedVideoAd(videoObj);
|
|
this._rewardVideo.onLoad(() => {
|
|
console.log("视频广告加载成功");
|
|
this._isVideoLoaded = true;
|
|
});
|
|
this._rewardVideo.onError((res) => {
|
|
this._videoFailedCount++;
|
|
console.warn("视频广告加载失败", res, this._videoFailedCount);
|
|
this.loadFail();
|
|
|
|
});
|
|
this._rewardVideo.onClose((res) => {
|
|
|
|
console.log("视频回调", res);
|
|
let isEnd = res["isEnded"] as boolean;
|
|
new Promise((r) => {
|
|
setTimeout(r,20);
|
|
//Laya.timer.frameOnce(1, this, r);
|
|
}).then(() => {
|
|
if (isEnd) {
|
|
if (this._rewardSuccessed) this._rewardSuccessed();
|
|
} else {
|
|
if (this._rewardSkipped) this._rewardSkipped();
|
|
}
|
|
});
|
|
});
|
|
|
|
this._rewardVideo.load().then(() => {
|
|
console.log("激励视频 加载成功");
|
|
// 加载成功后 再显示广告
|
|
return this._rewardVideo.show().then(() => {
|
|
TXSDKMgr.ins.AD_IMPRESSION(1);
|
|
//
|
|
}).catch((err) => {
|
|
console.warn(err);
|
|
});;
|
|
});
|
|
}
|
|
|
|
private onVideoClose(res): any {
|
|
console.log("视频回调", res);
|
|
let isEnd = res["isEnded"] as boolean;
|
|
new Promise((r) => {
|
|
setTimeout(r,20);
|
|
//Laya.timer.frameOnce(1, this, r);
|
|
}).then(() => {
|
|
if (isEnd) {
|
|
if (this._rewardSuccessed)
|
|
this._rewardSuccessed();
|
|
}
|
|
else {
|
|
if (this._rewardSkipped)
|
|
this._rewardSkipped();
|
|
}
|
|
});
|
|
}
|
|
|
|
ShowRewardVideoAd(onSuccess: Function, onSkipped: Function, loadFail: Function) {
|
|
if (this._cacheVideoAD) {
|
|
this._DoCacheShowVideo(onSuccess, onSkipped);
|
|
} else {
|
|
this._DoNoCacheShowVideo(onSuccess, onSkipped, loadFail);
|
|
}
|
|
|
|
}
|
|
ShowRewardVideoAdAsync(): Promise<boolean> {
|
|
return new Promise(function (resolve) {
|
|
PlatformManagerProxy.instance.PlatformInstance.ShowRewardVideoAd((this, () => {
|
|
resolve(true);
|
|
}), (this, () => {
|
|
resolve(false);
|
|
}), (this, () => {
|
|
resolve(false);
|
|
}));
|
|
});
|
|
}
|
|
|
|
ShowInterstitalAd(callBack:Function) {
|
|
if (!this._isInterstitialLoaded) {
|
|
console.warn("插页广告尚未加载好");
|
|
return;
|
|
}
|
|
this._intersitialAd.show().then(()=>{
|
|
// 插屏广告展示成功
|
|
callBack && callBack();
|
|
});
|
|
}
|
|
|
|
GetFromAppId(): string {
|
|
if (this.lauchOption.referrerInfo == null) {
|
|
return null;
|
|
}
|
|
if (!this.lauchOption.referrerInfo.appId) {
|
|
return null;
|
|
}
|
|
return this.lauchOption.referrerInfo.appId;
|
|
}
|
|
|
|
GetFeedType(): number {
|
|
return -1;
|
|
}
|
|
|
|
/**
|
|
* 小游戏回到前台的事件
|
|
*/
|
|
protected _OnShow(res: PlatformCommonDefine.LaunchOption) {
|
|
console.log(PlatformManagerProxy.platformStr, "OnShow", res);
|
|
PlatformManagerProxy.instance.PlatformInstance.lauchOption = res;
|
|
PlatformManagerProxy.instance.PlatformInstance._CheckUpdate();
|
|
this.NavigateToAppSuccess = null;
|
|
new Promise((r) => {
|
|
setTimeout(r,20);
|
|
// Laya.timer.frameOnce(1, this, r);
|
|
}).then(() => {
|
|
if (PlatformManagerProxy.instance.PlatformInstance.onResume) {
|
|
PlatformManagerProxy.instance.PlatformInstance.onResume(res);
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 小游戏退出前台的事件
|
|
*/
|
|
protected _OnHide(res: PlatformCommonDefine.LaunchOption) {
|
|
console.log(PlatformManagerProxy.platformStr, "OnHide", res);
|
|
if (PlatformManagerProxy.instance.PlatformInstance.onPause) {
|
|
PlatformManagerProxy.instance.PlatformInstance.onPause(res);
|
|
}
|
|
if (this.NavigateToAppSuccess) {
|
|
this.NavigateToAppSuccess();
|
|
}
|
|
LocalStorage.CheckSaveServerData();
|
|
}
|
|
|
|
ShareAppMessage(shareInfo: ShareInfo, onSuccess: Function, onFailed: Function) {
|
|
console.log("分享消息", shareInfo);
|
|
let shareObj = this._WrapShareInfo(shareInfo);
|
|
this._base.shareAppMessage(shareObj);
|
|
if (onSuccess) {
|
|
onSuccess();
|
|
}
|
|
}
|
|
|
|
RecordEvent(eventId: string, param: object) {
|
|
console.log("记录事件", eventId, param);
|
|
let aldSendEvent = this._base["aldSendEvent"];
|
|
if (aldSendEvent == null) {
|
|
console.warn("阿拉丁sdk尚未接入,请检查配置");
|
|
return;
|
|
}
|
|
if (param != null) {
|
|
aldSendEvent(eventId, param);
|
|
} else {
|
|
aldSendEvent(eventId);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 创建分享视频按钮
|
|
* @param x
|
|
* @param y
|
|
* @param width
|
|
* @param height
|
|
*/
|
|
public CreateShareVideoBtn(x: number, y: number, width: number, height: number) {
|
|
let btnObj = {} as any;
|
|
btnObj.style = {
|
|
left: x * this._cacheScreenScale,
|
|
top: y * this._cacheScreenScale,
|
|
height: height * this._cacheScreenScale,
|
|
width: width * this._cacheScreenScale
|
|
};
|
|
btnObj.share = {
|
|
query: {
|
|
tick: 1
|
|
},
|
|
bgm: "",
|
|
timeRange: [0, 60 * 1000]
|
|
};
|
|
if (this._shareVideoBtn == null) {
|
|
this._shareVideoBtn = this._base.createGameRecorderShareButton(btnObj);
|
|
} else {
|
|
this._shareVideoBtn.show();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 隐藏分享视频按钮
|
|
*/
|
|
public HideShareVideoBtn() {
|
|
if (this._shareVideoBtn != null) {
|
|
this._shareVideoBtn.hide();
|
|
}
|
|
}
|
|
|
|
ShowToast(str: string) {
|
|
this._base.showToast(
|
|
{
|
|
title: str,
|
|
duration: 2000
|
|
}
|
|
);
|
|
}
|
|
|
|
OpenGameBox(appIds: string[]) {
|
|
console.warn("当前平台", PlatformManagerProxy.platformStr, "暂不支持互推游戏盒子");
|
|
}
|
|
NavigateToAppSuccess: () => void = null;
|
|
NavigateToApp(appid: string, path?: string, extra?: any, showGC?: boolean, isbanner?: boolean, adid?: number): Promise<boolean> {
|
|
return new Promise((resolve, reject) => {
|
|
if (showGC) {
|
|
// GlobalUnit.gameManager.GameOver();
|
|
}
|
|
// this.NavigateToAppSuccess = null;
|
|
window["wx"].navigateToMiniProgram({
|
|
appId: appid,
|
|
path: path,
|
|
extraData: extra,
|
|
envVersion: '',
|
|
success: (res) => {
|
|
console.log('小游戏跳转成功', res);
|
|
resolve(true);
|
|
},
|
|
fail: () => {
|
|
console.log('小游戏跳转失败:');
|
|
reject(false);
|
|
if (showGC) {
|
|
//
|
|
}
|
|
},
|
|
complete: () => { }
|
|
});
|
|
})
|
|
}
|
|
createShortcut(BackFun:(isOK:boolean)=>void) {
|
|
BackFun && BackFun(true)
|
|
console.log('暂未实现');
|
|
}
|
|
checkShortcut(BackFun:(isOK:boolean)=>void) {
|
|
BackFun && BackFun(true)
|
|
console.log('暂未实现');
|
|
}
|
|
|
|
|
|
requestFeedSubscribe(BackFun:(isOK:boolean)=>void){
|
|
BackFun && BackFun(true)
|
|
console.log('直玩推订阅');
|
|
}
|
|
checkFeedSubscribe(BackFun:(isOK:boolean)=>void){
|
|
BackFun && BackFun(true)
|
|
console.log('检查是否订阅直玩推');
|
|
}
|
|
|
|
/**QQ 微信 无法在主域获取到数据 */
|
|
GetUserCloudStorage() {
|
|
|
|
}
|
|
/**设置用户数据 */
|
|
SetUserCloudStorage() {
|
|
|
|
}
|
|
|
|
CloseGame() {
|
|
|
|
}
|
|
get isCanShowRecommend(){
|
|
return this.mRecommend.InitComplete;
|
|
};
|
|
showRecommend(callBack: Function) {
|
|
this.mRecommend.show(callBack);
|
|
}
|
|
|
|
/**获取用户信息 */
|
|
GetUserInfo(value: {
|
|
success?: Function,
|
|
fail?: Function,
|
|
btnStyle?:{ left: number, top: number, width: number, height: number },
|
|
}){
|
|
this._base.getSetting({
|
|
success: (settingResponse) => {
|
|
if (settingResponse.authSetting["scope.userInfo"] != null) {
|
|
this._base.getUserInfo({
|
|
success: (userInfoResponse) => {
|
|
const userInfo = userInfoResponse.userInfo;
|
|
MainConfig.UserInfo.nick_name = userInfo.nickName;
|
|
MainConfig.UserInfo.avatar_url = userInfo.avatarUrl;
|
|
value.success && value.success();
|
|
},
|
|
fail:(err)=>{
|
|
ConsoleEx.Error("获取用户信息失败:",err);
|
|
this.createUserInfoButton(value);
|
|
value.fail && value.fail();
|
|
}
|
|
});
|
|
} else {
|
|
this.createUserInfoButton(value);
|
|
value.fail && value.fail();
|
|
}
|
|
},
|
|
fail:()=>{
|
|
value.fail && value.fail();
|
|
}
|
|
});
|
|
}
|
|
|
|
private createUserInfoButton(value: {
|
|
success?: Function,
|
|
fail?: Function,
|
|
btnStyle?:{ left: number, top: number, width: number, height: number },
|
|
}) {
|
|
if (this._userInfoBtn) {
|
|
this.showUserInfoButton();
|
|
} else {
|
|
const buttonStyle = {
|
|
left: value.btnStyle.left,
|
|
top: value.btnStyle.top,
|
|
width: value.btnStyle.width,
|
|
height: value.btnStyle.height,
|
|
backgroundColor: '#ff000000',
|
|
};
|
|
const userInfoButtonConfig = {
|
|
type: "text",
|
|
image: " ",
|
|
text: "",
|
|
style: buttonStyle,
|
|
withCredentials: false
|
|
};
|
|
this._userInfoBtn = this._base.createUserInfoButton(userInfoButtonConfig);
|
|
this.showUserInfoButton();
|
|
let self = this;
|
|
// console.log("create btn")
|
|
this._userInfoBtn && this._userInfoBtn.onTap(event => {
|
|
if (event.errMsg.includes(":ok")) {
|
|
this.removeWXLoginButton();
|
|
const userInfo = JSON.parse(event.rawData);
|
|
MainConfig.UserInfo.nick_name = userInfo.nickName;
|
|
MainConfig.UserInfo.avatar_url = userInfo.avatarUrl;
|
|
value.success && value.success();
|
|
console.log("用户头像信息", userInfo);
|
|
} else {
|
|
self.toastMsg("授权失败", 2000);
|
|
value.fail && value.fail();
|
|
console.log("授权失败==", event);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
showUserInfoButton() {
|
|
this._userInfoBtn && this._userInfoBtn.show();
|
|
}
|
|
hideUserInfoButton() {
|
|
this._userInfoBtn && this._userInfoBtn.hide();
|
|
}
|
|
removeWXLoginButton() {
|
|
this._userInfoBtn && (this._userInfoBtn.destroy(), this._userInfoBtn = null);
|
|
}
|
|
|
|
toastMsg(title, duration = 1500) {
|
|
var data: any = {};
|
|
data.title = title,
|
|
data.icon = "none",
|
|
data.duration = duration,
|
|
this._base.showToast(data);
|
|
}
|
|
|
|
// -------------------- 巨量回传 --------------------
|
|
getQueryInfo(launchOptions, key: string, ad_paramsUrl: URL) {
|
|
let value = null;
|
|
const query = launchOptions?.query;
|
|
if (query) {
|
|
value = query[key];
|
|
console.log(`${key}:`, value);
|
|
}
|
|
|
|
let value2 = null;
|
|
if (ad_paramsUrl) {
|
|
value2 = ad_paramsUrl.searchParams.get(key);
|
|
console.log("value2",key,value2)
|
|
}
|
|
|
|
if (!!value && value != "0") {
|
|
return value;
|
|
} else if (ad_paramsUrl) {
|
|
value = ad_paramsUrl.searchParams.get(key);
|
|
if (!!value) {
|
|
return value;
|
|
} else {
|
|
return null;
|
|
}
|
|
} else {
|
|
return value;
|
|
}
|
|
}
|
|
|
|
oceanengineEvent() {
|
|
let isNewUser: boolean = false
|
|
// @ts-ignore
|
|
const launchOptions = this.base.getLaunchOptionsSync();
|
|
console.log("启动参数:", launchOptions);
|
|
if (launchOptions?.query?.clickid) {
|
|
this.clickId = launchOptions.query.clickid;
|
|
console.log("广告 clickid:", this.clickId);
|
|
}
|
|
|
|
let ad_paramsUrl: URL = null;
|
|
if (launchOptions.query && launchOptions.query.ad_params) {
|
|
let str = launchOptions.query.ad_params;
|
|
try {
|
|
let ad_params = JSON.parse(decodeURIComponent(str));
|
|
if (ad_params.web_url) {
|
|
ad_paramsUrl = new URL(ad_params.web_url);
|
|
console.log("ad_paramsUrl", ad_paramsUrl.searchParams)
|
|
}
|
|
} catch (e) {
|
|
console.warn("ad_params parse error:", e);
|
|
}
|
|
}
|
|
|
|
let projectId = this.getQueryInfo(launchOptions, "projectId", ad_paramsUrl);
|
|
if (projectId && projectId != "0") {
|
|
TDAnalyticsMgr.ins.projectId(`${projectId}`)
|
|
}
|
|
|
|
let promotionid = this.getQueryInfo(launchOptions, "promotionid", ad_paramsUrl);
|
|
if (promotionid && promotionid != "0") {
|
|
TDAnalyticsMgr.ins.promotionid(`${promotionid}`)
|
|
}
|
|
|
|
let adid = this.getQueryInfo(launchOptions, "adid", ad_paramsUrl);
|
|
if (adid && adid != "0") {
|
|
TDAnalyticsMgr.ins.aid(`${adid}`)
|
|
}
|
|
|
|
let creativeid = this.getQueryInfo(launchOptions, "creativeid", ad_paramsUrl);
|
|
if (creativeid && creativeid != "0") {
|
|
TDAnalyticsMgr.ins.cid(`${creativeid}`)
|
|
}
|
|
|
|
isNewUser = !LocalStorage.getItem("isNewUser")
|
|
|
|
// 抖转微巨量初始化
|
|
if (window["ChannelUpload"] && window["ChannelUpload"].default) {
|
|
ConsoleEx.Log("ChannelUpload抖转微初始化");
|
|
window["ChannelUpload"].default.Init(PlatformManager.instance.platData.appId, isNewUser);
|
|
}
|
|
|
|
if (!isNewUser) {
|
|
console.log("非新用户,不上报");
|
|
return;
|
|
}
|
|
if (!this.clickId) {
|
|
console.log("无 clickid,不上报");
|
|
return;
|
|
}
|
|
|
|
GEAnalyticsMgr.ins.TrySendtrack(GEType.new_player);
|
|
|
|
console.log("上报广告激活事件");
|
|
const url = 'https://analytics.oceanengine.com/api/v2/conversion';
|
|
const data = {
|
|
event_type: 'active',
|
|
context: {
|
|
ad: {
|
|
callback: this.clickId, // 广告 clickid
|
|
}
|
|
},
|
|
timestamp: new Date().getTime()
|
|
};
|
|
|
|
console.log("上报数据:", data);
|
|
// @ts-ignore
|
|
this._base.request({
|
|
url,
|
|
method: "POST",
|
|
data: JSON.stringify(data),
|
|
header: { "Content-Type": "application/json" },
|
|
success: (res) => {
|
|
console.log("广告归因上报成功:", res);
|
|
},
|
|
fail: (err) => {
|
|
console.error("广告归因上报失败:", err);
|
|
}
|
|
});
|
|
LocalStorage.setItem("isNewUser",true)
|
|
|
|
this.keepEvent()
|
|
}
|
|
|
|
// 次留存
|
|
public keepEvent() {
|
|
|
|
// 获取激活时间
|
|
//@ts-ignore
|
|
const activationDateStr = LocalStorage.getItem('activationDate')
|
|
// const clickId = GameManager.getInstance().getClickID();
|
|
|
|
// 检查是否有激活时间和clickId
|
|
if (!activationDateStr) {
|
|
console.log("未找到激活时间,不上报次留存");
|
|
return;
|
|
}
|
|
|
|
// 检查是否已经上报过次留存
|
|
//@ts-ignore
|
|
const hasReportedKeep = LocalStorage.getItem('hasReportedKeep');
|
|
if (hasReportedKeep) {
|
|
console.log("次留存已经上报过,不再上报");
|
|
return;
|
|
}
|
|
|
|
if (!this.clickId) {
|
|
console.log("无 clickid,不上报次留存");
|
|
return;
|
|
}
|
|
|
|
const activationDate = new Date(activationDateStr);
|
|
const currentDate = new Date();
|
|
|
|
// 计算日期差
|
|
const activationDay = new Date(activationDate.getFullYear(), activationDate.getMonth(), activationDate.getDate());
|
|
const currentDay = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate());
|
|
|
|
// 计算两个日期之间的天数差
|
|
const diffTime = currentDay.getTime() - activationDay.getTime();
|
|
const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));
|
|
|
|
// 只有当是激活后的第二天(diffDays === 1)才上报次留存
|
|
if (diffDays !== 1) {
|
|
console.log(`不是激活后的第二天(差值: ${diffDays}天),不上报次留存`);
|
|
return;
|
|
}
|
|
|
|
console.log("满足次留存条件,准备上报");
|
|
const url = 'https://analytics.oceanengine.com/api/v2/conversion';
|
|
const data = {
|
|
event_type: 'next_day_open',
|
|
context: {
|
|
ad: {
|
|
callback: this.clickId, // 广告 clickid
|
|
}
|
|
},
|
|
timestamp: currentDate.getTime()
|
|
};
|
|
|
|
console.log("上报数据:", data);
|
|
// @ts-ignore
|
|
this._base.request({
|
|
url,
|
|
method: "POST",
|
|
data: JSON.stringify(data),
|
|
header: { "Content-Type": "application/json" },
|
|
success: (res) => {
|
|
console.log("广告归因上报成功:", res);
|
|
// 标记已上报次留存,避免重复上报
|
|
//@ts-ignore
|
|
LocalStorage.setItem('hasReportedKeep', 'true');
|
|
},
|
|
fail: (err) => {
|
|
console.error("广告归因上报失败:", err);
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
reportScene(sceneID: number){}
|
|
}
|