Commit 269f2a58 authored by 王雪伟's avatar 王雪伟

修复设置actionName为null 和 上报加入公共参数

parent cd52f889
{
"version": "1.0",
"components": [
"Microsoft.VisualStudio.Workload.ManagedGame"
]
}
...@@ -3,6 +3,7 @@ using System.Collections.Generic; ...@@ -3,6 +3,7 @@ using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using System; using System;
using Tencent.GDT; using Tencent.GDT;
using System.Runtime.InteropServices;
public class AdManager public class AdManager
{ {
...@@ -40,7 +41,8 @@ public class AdManager ...@@ -40,7 +41,8 @@ public class AdManager
return activity; return activity;
} }
[DllImport("__Internal")]
public static extern void InitCSJSDK(string appId); // ios初始化穿山甲SDK
private bool IsInitAd = false; private bool IsInitAd = false;
...@@ -55,16 +57,20 @@ public class AdManager ...@@ -55,16 +57,20 @@ public class AdManager
//paras.Clear(); //paras.Clear();
//paras.Add("pkg", "com.ym.xynt"); //paras.Add("pkg", "com.ym.xynt");
//获取广告配置 //获取广告配置
Dictionary<string, object> paras = new Dictionary<string, object>(); HttpTool.Instance._GetAD(AdConfigUrl, null, new Action<List<AdIdConfig>>((AdConfigList) =>
HttpTool.Instance._GetAD(AdConfigUrl, paras, new Action<List<AdIdConfig>>((AdConfigList) =>
{ {
foreach (AdIdConfig id in AdConfigList) foreach (AdIdConfig id in AdConfigList)
{ {
switch (id.adPlatform) switch (id.adPlatform)
{ {
//初始化穿山甲广告ID
case ZXADConfig.PLANTFORM_AD_TT: case ZXADConfig.PLANTFORM_AD_TT:
#if UNITY_ANDROID
AndroidJavaClass jc = new AndroidJavaClass("com.unity.adcommon.unity.TTADManager"); AndroidJavaClass jc = new AndroidJavaClass("com.unity.adcommon.unity.TTADManager");
jc.CallStatic("init", id.codeAppId); jc.CallStatic("init", id.codeAppId);
#elif UNITY_IOS
InitCSJSDK(id.codeAppId);
#endif
break; break;
case ZXADConfig.PLANTFORM_AD_GDT: case ZXADConfig.PLANTFORM_AD_GDT:
if (id.codeAppId != null && id.codeAppId != "") if (id.codeAppId != null && id.codeAppId != "")
...@@ -170,8 +176,14 @@ public class AdManager ...@@ -170,8 +176,14 @@ public class AdManager
switch (entity.adPlatform) switch (entity.adPlatform)
{ {
case ZXADConfig.PLANTFORM_AD_TT: case ZXADConfig.PLANTFORM_AD_TT:
//加载穿山甲开屏广告 #if UNITY_ANDROID
//加载穿山甲开屏广告
CSJSplshADUtils.Instance.LoadSplshAd(entity, GetActivity(), GetSplashAdManager(), listener, callback); CSJSplshADUtils.Instance.LoadSplshAd(entity, GetActivity(), GetSplashAdManager(), listener, callback);
#elif UNITY_IOS
//加载穿山甲开屏广告
CSJSplshADUtils.Instance.LoadSplshAd(entity,null, null, listener, callback);
#endif
break; break;
case ZXADConfig.PLANTFORM_AD_GDT: case ZXADConfig.PLANTFORM_AD_GDT:
//广点通开屏广告 //广点通开屏广告
...@@ -275,9 +287,9 @@ public class AdManager ...@@ -275,9 +287,9 @@ public class AdManager
public void ShowCacheBannerAd(string slotName,string actionName) public void ShowCacheBannerAd(string slotName,string actionName)
{ {
AdEntity entity = ZXADConfig.Instance.GetAdCache(slotName, ""); AdEntity entity = ZXADConfig.Instance.GetAdCache(slotName, "");
entity.actionName = actionName;
if (entity != null) if (entity != null)
{ {
entity.actionName = actionName;
ZXADConfig.Instance.RemoveAdCache(slotName, ""); ZXADConfig.Instance.RemoveAdCache(slotName, "");
mShowCacheBannerAdPlatform(entity, new Action<bool>((bl) => mShowCacheBannerAdPlatform(entity, new Action<bool>((bl) =>
{ {
...@@ -293,6 +305,7 @@ public class AdManager ...@@ -293,6 +305,7 @@ public class AdManager
} }
else else
{ {
LoadCacheBannerAd(slotName);
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "展示Banner失败 缓存的信息为null"); Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "展示Banner失败 缓存的信息为null");
} }
} }
...@@ -350,7 +363,7 @@ public class AdManager ...@@ -350,7 +363,7 @@ public class AdManager
/// <summary> /// <summary>
/// 根据广告List开始加载插屏缓存 /// 根据广告List开始加载大图缓存
/// </summary> /// </summary>
private Action<bool> FeedAdCallBack; private Action<bool> FeedAdCallBack;
private void mLoadFeedCacheAd(string sloatName, List<AdEntity> adList) private void mLoadFeedCacheAd(string sloatName, List<AdEntity> adList)
...@@ -409,9 +422,9 @@ public class AdManager ...@@ -409,9 +422,9 @@ public class AdManager
public void ShowCacheFeedAd(string slotName,string actionName) public void ShowCacheFeedAd(string slotName,string actionName)
{ {
AdEntity entity = ZXADConfig.Instance.GetAdCache(slotName, ""); AdEntity entity = ZXADConfig.Instance.GetAdCache(slotName, "");
entity.actionName = actionName;
if (entity != null) if (entity != null)
{ {
entity.actionName = actionName;
ZXADConfig.Instance.RemoveAdCache(slotName, ""); ZXADConfig.Instance.RemoveAdCache(slotName, "");
mShowCacheFeedAdPlatform(entity, new Action<bool>((bl) => mShowCacheFeedAdPlatform(entity, new Action<bool>((bl) =>
{ {
...@@ -427,6 +440,7 @@ public class AdManager ...@@ -427,6 +440,7 @@ public class AdManager
} }
else else
{ {
LoadCacheFeedAd(slotName);
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "展示大图失败 缓存的信息为null"); Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "展示大图失败 缓存的信息为null");
} }
} }
...@@ -543,25 +557,26 @@ public class AdManager ...@@ -543,25 +557,26 @@ public class AdManager
public void PlayCacheInterstitialAd(string slotName,string actionName) public void PlayCacheInterstitialAd(string slotName,string actionName)
{ {
AdEntity entity = ZXADConfig.Instance.GetAdCache(slotName,""); AdEntity entity = ZXADConfig.Instance.GetAdCache(slotName,"");
entity.actionName = actionName;
if (entity != null) if (entity != null)
{ {
entity.actionName = actionName;
ZXADConfig.Instance.RemoveAdCache(slotName, ""); ZXADConfig.Instance.RemoveAdCache(slotName, "");
mPlayCacheInterstitialAdPlatform(entity, new Action<bool>((bl) => mPlayCacheInterstitialAdPlatform(entity, new Action<bool>((bl) =>
{ {
if (bl) if (bl)
{ {
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "播放屏视频成功 " + entity.adPlatform + " CodeId" + entity.codeId); Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "播放屏视频成功 " + entity.adPlatform + " CodeId" + entity.codeId);
} }
else else
{ {
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "播放屏视频失败 " + entity.adPlatform + " CodeId" + entity.codeId); Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "播放屏视频失败 " + entity.adPlatform + " CodeId" + entity.codeId);
} }
})); }));
} }
else else
{ {
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "播放全屏视频失败 缓存的信息为null"); LoadCacheInterstitialAd(slotName);
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "播放插屏视频失败 缓存的信息为null");
} }
} }
...@@ -789,9 +804,9 @@ public class AdManager ...@@ -789,9 +804,9 @@ public class AdManager
entity = entityB; entity = entityB;
ZXADConfig.Instance.RemoveAdCache(slotName, "B"); ZXADConfig.Instance.RemoveAdCache(slotName, "B");
} }
entity.actionName = actionName;
if (entity != null) if (entity != null)
{ {
entity.actionName = actionName;
mPlayCacheFSVodeoAdPlatform(entity, listener, new Action<bool>((bl) => mPlayCacheFSVodeoAdPlatform(entity, listener, new Action<bool>((bl) =>
{ {
if (bl) if (bl)
...@@ -806,6 +821,8 @@ public class AdManager ...@@ -806,6 +821,8 @@ public class AdManager
} }
else else
{ {
LoadCacheFSVideoAd(slotName);
listener.onError("播放全屏视频失败 缓存的信息为null");
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "播放全屏视频失败 缓存的信息为null"); Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "播放全屏视频失败 缓存的信息为null");
} }
} }
...@@ -897,14 +914,12 @@ public class AdManager ...@@ -897,14 +914,12 @@ public class AdManager
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "激励视频A组没有数据"); Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "激励视频A组没有数据");
return; return;
} }
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "正序的第一个广告ID" + adList[0].codeId);
if (IsFirstLoadRewardAd) if (IsFirstLoadRewardAd)
{ {
//第一次预加载 A组进行逆序加载 //第一次预加载 A组进行逆序加载
IsFirstLoadRewardAd = false; IsFirstLoadRewardAd = false;
adList.Reverse(); adList.Reverse();
} }
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "反序的第一个广告ID" + adList[0].codeId);
List<AdEntity> totalEntityList = adList; List<AdEntity> totalEntityList = adList;
AdEntity entity = totalEntityList[0]; AdEntity entity = totalEntityList[0];
...@@ -1046,9 +1061,9 @@ public class AdManager ...@@ -1046,9 +1061,9 @@ public class AdManager
ZXADConfig.Instance.RemoveAdCache(slotName, "B"); ZXADConfig.Instance.RemoveAdCache(slotName, "B");
} }
entity.actionName = actionName;
if (entity != null) if (entity != null)
{ {
entity.actionName = actionName;
mPlayCacheRewardVodeoAdPlatform(entity, listener, new Action<bool>((bl) => mPlayCacheRewardVodeoAdPlatform(entity, listener, new Action<bool>((bl) =>
{ {
...@@ -1059,14 +1074,15 @@ public class AdManager ...@@ -1059,14 +1074,15 @@ public class AdManager
else else
{ {
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, entity.codeGroup + "播放激励视频失败 " + entity.adPlatform + " CodeId" + entity.codeId); Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, entity.codeGroup + "播放激励视频失败 " + entity.adPlatform + " CodeId" + entity.codeId);
//listener.onError(entity.codeGroup + "播放激励视频失败 " + entity.adPlatform + " CodeId" + entity.codeId);
} }
})); }));
} }
else else
{ {
LoadCacheRewardVideoAd(slotName);
listener.onError("播放激励视频失败 缓存的信息为null");
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "播放激励视频失败 缓存的信息为null"); Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "播放激励视频失败 缓存的信息为null");
} }
} }
......
...@@ -135,21 +135,25 @@ public class CSJBannerUtil ...@@ -135,21 +135,25 @@ public class CSJBannerUtil
public void OnExpressAdLoad(List<ExpressAd> ads) public void OnExpressAdLoad(List<ExpressAd> ads)
{ {
#if UNITY_ANDROID
EventUtils.onEventPullSuccess(entity); EventUtils.onEventPullSuccess(entity);
IEnumerator<ExpressAd> enumerator = ads.GetEnumerator(); IEnumerator<ExpressAd> enumerator = ads.GetEnumerator();
if (enumerator.MoveNext()) if (enumerator.MoveNext())
{ {
callback(true);
bannerAdCacheListAndroid.Enqueue(enumerator.Current); bannerAdCacheListAndroid.Enqueue(enumerator.Current);
callback(true);
} }
#endif
} }
#if UNITY_IOS #if UNITY_IOS
public void OnExpressBannerAdLoad(ExpressBannerAd ad) public void OnExpressBannerAdLoad(ExpressBannerAd ad)
{ {
EventUtils.onEventPullSuccess(entity); EventUtils.onEventPullSuccess(entity);
callback(true);
Debug.Log("OnExpressBannerAdLoad"); Debug.Log("OnExpressBannerAdLoad");
bannerAdCacheListIOS.Enqueue(ad); bannerAdCacheListIOS.Enqueue(ad);
callback(true);
} }
public void OnExpressInterstitialAdLoad(ExpressInterstitialAd ad) public void OnExpressInterstitialAdLoad(ExpressInterstitialAd ad)
...@@ -186,16 +190,17 @@ public class CSJBannerUtil ...@@ -186,16 +190,17 @@ public class CSJBannerUtil
public void OnAdShow(ExpressAd ad) public void OnAdShow(ExpressAd ad)
{ {
Debug.Log("express OnAdShow,type:" + type);
EventUtils.onEventShowSuccess(entity); EventUtils.onEventShowSuccess(entity);
callback(true); callback(true);
Debug.Log("express OnAdShow,type:" + type);
} }
public void OnAdViewRenderError(ExpressAd ad, int code, string message) public void OnAdViewRenderError(ExpressAd ad, int code, string message)
{ {
Debug.Log("express OnAdViewRenderError,type:" + type);
EventUtils.onEventShowFail(entity); EventUtils.onEventShowFail(entity);
callback(false); callback(false);
Debug.Log("express OnAdViewRenderError,type:" + type);
} }
public void OnAdViewRenderSucc(ExpressAd ad, float width, float height) public void OnAdViewRenderSucc(ExpressAd ad, float width, float height)
......
...@@ -125,8 +125,8 @@ public class CSJFeedUtil : MonoBehaviour ...@@ -125,8 +125,8 @@ public class CSJFeedUtil : MonoBehaviour
IEnumerator<ExpressAd> enumerator = ads.GetEnumerator(); IEnumerator<ExpressAd> enumerator = ads.GetEnumerator();
if (enumerator.MoveNext()) if (enumerator.MoveNext())
{ {
callback(true);
feedAdCacheList.Enqueue(enumerator.Current); feedAdCacheList.Enqueue(enumerator.Current);
callback(true);
} }
} }
#if UNITY_IOS #if UNITY_IOS
...@@ -168,16 +168,18 @@ public class CSJFeedUtil : MonoBehaviour ...@@ -168,16 +168,18 @@ public class CSJFeedUtil : MonoBehaviour
public void OnAdShow(ExpressAd ad) public void OnAdShow(ExpressAd ad)
{ {
Debug.Log("express OnAdShow,type:" + type);
EventUtils.onEventShowSuccess(entity); EventUtils.onEventShowSuccess(entity);
callback(true); callback(true);
Debug.Log("express OnAdShow,type:" + type);
} }
public void OnAdViewRenderError(ExpressAd ad, int code, string message) public void OnAdViewRenderError(ExpressAd ad, int code, string message)
{ {
Debug.Log("express OnAdViewRenderError,type:" + type);
EventUtils.onEventShowFail(entity); EventUtils.onEventShowFail(entity);
callback(false); callback(false);
Debug.Log("express OnAdViewRenderError,type:" + type);
} }
public void OnAdViewRenderSucc(ExpressAd ad, float width, float height) public void OnAdViewRenderSucc(ExpressAd ad, float width, float height)
...@@ -186,8 +188,9 @@ public class CSJFeedUtil : MonoBehaviour ...@@ -186,8 +188,9 @@ public class CSJFeedUtil : MonoBehaviour
} }
public void OnAdClose(ExpressAd ad) public void OnAdClose(ExpressAd ad)
{ {
EventUtils.onEventAdComplete(entity);
Debug.Log("express OnAdClose,type:" + type); Debug.Log("express OnAdClose,type:" + type);
EventUtils.onEventAdComplete(entity);
} }
} }
......
...@@ -59,7 +59,7 @@ public class CSJFullScreenUtil : MonoBehaviour ...@@ -59,7 +59,7 @@ public class CSJFullScreenUtil : MonoBehaviour
.SetOrientation(AdOrientation.Horizontal) .SetOrientation(AdOrientation.Horizontal)
.Build(); .Build();
#if UNITY_IOS #if UNITY_IOS
this.AdNative.LoadExpressFullScreenVideoAd(adSlot, new FullScreenVideoAdListener(this, callback)); this.AdNative.LoadExpressFullScreenVideoAd(adSlot, new FullScreenVideoAdListener(this,entity, callback));
#else #else
this.AdNative.LoadFullScreenVideoAd(adSlot, new FullScreenVideoAdListener(this, entity, callback)); this.AdNative.LoadFullScreenVideoAd(adSlot, new FullScreenVideoAdListener(this, entity, callback));
#endif #endif
...@@ -71,7 +71,7 @@ public class CSJFullScreenUtil : MonoBehaviour ...@@ -71,7 +71,7 @@ public class CSJFullScreenUtil : MonoBehaviour
ExpressFullScreenVideoAd fsAd = GetFSVideoAdForIOS(entity.codeGroup+entity.codeId); ExpressFullScreenVideoAd fsAd = GetFSVideoAdForIOS(entity.codeGroup+entity.codeId);
if (fsAd!=null) if (fsAd!=null)
{ {
fsAd.SetFullScreenVideoAdInteractionListener(new FullScreenAdInteractionListener(listener, callback)); fsAd.SetFullScreenVideoAdInteractionListener(new FullScreenAdInteractionListener(entity,listener, callback));
fsAd.ShowFullScreenVideoAd(); fsAd.ShowFullScreenVideoAd();
} }
else else
...@@ -163,8 +163,8 @@ public class CSJFullScreenUtil : MonoBehaviour ...@@ -163,8 +163,8 @@ public class CSJFullScreenUtil : MonoBehaviour
public void OnAdShow() public void OnAdShow()
{ {
EventUtils.onEventShowSuccess(entity); EventUtils.onEventShowSuccess(entity);
callback(true);
listener.onAdShow(); listener.onAdShow();
callback(true);
} }
public void OnAdVideoBarClick() public void OnAdVideoBarClick()
...@@ -187,8 +187,9 @@ public class CSJFullScreenUtil : MonoBehaviour ...@@ -187,8 +187,9 @@ public class CSJFullScreenUtil : MonoBehaviour
public void OnVideoError() public void OnVideoError()
{ {
EventUtils.onEventShowFail(entity); EventUtils.onEventShowFail(entity);
callback(false);
listener.onError("CSJ 全屏视频播放错误"); listener.onError("CSJ 全屏视频播放错误");
callback(false);
} }
} }
......
...@@ -105,8 +105,9 @@ public class CSJInterstitialUtil ...@@ -105,8 +105,9 @@ public class CSJInterstitialUtil
} }
else else
{ {
callback(false);
Debug.Log("CSJ 插屏广告没有缓存数据了"); Debug.Log("CSJ 插屏广告没有缓存数据了");
callback(false);
} }
#endif #endif
} }
...@@ -130,13 +131,20 @@ public class CSJInterstitialUtil ...@@ -130,13 +131,20 @@ public class CSJInterstitialUtil
public void OnExpressAdLoad(List<ExpressAd> ads) public void OnExpressAdLoad(List<ExpressAd> ads)
{ {
#if UNITY_ANDROID
EventUtils.onEventPullSuccess(entity); EventUtils.onEventPullSuccess(entity);
IEnumerator<ExpressAd> enumerator = ads.GetEnumerator(); IEnumerator<ExpressAd> enumerator = ads.GetEnumerator();
if (enumerator.MoveNext()) if (enumerator.MoveNext())
{ {
callback(true);
interstitialAdCacheListAndroid.Enqueue(enumerator.Current); interstitialAdCacheListAndroid.Enqueue(enumerator.Current);
callback(true);
} }
#endif
} }
#if UNITY_IOS #if UNITY_IOS
public void OnExpressBannerAdLoad(ExpressBannerAd ad) public void OnExpressBannerAdLoad(ExpressBannerAd ad)
...@@ -147,8 +155,9 @@ public class CSJInterstitialUtil ...@@ -147,8 +155,9 @@ public class CSJInterstitialUtil
public void OnExpressInterstitialAdLoad(ExpressInterstitialAd ad) public void OnExpressInterstitialAdLoad(ExpressInterstitialAd ad)
{ {
EventUtils.onEventPullSuccess(entity); EventUtils.onEventPullSuccess(entity);
callback(true);
interstitialAdCacheListIOS.Enqueue(ad); interstitialAdCacheListIOS.Enqueue(ad);
callback(true);
} }
#else #else
#endif #endif
......
...@@ -121,9 +121,9 @@ public class CSJRewardUtil ...@@ -121,9 +121,9 @@ public class CSJRewardUtil
public void OnError(int code, string message) public void OnError(int code, string message)
{ {
EventUtils.onEventPullFail(entity, code.ToString(),message); EventUtils.onEventPullFail(entity, code.ToString(),message);
callback(false);
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, entity.adPlatform + " 激励视频 Error Group" + entity.codeGroup + " Code " + code + " msg" + message); Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, entity.adPlatform + " 激励视频 Error Group" + entity.codeGroup + " Code " + code + " msg" + message);
} callback(false);
}
public void OnRewardVideoAdLoad(RewardVideoAd ad) public void OnRewardVideoAdLoad(RewardVideoAd ad)
{ {
...@@ -181,9 +181,10 @@ public class CSJRewardUtil ...@@ -181,9 +181,10 @@ public class CSJRewardUtil
{ {
EventUtils.onEventShowSuccess(entity); EventUtils.onEventShowSuccess(entity);
Debug.Log("rewardVideoAd show"); Debug.Log("rewardVideoAd show");
listener.onAdShow();
callback(true); callback(true);
//this.cjsAd.rewardAd = null; //this.cjsAd.rewardAd = null;
listener.onAdShow();
} }
public void OnAdVideoBarClick() public void OnAdVideoBarClick()
...@@ -214,8 +215,9 @@ public class CSJRewardUtil ...@@ -214,8 +215,9 @@ public class CSJRewardUtil
{ {
EventUtils.onEventShowFail(entity); EventUtils.onEventShowFail(entity);
Debug.Log("rewardVideoAd error"); Debug.Log("rewardVideoAd error");
callback(false);
listener.onError("CSJ RewardAd Error"); listener.onError("CSJ RewardAd Error");
callback(false);
} }
public void OnRewardVerify(bool rewardVerify, int rewardAmount, string rewardName) public void OnRewardVerify(bool rewardVerify, int rewardAmount, string rewardName)
......
...@@ -39,12 +39,12 @@ public class AdDemo : MonoBehaviour ...@@ -39,12 +39,12 @@ public class AdDemo : MonoBehaviour
public void onAdClose() public void onAdClose()
{ {
this.demo.RewardAdResult.text = "Reward onAdClose"; this.demo.RewardAdResult.text = "Reward onAdClose";
//AdManager.Instance.LoadCacheRewardVideoAd("video");
} }
public void onAdShow() public void onAdShow()
{ {
this.demo.RewardAdResult.text = "Reward onAdShow"; this.demo.RewardAdResult.text = "Reward onAdShow";
AdManager.Instance.LoadCacheRewardVideoAd("video");
} }
public void onAdVideoBarClick() public void onAdVideoBarClick()
......
...@@ -59,12 +59,12 @@ public class Splash : MonoBehaviour ...@@ -59,12 +59,12 @@ public class Splash : MonoBehaviour
public void onAdSkip() public void onAdSkip()
{ {
SceneManager.LoadScene("AdDemo"); SceneManager.LoadSceneAsync("AdDemo");
} }
public void onError(string errorMsg) public void onError(string errorMsg)
{ {
SceneManager.LoadScene("AdDemo"); SceneManager.LoadSceneAsync("AdDemo");
} }
} }
......
...@@ -528,5 +528,6 @@ PrefabInstance: ...@@ -528,5 +528,6 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z propertyPath: m_LocalEulerAnglesHint.z
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents:
- {fileID: 5984542369482327738, guid: 1053be02c113a7a45adf322c929b0cb6, type: 3}
m_SourcePrefab: {fileID: 100100000, guid: 1053be02c113a7a45adf322c929b0cb6, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 1053be02c113a7a45adf322c929b0cb6, type: 3}
using UnityEngine;
using System.Collections;
using System;
using System.Security.Cryptography;
using System.Text;
/// <summary>
/// AES加密算法
/// </summary>
public class AESEncryption : MonoBehaviour
{
/// <summary>
/// aes加密key
/// </summary>
private static string aesKey = "c20505927997d952";
/// <summary>
/// aes加密偏移量
/// </summary>
private static string aeslv = "e2e7d664d72f710b";
/// <summary>
/// AES加密
/// </summary>
/// <param name="content">被加密的明文</param>
/// <param name="key">密钥</param>
/// <param name="vector">向量</param>
/// <returns>密文</returns>
public static string AESEncrypt(string content)
{
string key = aesKey;
string vector = aeslv;
if (string.IsNullOrEmpty(content)) return null;
byte[] toEncryptArray = Encoding.UTF8.GetBytes(content);
RijndaelManaged rm = new RijndaelManaged
{
Key = Encoding.UTF8.GetBytes(key),
IV = Encoding.UTF8.GetBytes(vector),
Mode = CipherMode.CBC,
Padding = PaddingMode.PKCS7
};
ICryptoTransform cTransform = rm.CreateEncryptor();
byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
return Convert.ToBase64String(resultArray, 0, resultArray.Length);
}
/// <summary>
/// AES解密方法
/// </summary
/// <param name="content">要解密的内容</param>
/// <param name="key">解密key</param>
/// <param name="vector">向量</param>
/// <returns></returns>
public static string AESDecipher(string content)
{
string key = aesKey;
string vector = aeslv;
if (string.IsNullOrEmpty(content)) return null;
byte[] toEncryptArray = Convert.FromBase64String(content);
RijndaelManaged rm = new RijndaelManaged
{
Key = Encoding.UTF8.GetBytes(key),
IV = Encoding.UTF8.GetBytes(vector),
Mode = CipherMode.CBC,
Padding = PaddingMode.PKCS7
};
ICryptoTransform cTransform = rm.CreateDecryptor();
byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
return Encoding.UTF8.GetString(resultArray);
}
}
\ No newline at end of file
fileFormatVersion: 2 fileFormatVersion: 2
guid: 3f3bf7630836b7043bfb3b3328ed8fdc guid: 1617db6d6711f8442a0a168a8c4b909d
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
......
fileFormatVersion: 2 fileFormatVersion: 2
guid: 4402898c05ead0348ae9c35f0ba35328 guid: 08abcf21e7d2d224596f1ce2fd2178d4
PluginImporter: PluginImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
......
...@@ -19,23 +19,8 @@ public class GameConfig : MonoBehaviour ...@@ -19,23 +19,8 @@ public class GameConfig : MonoBehaviour
private void Awake() private void Awake()
{ {
GameConfig._instacne = this; GameConfig._instacne = this;
//是否显示Log
Debug.unityLogger.logEnabled = IsShowLog;
} }
public bool IsShowLog = false;
//private string
......
...@@ -10,7 +10,6 @@ GameObject: ...@@ -10,7 +10,6 @@ GameObject:
m_Component: m_Component:
- component: {fileID: 2853166085728200635} - component: {fileID: 2853166085728200635}
- component: {fileID: 2853166085728200634} - component: {fileID: 2853166085728200634}
- component: {fileID: 5984542369482327738}
- component: {fileID: -2993611056400550530} - component: {fileID: -2993611056400550530}
m_Layer: 0 m_Layer: 0
m_Name: HTTP m_Name: HTTP
...@@ -46,21 +45,10 @@ MonoBehaviour: ...@@ -46,21 +45,10 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
IS_TEST: 1 IS_TEST: 1
pkg: IS_TGYZ: 0
IsShowLog: 1
appLs: appLs:
--- !u!114 &5984542369482327738 appkey: faba1d018f76086
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2853166085728200632}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3f3bf7630836b7043bfb3b3328ed8fdc, type: 3}
m_Name:
m_EditorClassIdentifier:
URL_GAME_HOME_INFO: app/v1/game/xynt/home_info
--- !u!114 &-2993611056400550530 --- !u!114 &-2993611056400550530
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
......
...@@ -11,14 +11,13 @@ using System.Net; ...@@ -11,14 +11,13 @@ using System.Net;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Threading.Tasks; using System.Threading.Tasks;
public delegate void HttpResponse(string result);
public class HttpTool : MonoBehaviour public class HttpTool : MonoBehaviour
{ {
public bool IS_TEST = true; public bool IS_TEST = true;
public bool IS_TGYZ = false; public bool IS_TGYZ = false;
public bool IsShowLog = false;
private string HttpLogTag = "UnityHttp"; private static string HttpLogTag = "UnityHttp";
private static HttpTool _instacne = null; private static HttpTool _instacne = null;
...@@ -44,7 +43,7 @@ public class HttpTool : MonoBehaviour ...@@ -44,7 +43,7 @@ public class HttpTool : MonoBehaviour
{ {
if (_instacne == null) if (_instacne == null)
{ {
Debug.LogError("HTTP Awake error"); Debug.unityLogger.LogError(HttpLogTag, "HTTP Awake error");
} }
return _instacne; return _instacne;
} }
...@@ -52,6 +51,7 @@ public class HttpTool : MonoBehaviour ...@@ -52,6 +51,7 @@ public class HttpTool : MonoBehaviour
void Awake() void Awake()
{ {
Debug.unityLogger.logEnabled = IsShowLog;
if (IS_TEST) if (IS_TEST)
{ {
BaseGameUrl = TEST_BASE_GAEM_URL; BaseGameUrl = TEST_BASE_GAEM_URL;
...@@ -75,122 +75,120 @@ public class HttpTool : MonoBehaviour ...@@ -75,122 +75,120 @@ public class HttpTool : MonoBehaviour
//上报 根据后台提供的url直接请求上报 //上报 根据后台提供的url直接请求上报
public void _GetEvent(string url) public void _GetEvent(string url)
{ {
//Debug.unityLogger.Log(HttpLogTag, "开始上报url" + url);
//HTTPRequest request = new HTTPRequest(new Uri(url), (req, resp) =>
//{
// //Debug.unityLogger.Log(HttpLogTag, "结束上报url" + url);
//});
//request.Timeout = TimeSpan.FromSeconds(timeOut);
//request.Send();
StartCoroutine(GetRequestReport(url));
}
var handler = new HttpClientHandler() public IEnumerator GetRequestReport(string url)
{ {
AutomaticDecompression = DecompressionMethods.GZip using (UnityWebRequest webRequest = UnityWebRequest.Get(url))
};
try
{ {
using (var http = new HttpClient(handler)) //设置header
foreach (var v in requestHeader)
{ {
using (HttpContent content = new StringContent("")) webRequest.SetRequestHeader(v.Key, (string)v.Value);
{ }
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "上报url" + url); webRequest.timeout = timeOut;
var response = http.GetAsync(url).Result; yield return webRequest.SendWebRequest();
}
};
}
catch (Exception ex)
{
Debug.unityLogger.Log("_GetEvent上报错误" + ex.Message);
} }
//if (handler == null)
//{
// handler = new HttpClientHandler()
// {
// AutomaticDecompression = DecompressionMethods.GZip
// };
//}
//if (http == null)
//{
// http = new HttpClient(handler);
//}
//try
//{
// Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "上报url"+ url);
// //var response = http.GetAsync(url).Result;
//}
//catch (Exception ex)
//{
// Debug.unityLogger.Log("_GetEvent上报错误" + ex.Message);
//}
} }
//上报 //上报
public void _PostEvent(string reportJson) public void _PostEvent(string reportJson)
{ {
var handler = new HttpClientHandler()
{
AutomaticDecompression = DecompressionMethods.GZip,
};
try
{
using (var http = new HttpClient(handler))
{
#if UNITY_ANDROID #if UNITY_ANDROID
AndroidJavaClass AESUtils = new AndroidJavaClass("com.unity.adcommon.unity.AESUtils"); AndroidJavaClass AESUtils = new AndroidJavaClass("com.unity.adcommon.unity.AESUtils");
string encryptKey = AESUtils.CallStatic<string>("encrypt", reportJson); string encryptKey = AESUtils.CallStatic<string>("encrypt", reportJson);
#elif UNITY_IOS #elif UNITY_IOS
//IOS 要做加密处理 //IOS 要做加密处理
string encryptKey = reportJson; string encryptKey = AESEncryption.AESEncrypt(reportJson);
#endif #endif
using (HttpContent content = new StringContent(encryptKey, Encoding.UTF8, "application/json")) //Debug.unityLogger.Log(HttpLogTag, "开始上报请求地址" + BaseEventUrl + "?module=behavior");
{ //Debug.unityLogger.Log(HttpLogTag, "开始上报AESUtils" + encryptKey);
//content.Headers.ContentType = new MediaTypeHeaderValue("application/json;charset=UTF-8"); //HTTPRequest request = new HTTPRequest(new System.Uri(BaseEventUrl + "?module=behavior"), HTTPMethods.Post, (req, resp) =>
//foreach (var item in myDictionary) //{
//{ // //Debug.unityLogger.Log(HttpLogTag, "结束上报请求地址" + BaseEventUrl + "?module=behavior");
// content.Headers.Add(item.Key, item.Value); // //Debug.unityLogger.Log(HttpLogTag, "结束上报AESUtils" + encryptKey);
//} //});
var response = http.PostAsync(BaseEventUrl + "?module=behavior", content).Result; //request.RawData= Encoding.UTF8.GetBytes(encryptKey);
} ////request.AddField("FieldName", "Field Value");
}; //request.Send();
}
catch (Exception ex) StartCoroutine(PostRequestReport(encryptKey));
{
//outResStr = ex.Message;
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "_PostEvent事件上报Error" + ex.Message);
}
} }
public void _GetAD<T>(string methodName, Dictionary<string, object> getParas, Action<T> success, Action<string, string> failed) public IEnumerator PostRequestReport(string jsonString)
{ {
string url = BaseEventUrl + "logCollection/log/v1/userLogCollection?module=behavior"+addParams(null);
var handler = new HttpClientHandler() using (UnityWebRequest webRequest = UnityWebRequest.Post (url, ""))
{
AutomaticDecompression = DecompressionMethods.GZip
};
try
{ {
using (var http = new HttpClient(handler)) if (jsonString != null && jsonString.Length > 0)
{ {
using (HttpContent content = new StringContent("")) byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonString);
{
var response = http.GetAsync(BaseAdUrl + methodName + "?" + addParams(getParas)).Result; // postParaStr 注意拼接好 webRequest.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
string rsult = response.Content.ReadAsStringAsync().Result; }
if (response.IsSuccessStatusCode) foreach (var v in requestHeader)
{
RequestResult(rsult, success, failed);
}
else
{
if (failed != null)
{
failed("0", rsult);
}
}
}
};
}
catch (Exception ex)
{
if (failed != null)
{ {
failed("-1", ex.Message); webRequest.SetRequestHeader(v.Key, (string)v.Value);
} }
webRequest.timeout = timeOut;
yield return webRequest.SendWebRequest();
//if (webRequest.isHttpError || webRequest.isNetworkError)
//{
// //Debug.LogError(webRequest.error + "\n" + webRequest.downloadHandler.text);
// //result = webRequest.error;
// Debug.unityLogger.Log(HttpLogTag, "ADReport" + url);
//}
//else
//{
// Debug.unityLogger.Log(HttpLogTag, "ADReport" + url);
// //string json = webRequest.downloadHandler.text;
// Debug.unityLogger.Log("ADReport success" +webRequest.downloadHandler.text);
//}
} }
}
public void _GetAD<T>(string methodName, Dictionary<string, object> getParas, Action<T> success, Action<string, string> failed)
{
StartCoroutine(GetRequest(BaseAdUrl, methodName, getParas, success, failed));
//Debug.unityLogger.Log(HttpLogTag, "开始广告请求地址" + BaseAdUrl + methodName);
//HTTPRequest request = new HTTPRequest(new Uri(BaseAdUrl + methodName + "?" + addParams(getParas)), (req, resp) =>
//{
// Debug.unityLogger.Log(HttpLogTag, "结束广告请求地址" + BaseAdUrl + methodName);
// switch (req.State)
// { // The request finished without any problem.
// case HTTPRequestStates.Finished:
// RequestResult(resp.DataAsText, success, failed);
// break;
// case HTTPRequestStates.Error:
// if (failed != null)
// {
// failed("0", (req.Exception != null ? (req.Exception.Message + "\n" + req.Exception.StackTrace) : "No Exception"));
// }
// break;
// case HTTPRequestStates.Aborted:
// break;
// case HTTPRequestStates.ConnectionTimedOut:
// break;
// case HTTPRequestStates.TimedOut:
// break;
// }
//});
//request.Timeout = TimeSpan.FromSeconds(timeOut);
//request.Send();
} }
public void _Get<T>(string methodName, Dictionary<string, object> getParas, Action<T> success, Action<string, string> failed) public void _Get<T>(string methodName, Dictionary<string, object> getParas, Action<T> success, Action<string, string> failed)
...@@ -214,7 +212,7 @@ public class HttpTool : MonoBehaviour ...@@ -214,7 +212,7 @@ public class HttpTool : MonoBehaviour
yield return webRequest.SendWebRequest(); yield return webRequest.SendWebRequest();
if (webRequest.isHttpError || webRequest.isNetworkError) if (webRequest.isHttpError || webRequest.isNetworkError)
{ {
Debug.LogError(webRequest.error + "\n" + webRequest.downloadHandler.text); //Debug.LogError(webRequest.error + "\n" + webRequest.downloadHandler.text);
//result = webRequest.error; //result = webRequest.error;
if (failed != null) if (failed != null)
{ {
...@@ -319,7 +317,58 @@ public class HttpTool : MonoBehaviour ...@@ -319,7 +317,58 @@ public class HttpTool : MonoBehaviour
//定义 //定义
Dictionary<string, object> paragrams = request; Dictionary<string, object> paragrams = request;
if (IS_TEST)
#if UNITY_IOS
//paragrams.Add("pkg", "com.ym.animalspa");
//paragrams.Add("appLs", appLs);
//paragrams.Add("ts", UserInfoManager.getInstance().GetTimeStamp());
//paragrams.Add("platform", "ios");
//paragrams.Add("source", "AppStore");
//paragrams.Add("module", "behavior");
//paragrams.Add("ua", "Safari");
//paragrams.Add("ntt", "4G");
////paragrams.Add("device", "d0ff4c9b53d1688fc81ce8d730b2989a");
//if (UserInfoManager.getInstance().udid.Length > 0)
//{
// paragrams.Add("device", UserInfoManager.getInstance().udid);
//}
//if (UserInfoManager.getInstance().build.Length > 0)
//{
// paragrams.Add("vc", UserInfoManager.getInstance().build);
//}
//if (UserInfoManager.getInstance().version.Length > 0)
//{
// paragrams.Add("vn", UserInfoManager.getInstance().version);
//}
//if (UserInfoManager.getInstance().idfa.Length > 0)
//{
// paragrams.Add("idfa", UserInfoManager.getInstance().idfa);
//}
//if (UserInfoManager.getInstance().token.Length > 0)
//{
// paragrams.Add("token", UserInfoManager.getInstance().token);
//}
//if (UserInfoManager.getInstance().uid > 0)
//{
// paragrams.Add("uid", UserInfoManager.getInstance().uid + "");
//}
//if (IS_TGYZ)
//{
// paragrams["zygt"] = "hzwz";
// paragrams["tgtk"] = "1";
//}
//string signString = signParamsWithDict(paragrams);
//paragrams.Add("sign", signString);
#elif UNITY_ANDROID
if (IS_TGYZ)
{ {
paragrams.Add("zygt", "hzwz"); paragrams.Add("zygt", "hzwz");
paragrams.Add("tgtk", "1"); paragrams.Add("tgtk", "1");
...@@ -376,6 +425,13 @@ public class HttpTool : MonoBehaviour ...@@ -376,6 +425,13 @@ public class HttpTool : MonoBehaviour
#endif #endif
string signString = signParamsWithDict(paragrams); string signString = signParamsWithDict(paragrams);
paragrams.Add("sign", signString); paragrams.Add("sign", signString);
#endif
foreach (KeyValuePair<string, object> item in paragrams) foreach (KeyValuePair<string, object> item in paragrams)
{ {
// && !string.IsNullOrEmpty(item.Value) // && !string.IsNullOrEmpty(item.Value)
...@@ -442,9 +498,10 @@ public class HttpTool : MonoBehaviour ...@@ -442,9 +498,10 @@ public class HttpTool : MonoBehaviour
string meid = ""; string meid = "";
private string GetDeviceIMEI() private string GetDeviceIMEI()
{ {
#if UNITY_ANDROID
try try
{ {
var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
var context = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"); var context = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
var telephoneyManager = context.Call<AndroidJavaObject>("getSystemService", "phone"); var telephoneyManager = context.Call<AndroidJavaObject>("getSystemService", "phone");
...@@ -452,14 +509,17 @@ public class HttpTool : MonoBehaviour ...@@ -452,14 +509,17 @@ public class HttpTool : MonoBehaviour
//imei1 = telephoneyManager.Call<string>("getImei", 1); //imei1 = telephoneyManager.Call<string>("getImei", 1);
//meid = telephoneyManager.Call<string>("getMeid");//电信的手机 是MEID //meid = telephoneyManager.Call<string>("getMeid");//电信的手机 是MEID
return imei0; return imei0;
//texts[18].text = "IMEI1:" + imei1;
//texts[19].text = "MEID:" + meid; //texts[18].text = "IMEI1:" + imei1;
} //texts[19].text = "MEID:" + meid;
}
catch (Exception e) catch (Exception e)
{ {
return ""; return "";
} }
#else
return "";
#endif
} }
#endregion #endregion
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NetConfig : MonoBehaviour
{
private static NetConfig _instacne = null;
public static NetConfig Instance
{
get
{
if (_instacne == null)
{
Debug.LogError("NetConfig Awake error");
}
return _instacne;
}
}
private void Awake()
{
NetConfig._instacne = this;
}
public string URL_GAME_HOME_INFO = "app/v1/game/xynt/home_info";
}
...@@ -270,7 +270,7 @@ PlayerSettings: ...@@ -270,7 +270,7 @@ PlayerSettings:
AndroidEnableTango: 0 AndroidEnableTango: 0
androidEnableBanner: 1 androidEnableBanner: 1
androidUseLowAccuracyLocation: 0 androidUseLowAccuracyLocation: 0
androidUseCustomKeystore: 0 androidUseCustomKeystore: 1
m_AndroidBanners: m_AndroidBanners:
- width: 320 - width: 320
height: 180 height: 180
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment