提交 75988269 作者: wj

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

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