提交 8c4fe5d5 作者: wangjin

增加视频广告接口

上级 2e950f5f
/** /**
* 鲸鱼游戏微信小游戏接入库 * 鲸鱼游戏微信小游戏接入库
* @author 推广技术部 * @author 推广技术部
* @time: 2022-06-27 * @time: 2022-07-28
* *
* 登录接口返回session_key改为login_code * 登录接口返回session_key改为login_code
* *
*/ */
class WechatSDK { class WechatSDK {
private sdkVersion: string = "3.0.9"; private sdkVersion: string = "3.1";
public LaunchOptions: Object; // 启动参数对象 public LaunchOptions: Object; // 启动参数对象
public SystemInfo: Object; // 设备信息 public SystemInfo: Object; // 设备信息
...@@ -76,6 +76,7 @@ class WechatSDK { ...@@ -76,6 +76,7 @@ class WechatSDK {
private sdkActive = async () => { private sdkActive = async () => {
const { data } = await this.sdkRequest(Links.active, { ...this.SDKCOMMDATA, ...this.LoginData }); const { data } = await this.sdkRequest(Links.active, { ...this.SDKCOMMDATA, ...this.LoginData });
this.LoginData["pay_channel"] = data.default_pay_channel; this.LoginData["pay_channel"] = data.default_pay_channel;
this.LoginData["ad_unit_id"] = data.ad_unit_id;
this.ActiReport(); // 上报激活 this.ActiReport(); // 上报激活
return this.sdkLogin(); return this.sdkLogin();
}; };
...@@ -784,8 +785,37 @@ class WechatSDK { ...@@ -784,8 +785,37 @@ class WechatSDK {
"1000": "参数错误", "1000": "参数错误",
"1003": "米大师Portal错误", "1003": "米大师Portal错误",
}; };
// 创建视频广告
private wxVideoAdReward: any = null; // 微信视频广告对象
// 初始化激励视频
public createWxVideoAd = async (wxVideoAdParams?: wxVideoAd) => {
this.wxVideoAdReward = await (wx as any).createRewardedVideoAd({
adUnitId: this.LoginData["ad_unit_id"], // mp后台配置的广告id
});
this.wxVideoAdReward.onError(err => {
console.log('微信激励广告视频播放失败:', err);
wxVideoAdParams && wxVideoAdParams.onError(err);
});
};
public playAdVideo = async (Params: ProductInfo, callback?: Function, retry: number = 0) => {
if (retry > 2) {
callback({ status: false });
return;
}
this.wxVideoAdReward.load()
.then(() => {
this.wxVideoAdReward.show()
.then(() => {
console.log('微信激励广告视频播放成功');
this.CustomReport({ customeventName: "adVideoReport", customeventData: {...Params} }); // 上报播放完成
callback({ status: true });
})
.catch(err => this.playAdVideo(Params, retry++, callback));
});
}
} }
interface shareInfo { declare interface shareInfo {
title?: string; title?: string;
image?: string; image?: string;
imageId?: string; imageId?: string;
...@@ -794,9 +824,23 @@ interface shareInfo { ...@@ -794,9 +824,23 @@ interface shareInfo {
fail: any; fail: any;
complete?: any; complete?: any;
} }
interface RecorderInfo { declare interface RecorderInfo {
duration: number; duration: number;
} }
declare interface wxVideoAd {
onError?: Function;
}
declare interface ProductInfo {
money: number
product_id: string
product_name: string
product_num: number
app_server: string
role_level: number
role_name: string
}
// SDK后端接口(勿改) // SDK后端接口(勿改)
const Links = { const Links = {
init: SDKConfig.sdk_domain + "/weixin/access_token.php", // 获取openid init: SDKConfig.sdk_domain + "/weixin/access_token.php", // 获取openid
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论