From 5b1540fa5c18bc8b2739f4ab06d2a7b7953c65bf Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期六, 04 十二月 2021 18:24:30 +0800
Subject: [PATCH] 功能完善

---
 lib/utils/ad_util.dart |  268 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 241 insertions(+), 27 deletions(-)

diff --git a/lib/utils/ad_util.dart b/lib/utils/ad_util.dart
index 0dd7004..ec845f4 100644
--- a/lib/utils/ad_util.dart
+++ b/lib/utils/ad_util.dart
@@ -18,27 +18,98 @@
 
   static void showSplashAd(
       double width, double height, OnAdCallback adCallback) async {
-    var csjAppId = await ConfigUtil.getConfig(ConfigKey.csjAppId);
-    var gdtAppId = await ConfigUtil.getConfig(ConfigKey.gdtAppId);
-    if (StringUtil.isNullOrEmpty(csjAppId) &&
-        StringUtil.isNullOrEmpty(gdtAppId)) {
-      adCallback(false, "appId涓虹┖");
-      return;
+    //鍔犺浇骞垮憡
+  }
+
+  static Widget? loadSplash(AdinfoModel? adInfo, double width, double height,
+      OnAdCallback adCallback) {
+    if (adInfo == null) {
+      adCallback(false, "骞垮憡淇℃伅涓虹┖");
+      return null;
     }
 
-    var adInfo = await getAdInfo(AdPosition.splash);
-    if (adInfo == null) {
-      adCallback(false, "appId涓虹┖");
-      return;
+    if (StringUtil.isNullOrEmpty(adInfo.type)) {
+      adCallback(false, "骞垮憡绫诲瀷涓虹┖");
+      return null;
     }
 
     if (adInfo.type == "csj") {
-      CSJAdUtil.loadSplash(adInfo.pid!, width, height, (success, msg) {});
+      return CSJAdUtil.loadSplash(adInfo.pid!, width, height, adCallback);
     } else {
-      GDTAdUtil.loadSplash(adInfo.pid!, (success, msg) {});
+      return GDTAdUtil.loadSplash(adInfo.pid!, width, height, adCallback);
+    }
+  }
+
+  static Widget? loadBanner(
+      AdinfoModel? adInfo, double width, double height, OnAdCallback callback) {
+    if (adInfo == null) {
+      callback(false, "骞垮憡淇℃伅涓虹┖");
+      return null;
     }
 
-    //鍔犺浇骞垮憡
+    if (StringUtil.isNullOrEmpty(adInfo.type)) {
+      callback(false, "骞垮憡绫诲瀷涓虹┖");
+      return null;
+    }
+
+    if (adInfo.type == "csj") {
+      return CSJAdUtil.loadBanner(adInfo.pid!, width, height, callback);
+    } else {
+      return GDTAdUtil.loadBanner(adInfo.pid!, width, height, callback);
+    }
+  }
+
+  static Widget? loadExpress(
+      AdinfoModel? adInfo, double width, double height, OnAdCallback callback) {
+    if (adInfo == null) {
+      callback(false, "骞垮憡淇℃伅涓虹┖");
+      return null;
+    }
+
+    if (StringUtil.isNullOrEmpty(adInfo.type)) {
+      callback(false, "骞垮憡绫诲瀷涓虹┖");
+      return null;
+    }
+
+    if (adInfo.type == "csj") {
+      return CSJAdUtil.loadExpress(adInfo.pid!, width, height, callback);
+    } else {
+      return GDTAdUtil.loadExpress(adInfo.pid!, width, height, callback);
+    }
+  }
+
+  static loadReward(AdinfoModel? adInfo, OnAdCallback callback) async {
+    if (adInfo == null) {
+      callback(false, "骞垮憡淇℃伅涓虹┖");
+      return null;
+    }
+
+    if (StringUtil.isNullOrEmpty(adInfo.type)) {
+      callback(false, "骞垮憡绫诲瀷涓虹┖");
+      return null;
+    }
+
+    if (adInfo.type == "csj") {
+      return CSJAdUtil.loadReward(adInfo.pid!, callback);
+    } else {
+      return GDTAdUtil.loadReward(adInfo.pid!, callback);
+    }
+  }
+
+  static loadInterstitial(AdinfoModel? adInfo, OnAdCallback callback) async {
+    if (adInfo == null) {
+      return null;
+    }
+
+    if (StringUtil.isNullOrEmpty(adInfo.type)) {
+      return null;
+    }
+
+    if (adInfo.type == "csj") {
+      CSJAdUtil.loadInterstitial(adInfo.pid!, callback);
+    } else {
+      GDTAdUtil.loadInterstitial(adInfo.pid!, callback);
+    }
   }
 
   static Future<AdinfoModel?> getAdInfo(String position) async {
@@ -50,12 +121,13 @@
     if (StringUtil.isNullOrEmpty(model.type)) {
       return null;
     }
+    return model;
   }
 }
 
 class CSJAdUtil {
   static Future init() async {
-    var csjAppId = await ConfigUtil.getConfig(ConfigKey.csjAppId);
+    var csjAppId = "5240078";
     //鍒濆鍖栫┛灞辩敳
     if (!StringUtil.isNullOrEmpty(csjAppId)) {
       // if (Platform.isAndroid) {
@@ -79,7 +151,7 @@
       // }
 
       await FlutterUnionad.register(
-          androidAppId: csjAppId!,
+          androidAppId: csjAppId,
           //绌垮北鐢插箍鍛� Android appid 蹇呭~
           iosAppId: "",
           //绌垮北鐢插箍鍛� ios appid 蹇呭~
@@ -270,7 +342,7 @@
     );
   }
 
-  static loadInterstitial(String pid) async {
+  static loadInterstitial(String pid, OnAdCallback adCallback) async {
     FlutterUnionad.loadFullScreenVideoAdInteraction(
       androidCodeId: pid, //android 鍏ㄥ睆骞垮憡id 蹇呭~
       iosCodeId: "", //ios 鍏ㄥ睆骞垮憡id 蹇呭~
@@ -296,9 +368,11 @@
         },
         onFail: (error) {
           print("鏂版ā鏉挎覆鏌撴彃灞忓箍鍛婇敊璇� $error");
+          adCallback(false, "鏂版ā鏉挎覆鏌撴彃灞忓箍鍛婇敊璇� $error");
         },
         onClose: () {
           print("鏂版ā鏉挎覆鏌撴彃灞忓箍鍛婂叧闂�");
+          adCallback(true, "鏂版ā鏉挎覆鏌撴彃灞忓箍鍛婂叧闂�");
         },
         onReady: () async {
           print("鏂版ā鏉挎覆鏌撴彃灞忓箍鍛婇鍔犺浇鍑嗗灏辩华");
@@ -315,25 +389,22 @@
 
 class GDTAdUtil {
   static Future init() async {
-    var gdtAppId = await ConfigUtil.getConfig(ConfigKey.gdtAppId);
+    var gdtAppId = "1200343363";
     //鍒濆鍖栧箍鐐归��
     if (!StringUtil.isNullOrEmpty(gdtAppId)) {
       await FlutterTencentad.register(
-        androidId: gdtAppId!, //androidId
+        androidId: gdtAppId, //androidId
         iosId: "", //iosId
         debug: true, //鏄惁鏄剧ず鏃ュ織log
       );
     }
   }
 
-  static loadSplash(String? pid, OnAdCallback adCallback) {
-    if (pid == null) {
-      adCallback(false, "pid涓虹┖");
-      return;
-    }
-    FlutterTencentad.splashAdView(
+  static Widget? loadSplash(
+      String? pid, double width, double height, OnAdCallback adCallback) {
+    return FlutterTencentad.splashAdView(
       //android骞垮憡id
-      androidId: pid,
+      androidId: pid!,
       //ios骞垮憡id
       iosId: "",
       ////璁剧疆寮�灞忓箍鍛婁粠璇锋眰鍒板睍绀烘墍鑺辩殑鏈�澶ф椂闀匡紙骞朵笉鏄寚骞垮憡鏇濆厜鏃堕暱锛夛紝鍙栧�艰寖鍥翠负[1500, 5000]ms
@@ -351,13 +422,156 @@
         },
         onClose: () {
           print("寮�灞忓箍鍛婂叧闂�");
-          adCallback(true, "");
+          adCallback(true, "寮�灞忓箍鍛婂叧闂�");
         },
         onExpose: () {
           print("寮�灞忓箍鍛婃洕鍏�");
         },
         onFail: (code, message) {
-          adCallback(true, message);
+          adCallback(false, message);
+        },
+      ),
+    );
+  }
+
+  static Widget loadBanner(
+      String pid, double width, double height, OnAdCallback callback) {
+    return FlutterTencentad.bannerAdView(
+      //android骞垮憡id
+      androidId: pid,
+      //ios骞垮憡id
+      iosId: "",
+      //骞垮憡瀹� 鍗曚綅dp
+      viewWidth: width,
+      //骞垮憡楂�  鍗曚綅dp   瀹介珮姣斿簲璇ヤ负6.4:1
+      viewHeight: height,
+      // 骞垮憡鍥炶皟
+      callBack: FlutterTencentadBannerCallBack(
+        onShow: () {
+          print("Banner骞垮憡鏄剧ず");
+        },
+        onFail: (code, message) {
+          print("Banner骞垮憡閿欒 $code $message");
+          callback(false, "Banner骞垮憡閿欒  $code $message");
+        },
+        onClose: () {
+          print("Banner骞垮憡鍏抽棴");
+          callback(true, "Banner骞垮憡鍏抽棴");
+        },
+        onExpose: () {
+          print("Banner骞垮憡鏇濆厜");
+        },
+        onClick: () {
+          print("Banner骞垮憡鐐瑰嚮");
+        },
+      ),
+    );
+  }
+
+  static Widget loadExpress(
+      String pid, double width, double height, OnAdCallback callback) {
+    return FlutterTencentad.expressAdView(
+        //android骞垮憡id
+        androidId: pid,
+        //ios骞垮憡id
+        iosId: "",
+        //骞垮憡瀹� 鍗曚綅dp
+        viewWidth: width.toInt(),
+        //骞垮憡楂�  鍗曚綅dp
+        viewHeight: height.toInt(),
+        //鍥炶皟浜嬩欢
+        callBack: FlutterTencentadExpressCallBack(
+          onShow: () {
+            print("鍔ㄦ�佷俊鎭祦骞垮憡鏄剧ず");
+          },
+          onFail: (code, message) {
+            print("鍔ㄦ�佷俊鎭祦骞垮憡閿欒 $code $message");
+          },
+          onClose: () {
+            print("鍔ㄦ�佷俊鎭祦骞垮憡鍏抽棴");
+          },
+          onExpose: () {
+            print("鍔ㄦ�佷俊鎭祦骞垮憡鏇濆厜");
+          },
+          onClick: () {
+            print("鍔ㄦ�佷俊鎭祦骞垮憡鐐瑰嚮");
+          },
+        ));
+  }
+
+  static loadReward(String pid, OnAdCallback adCallback) async {
+    await FlutterTencentad.loadRewardVideoAd(
+        //android骞垮憡id
+        androidId: pid,
+        //ios骞垮憡id
+        iosId: "",
+        //鐢ㄦ埛id
+        userID: "",
+        //濂栧姳
+        rewardName: "VIP",
+        //濂栧姳鏁�
+        rewardAmount: 1,
+        //鎵╁睍鍙傛暟 鏈嶅姟鍣ㄥ洖璋冧娇鐢�
+        customData: "");
+
+    FlutterTencentAdStream.initAdStream(
+      //婵�鍔卞箍鍛�
+      flutterTencentadRewardCallBack:
+          FlutterTencentadRewardCallBack(onShow: () {
+        print("婵�鍔卞箍鍛婃樉绀�");
+      }, onClick: () {
+        print("婵�鍔卞箍鍛婄偣鍑�");
+      }, onFail: (code, message) {
+        print("婵�鍔卞箍鍛婂け璐� $code $message");
+        adCallback(false, "婵�鍔卞箍鍛婂け璐�");
+      }, onClose: () {
+        print("婵�鍔卞箍鍛婂叧闂�");
+      }, onReady: () async {
+        print("婵�鍔卞箍鍛婇鍔犺浇鍑嗗灏辩华");
+        await FlutterTencentad.showRewardVideoAd();
+      }, onUnReady: () {
+        print("婵�鍔卞箍鍛婇鍔犺浇鏈噯澶囧氨缁�");
+      }, onVerify: (transId, rewardName, rewardAmount) {
+        print("婵�鍔卞箍鍛婂鍔�  $transId   $rewardName   $rewardAmount");
+        adCallback(true, "婵�鍔卞箍鍛婂鍔�");
+      }, onFinish: () {
+        print("婵�鍔卞箍鍛婂畬鎴�");
+      }),
+    );
+  }
+
+  static loadInterstitial(String pid, OnAdCallback adCallback) async {
+    await FlutterTencentad.loadUnifiedInterstitialAD(
+      //android骞垮憡id
+      androidId: pid,
+      //ios骞垮憡id
+      iosId: "",
+      //鏄惁鍏ㄥ睆
+      isFullScreen: false,
+    );
+
+    FlutterTencentAdStream.initAdStream(
+      flutterTencentadInteractionCallBack: FlutterTencentadInteractionCallBack(
+        onShow: () {
+          print("鎻掑睆骞垮憡鏄剧ず");
+        },
+        onClick: () {
+          print("鎻掑睆骞垮憡鐐瑰嚮");
+        },
+        onFail: (code, message) {
+          print("鎻掑睆骞垮憡澶辫触 $code $message");
+          adCallback(false, "鎻掑睆骞垮憡澶辫触 $code $message");
+        },
+        onClose: () {
+          print("鎻掑睆骞垮憡鍏抽棴");
+          adCallback(true, "鎻掑睆骞垮憡鍏抽棴");
+        },
+        onReady: () async {
+          print("鎻掑睆骞垮憡棰勫姞杞藉噯澶囧氨缁�");
+          await FlutterTencentad.showUnifiedInterstitialAD();
+        },
+        onUnReady: () {
+          print("鎻掑睆骞垮憡棰勫姞杞芥湭鍑嗗灏辩华");
         },
       ),
     );

--
Gitblit v1.8.0