123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- import { _decorator, Component, Node } from 'cc';
- import { WECHAT } from 'cc/env';
- import { Global } from '../Global';
- const { ccclass, property } = _decorator;
- @ccclass('WxPlatform')
- export class WxPlatform {
- static _ins: WxPlatform;
- public wx = window["wx"];
- /**
- *
- */
- static get ins() {
- if (!this._ins) {
- this._ins = new WxPlatform();
- }
- return this._ins;
- }
- wechat_setting() {
- console.log("1 执行 wechat_setting",WECHAT);
- if (!WECHAT) {
- return;
- }
- console.log("2 执行 wechat_setting");
- this.wx.showShareMenu({
- withShareTicket: true,
- menus: ['shareAppMessage', 'shareTimeline']
- });
- //upgrade
- const updateManager = this.wx.getUpdateManager()
- updateManager.onCheckForUpdate(function (res) {
- console.log("请求完新版本信息的回调", res.hasUpdate);
- })
- updateManager.onUpdateReady(function () {
- this.wx.showModal({
- title: '更新提示',
- content: '新版本已经准备好,是否重启应用?',
- success(res) {
- if (res.confirm) {
- // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
- updateManager.applyUpdate()
- }
- }
- })
- })
- updateManager.onUpdateFailed(function () {
- // 新版本下载失败
- console.log("新版本下载失败")
- })
- }
- /**
- *
- * @param delay
- * @returns
- */
- show_interstitial(delay = 0) {
- console.log("显示差评广告》〉》〉》〉》〉》〉》〉》");
- if (!WECHAT) {
- return;
- }
- // let id = Main.ins.Platforms[0].intersitialId[0];
- let ad_video_id = Global.ad_intersitial_id;
- let interstitialAd = this.wx.createInterstitialAd({
- adUnitId: ad_video_id.trim(),
- });
- if (interstitialAd) {
- interstitialAd.load().then(() => {
- console.log('插屏 广告加载成功');
- });
- interstitialAd.onClose(res => {
- console.log('关闭插屏广告', res);
- });
- interstitialAd.onError(err => {
- console.log('err:插屏广告加载失败', err);
- });
- setTimeout(() => {
- interstitialAd.show().catch((err) => {
- console.log('插屏广告展示失败', err);
- });
- }, delay * 1000);
- }
- }
- rewardVideo2: any;
- /**
- *
- * @param callback
- */
- show_reward_video(callback: Function) {
- let my = this;
- let ad_video_id = Global.ad_video_id;
- // let id = Main.ins.Platforms[0].videoId[0];
- if (my.rewardVideo2 != null) {
- my.rewardVideo2.offClose(fun);
- }
- let rewardedVideoAd = this.wx.createRewardedVideoAd({
- adUnitId: ad_video_id.trim(),
- });
- my.rewardVideo2 = rewardedVideoAd;
- rewardedVideoAd.load().then(() => {
- this.wx.showToast({
- title: "加载中,请稍后",
- icon: 'success',//图标,支持"success"、"loading"
- duration: 1500,//提示的延迟时间,单位毫秒,默认:1500
- mask: false,//是否显示透明蒙层,防止触摸穿透,默认:false
- success: function () { },
- fail: function () { },
- complete: function () { }
- })
- console.log('激励视频 广告加载成功');
- rewardedVideoAd.show();
- });
- rewardedVideoAd.onError(err => {
- console.log('激励视频 广告显示失败', err);
- this.wx.showToast({
- title: "请稍后再试",
- icon: 'fail',//图标,支持"success"、"loading"
- duration: 1500,//提示的延迟时间,单位毫秒,默认:1500
- mask: false,//是否显示透明蒙层,防止触摸穿透,默认:false
- success: function () { },
- fail: function () { },
- complete: function () { }
- })
- callback(2);
- })
- var fun = function (res) {
- if (res && res.isEnded) {
- console.log('res: ', res);
- callback(1);
- rewardedVideoAd.offClose(fun);
- } else {
- console.log('播放中途退出');
- callback(0);
- }
- }
- rewardedVideoAd.onClose(fun);
- }
- }
|