提交 75988269 作者: wj

增加微信激励广告视频接口

上级 85d3bea9
/**
* 鲸鱼游戏微信小游戏接入库
* @author 推广技术部
* @time: 2023-02-17
* @time: 2023-11-08
*
* SDK增加右上角分享开关
* 调试分享异常问题
*
*/
class WechatSDK {
private sdkVersion: string = "3.3.1";
private sdkVersion: string = "3.3.2";
public LaunchOptions: Object; // 启动参数对象
public SystemInfo: Object; // 设备信息
......@@ -18,7 +18,7 @@ class WechatSDK {
private clickCounter = 0; // 当前用户点击次数
private GameRecorder: any = null; // 录屏对象
private recorderBtn: any = null; // 对局回放分享按钮对象
private contrlShareMenu:number = 0; // 右上角分享开关
private contrlShareMenu: number = 0; // 右上角分享开关
constructor() {
console.log("当前加载SDK版本号为:", this.sdkVersion);
this.sdkInit();
......@@ -76,6 +76,7 @@ class WechatSDK {
// SDK激活
private sdkActive = async () => {
const { data } = await this.sdkRequest(Links.active, { ...this.SDKCOMMDATA, ...this.LoginData });
console.log("SDK active:", data);
this.LoginData["pay_channel"] = data.default_pay_channel;
this.LoginData["ad_unit_id"] = data.ad_unit_id;
this.LoginData["game_club"] = data.game_club;
......@@ -489,7 +490,7 @@ class WechatSDK {
});
}
public addShareEvent = (shareInfo: shareInfo, callback?) => {
if(!this.contrlShareMenu) return;
if (!this.contrlShareMenu) return;
(wx as any).onShareAppMessage(() => {
if (callback) callback();
const ShareParams = {
......@@ -513,7 +514,7 @@ class WechatSDK {
};
return this.share(ShareParams);
}
public ShareGameInfo = (shareInfo?:shareInfo) => {
public ShareGameInfo = (shareInfo?: shareInfo) => {
// 参数,记录分享的用户openid
const ShareParams = {
title: shareInfo && shareInfo.title ? shareInfo.title : SDKConfig.shareTitle,
......@@ -798,28 +799,29 @@ class WechatSDK {
"1003": "米大师Portal错误",
};
// 创建视频广告
private wxVideoAdReward: any = null; // 微信视频广告对象
private videoAd: any = null; // 微信视频广告对象
// 初始化激励视频
public createWxVideoAd = async (wxVideoAdParams?: wxVideoAd) => {
this.wxVideoAdReward = await (wx as any).createRewardedVideoAd({
adUnitId: this.LoginData["ad_unit_id"], // mp后台配置的广告id
public createWxVideoAd = async (adError?: Function) => {
this.videoAd = await (wx as any).createRewardedVideoAd({
adUnitId: SDKConfig.WXADUNITID, // mp后台配置的广告id
});
this.wxVideoAdReward.onError(err => {
this.videoAd.onError(err => {
console.log('微信激励广告视频播放失败:', err);
wxVideoAdParams && wxVideoAdParams.onError(err);
adError && adError(err);
});
};
// 激励视频播放
public playAdVideo = async (Params: ProductInfo, callback: Function, retry: number = 0) => {
if (retry > 2) {
callback({ status: false });
return;
}
this.wxVideoAdReward.load()
this.videoAd.load()
.then(() => {
this.wxVideoAdReward.show()
this.videoAd.show()
.then(() => {
console.log('微信激励广告视频播放成功');
this.CustomReport({ customeventName: "adVideoReport", customeventData: {...Params} }); // 上报播放完成
console.log('微信激励广告视频播放成功.');
this.CustomReport({ customeventName: "adVideoReport", customeventData: { ...Params } }); // 上报播放完成
callback({ status: true });
})
.catch(err => this.playAdVideo(Params, callback, retry++));
......@@ -841,10 +843,6 @@ declare interface RecorderInfo {
duration: number;
}
declare interface wxVideoAd {
onError?: Function;
}
declare interface ProductInfo {
money: number
product_id: string
......
......@@ -28,6 +28,8 @@ const SDKConfig = {
shareImageUrl: "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3903587193,374462562&fm=27&gp=0.jpg", //分享图片链接
shareImageId: "" // 分享图片后台配置ID
shareImageId: "", // 分享图片后台配置ID
WXADUNITID: "adunit-edc7d59bdbdf5bec"
// 结束
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论