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;
using UnityEngine;
using System;
using Tencent.GDT;
using System.Runtime.InteropServices;
public class AdManager
{
......@@ -40,7 +41,8 @@ public class AdManager
return activity;
}
[DllImport("__Internal")]
public static extern void InitCSJSDK(string appId); // ios初始化穿山甲SDK
private bool IsInitAd = false;
......@@ -55,16 +57,20 @@ public class AdManager
//paras.Clear();
//paras.Add("pkg", "com.ym.xynt");
//获取广告配置
Dictionary<string, object> paras = new Dictionary<string, object>();
HttpTool.Instance._GetAD(AdConfigUrl, paras, new Action<List<AdIdConfig>>((AdConfigList) =>
HttpTool.Instance._GetAD(AdConfigUrl, null, new Action<List<AdIdConfig>>((AdConfigList) =>
{
foreach (AdIdConfig id in AdConfigList)
{
switch (id.adPlatform)
{
//初始化穿山甲广告ID
case ZXADConfig.PLANTFORM_AD_TT:
#if UNITY_ANDROID
AndroidJavaClass jc = new AndroidJavaClass("com.unity.adcommon.unity.TTADManager");
jc.CallStatic("init", id.codeAppId);
#elif UNITY_IOS
InitCSJSDK(id.codeAppId);
#endif
break;
case ZXADConfig.PLANTFORM_AD_GDT:
if (id.codeAppId != null && id.codeAppId != "")
......@@ -170,8 +176,14 @@ public class AdManager
switch (entity.adPlatform)
{
case ZXADConfig.PLANTFORM_AD_TT:
//加载穿山甲开屏广告
#if UNITY_ANDROID
//加载穿山甲开屏广告
CSJSplshADUtils.Instance.LoadSplshAd(entity, GetActivity(), GetSplashAdManager(), listener, callback);
#elif UNITY_IOS
//加载穿山甲开屏广告
CSJSplshADUtils.Instance.LoadSplshAd(entity,null, null, listener, callback);
#endif
break;
case ZXADConfig.PLANTFORM_AD_GDT:
//广点通开屏广告
......@@ -275,9 +287,9 @@ public class AdManager
public void ShowCacheBannerAd(string slotName,string actionName)
{
AdEntity entity = ZXADConfig.Instance.GetAdCache(slotName, "");
entity.actionName = actionName;
if (entity != null)
{
entity.actionName = actionName;
ZXADConfig.Instance.RemoveAdCache(slotName, "");
mShowCacheBannerAdPlatform(entity, new Action<bool>((bl) =>
{
......@@ -293,6 +305,7 @@ public class AdManager
}
else
{
LoadCacheBannerAd(slotName);
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "展示Banner失败 缓存的信息为null");
}
}
......@@ -350,7 +363,7 @@ public class AdManager
/// <summary>
/// 根据广告List开始加载插屏缓存
/// 根据广告List开始加载大图缓存
/// </summary>
private Action<bool> FeedAdCallBack;
private void mLoadFeedCacheAd(string sloatName, List<AdEntity> adList)
......@@ -409,9 +422,9 @@ public class AdManager
public void ShowCacheFeedAd(string slotName,string actionName)
{
AdEntity entity = ZXADConfig.Instance.GetAdCache(slotName, "");
entity.actionName = actionName;
if (entity != null)
{
entity.actionName = actionName;
ZXADConfig.Instance.RemoveAdCache(slotName, "");
mShowCacheFeedAdPlatform(entity, new Action<bool>((bl) =>
{
......@@ -427,6 +440,7 @@ public class AdManager
}
else
{
LoadCacheFeedAd(slotName);
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "展示大图失败 缓存的信息为null");
}
}
......@@ -543,25 +557,26 @@ public class AdManager
public void PlayCacheInterstitialAd(string slotName,string actionName)
{
AdEntity entity = ZXADConfig.Instance.GetAdCache(slotName,"");
entity.actionName = actionName;
if (entity != null)
{
entity.actionName = actionName;
ZXADConfig.Instance.RemoveAdCache(slotName, "");
mPlayCacheInterstitialAdPlatform(entity, new Action<bool>((bl) =>
{
if (bl)
{
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "播放屏视频成功 " + entity.adPlatform + " CodeId" + entity.codeId);
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "播放屏视频成功 " + entity.adPlatform + " CodeId" + entity.codeId);
}
else
{
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "播放屏视频失败 " + entity.adPlatform + " CodeId" + entity.codeId);
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "播放屏视频失败 " + entity.adPlatform + " CodeId" + entity.codeId);
}
}));
}
else
{
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "播放全屏视频失败 缓存的信息为null");
LoadCacheInterstitialAd(slotName);
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "播放插屏视频失败 缓存的信息为null");
}
}
......@@ -789,9 +804,9 @@ public class AdManager
entity = entityB;
ZXADConfig.Instance.RemoveAdCache(slotName, "B");
}
entity.actionName = actionName;
if (entity != null)
{
entity.actionName = actionName;
mPlayCacheFSVodeoAdPlatform(entity, listener, new Action<bool>((bl) =>
{
if (bl)
......@@ -806,6 +821,8 @@ public class AdManager
}
else
{
LoadCacheFSVideoAd(slotName);
listener.onError("播放全屏视频失败 缓存的信息为null");
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "播放全屏视频失败 缓存的信息为null");
}
}
......@@ -897,14 +914,12 @@ public class AdManager
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "激励视频A组没有数据");
return;
}
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "正序的第一个广告ID" + adList[0].codeId);
if (IsFirstLoadRewardAd)
{
//第一次预加载 A组进行逆序加载
IsFirstLoadRewardAd = false;
adList.Reverse();
}
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "反序的第一个广告ID" + adList[0].codeId);
List<AdEntity> totalEntityList = adList;
AdEntity entity = totalEntityList[0];
......@@ -1046,9 +1061,9 @@ public class AdManager
ZXADConfig.Instance.RemoveAdCache(slotName, "B");
}
entity.actionName = actionName;
if (entity != null)
{
entity.actionName = actionName;
mPlayCacheRewardVodeoAdPlatform(entity, listener, new Action<bool>((bl) =>
{
......@@ -1059,14 +1074,15 @@ public class AdManager
else
{
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, entity.codeGroup + "播放激励视频失败 " + entity.adPlatform + " CodeId" + entity.codeId);
//listener.onError(entity.codeGroup + "播放激励视频失败 " + entity.adPlatform + " CodeId" + entity.codeId);
}
}));
}
else
{
LoadCacheRewardVideoAd(slotName);
listener.onError("播放激励视频失败 缓存的信息为null");
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "播放激励视频失败 缓存的信息为null");
}
}
......
......@@ -135,21 +135,25 @@ public class CSJBannerUtil
public void OnExpressAdLoad(List<ExpressAd> ads)
{
#if UNITY_ANDROID
EventUtils.onEventPullSuccess(entity);
IEnumerator<ExpressAd> enumerator = ads.GetEnumerator();
if (enumerator.MoveNext())
{
callback(true);
bannerAdCacheListAndroid.Enqueue(enumerator.Current);
callback(true);
}
#endif
}
#if UNITY_IOS
public void OnExpressBannerAdLoad(ExpressBannerAd ad)
{
EventUtils.onEventPullSuccess(entity);
callback(true);
Debug.Log("OnExpressBannerAdLoad");
bannerAdCacheListIOS.Enqueue(ad);
bannerAdCacheListIOS.Enqueue(ad);
callback(true);
}
public void OnExpressInterstitialAdLoad(ExpressInterstitialAd ad)
......@@ -186,16 +190,17 @@ public class CSJBannerUtil
public void OnAdShow(ExpressAd ad)
{
Debug.Log("express OnAdShow,type:" + type);
EventUtils.onEventShowSuccess(entity);
callback(true);
Debug.Log("express OnAdShow,type:" + type);
}
public void OnAdViewRenderError(ExpressAd ad, int code, string message)
{
Debug.Log("express OnAdViewRenderError,type:" + type);
EventUtils.onEventShowFail(entity);
callback(false);
Debug.Log("express OnAdViewRenderError,type:" + type);
}
public void OnAdViewRenderSucc(ExpressAd ad, float width, float height)
......
......@@ -125,8 +125,8 @@ public class CSJFeedUtil : MonoBehaviour
IEnumerator<ExpressAd> enumerator = ads.GetEnumerator();
if (enumerator.MoveNext())
{
callback(true);
feedAdCacheList.Enqueue(enumerator.Current);
callback(true);
}
}
#if UNITY_IOS
......@@ -168,16 +168,18 @@ public class CSJFeedUtil : MonoBehaviour
public void OnAdShow(ExpressAd ad)
{
Debug.Log("express OnAdShow,type:" + type);
EventUtils.onEventShowSuccess(entity);
callback(true);
Debug.Log("express OnAdShow,type:" + type);
}
public void OnAdViewRenderError(ExpressAd ad, int code, string message)
{
Debug.Log("express OnAdViewRenderError,type:" + type);
EventUtils.onEventShowFail(entity);
callback(false);
Debug.Log("express OnAdViewRenderError,type:" + type);
}
public void OnAdViewRenderSucc(ExpressAd ad, float width, float height)
......@@ -186,8 +188,9 @@ public class CSJFeedUtil : MonoBehaviour
}
public void OnAdClose(ExpressAd ad)
{
EventUtils.onEventAdComplete(entity);
Debug.Log("express OnAdClose,type:" + type);
EventUtils.onEventAdComplete(entity);
}
}
......
......@@ -59,7 +59,7 @@ public class CSJFullScreenUtil : MonoBehaviour
.SetOrientation(AdOrientation.Horizontal)
.Build();
#if UNITY_IOS
this.AdNative.LoadExpressFullScreenVideoAd(adSlot, new FullScreenVideoAdListener(this, callback));
this.AdNative.LoadExpressFullScreenVideoAd(adSlot, new FullScreenVideoAdListener(this,entity, callback));
#else
this.AdNative.LoadFullScreenVideoAd(adSlot, new FullScreenVideoAdListener(this, entity, callback));
#endif
......@@ -71,7 +71,7 @@ public class CSJFullScreenUtil : MonoBehaviour
ExpressFullScreenVideoAd fsAd = GetFSVideoAdForIOS(entity.codeGroup+entity.codeId);
if (fsAd!=null)
{
fsAd.SetFullScreenVideoAdInteractionListener(new FullScreenAdInteractionListener(listener, callback));
fsAd.SetFullScreenVideoAdInteractionListener(new FullScreenAdInteractionListener(entity,listener, callback));
fsAd.ShowFullScreenVideoAd();
}
else
......@@ -163,8 +163,8 @@ public class CSJFullScreenUtil : MonoBehaviour
public void OnAdShow()
{
EventUtils.onEventShowSuccess(entity);
callback(true);
listener.onAdShow();
callback(true);
}
public void OnAdVideoBarClick()
......@@ -187,8 +187,9 @@ public class CSJFullScreenUtil : MonoBehaviour
public void OnVideoError()
{
EventUtils.onEventShowFail(entity);
callback(false);
listener.onError("CSJ 全屏视频播放错误");
callback(false);
}
}
......
......@@ -105,8 +105,9 @@ public class CSJInterstitialUtil
}
else
{
callback(false);
Debug.Log("CSJ 插屏广告没有缓存数据了");
callback(false);
}
#endif
}
......@@ -130,13 +131,20 @@ public class CSJInterstitialUtil
public void OnExpressAdLoad(List<ExpressAd> ads)
{
#if UNITY_ANDROID
EventUtils.onEventPullSuccess(entity);
IEnumerator<ExpressAd> enumerator = ads.GetEnumerator();
if (enumerator.MoveNext())
{
callback(true);
interstitialAdCacheListAndroid.Enqueue(enumerator.Current);
callback(true);
}
#endif
}
#if UNITY_IOS
public void OnExpressBannerAdLoad(ExpressBannerAd ad)
......@@ -147,8 +155,9 @@ public class CSJInterstitialUtil
public void OnExpressInterstitialAdLoad(ExpressInterstitialAd ad)
{
EventUtils.onEventPullSuccess(entity);
callback(true);
interstitialAdCacheListIOS.Enqueue(ad);
callback(true);
}
#else
#endif
......
......@@ -121,9 +121,9 @@ public class CSJRewardUtil
public void OnError(int code, string message)
{
EventUtils.onEventPullFail(entity, code.ToString(),message);
callback(false);
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, entity.adPlatform + " 激励视频 Error Group" + entity.codeGroup + " Code " + code + " msg" + message);
}
callback(false);
}
public void OnRewardVideoAdLoad(RewardVideoAd ad)
{
......@@ -181,9 +181,10 @@ public class CSJRewardUtil
{
EventUtils.onEventShowSuccess(entity);
Debug.Log("rewardVideoAd show");
listener.onAdShow();
callback(true);
//this.cjsAd.rewardAd = null;
listener.onAdShow();
}
public void OnAdVideoBarClick()
......@@ -214,8 +215,9 @@ public class CSJRewardUtil
{
EventUtils.onEventShowFail(entity);
Debug.Log("rewardVideoAd error");
callback(false);
listener.onError("CSJ RewardAd Error");
callback(false);
}
public void OnRewardVerify(bool rewardVerify, int rewardAmount, string rewardName)
......
......@@ -39,12 +39,12 @@ public class AdDemo : MonoBehaviour
public void onAdClose()
{
this.demo.RewardAdResult.text = "Reward onAdClose";
//AdManager.Instance.LoadCacheRewardVideoAd("video");
}
public void onAdShow()
{
this.demo.RewardAdResult.text = "Reward onAdShow";
AdManager.Instance.LoadCacheRewardVideoAd("video");
}
public void onAdVideoBarClick()
......
......@@ -59,12 +59,12 @@ public class Splash : MonoBehaviour
public void onAdSkip()
{
SceneManager.LoadScene("AdDemo");
SceneManager.LoadSceneAsync("AdDemo");
}
public void onError(string errorMsg)
{
SceneManager.LoadScene("AdDemo");
SceneManager.LoadSceneAsync("AdDemo");
}
}
......
......@@ -528,5 +528,6 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedComponents:
- {fileID: 5984542369482327738, 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
guid: 3f3bf7630836b7043bfb3b3328ed8fdc
guid: 1617db6d6711f8442a0a168a8c4b909d
MonoImporter:
externalObjects: {}
serializedVersion: 2
......
fileFormatVersion: 2
guid: 4402898c05ead0348ae9c35f0ba35328
guid: 08abcf21e7d2d224596f1ce2fd2178d4
PluginImporter:
externalObjects: {}
serializedVersion: 2
......
......@@ -19,23 +19,8 @@ public class GameConfig : MonoBehaviour
private void Awake()
{
GameConfig._instacne = this;
//是否显示Log
Debug.unityLogger.logEnabled = IsShowLog;
}
public bool IsShowLog = false;
//private string
......
......@@ -10,7 +10,6 @@ GameObject:
m_Component:
- component: {fileID: 2853166085728200635}
- component: {fileID: 2853166085728200634}
- component: {fileID: 5984542369482327738}
- component: {fileID: -2993611056400550530}
m_Layer: 0
m_Name: HTTP
......@@ -46,21 +45,10 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
IS_TEST: 1
pkg:
IS_TGYZ: 0
IsShowLog: 1
appLs:
--- !u!114 &5984542369482327738
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
appkey: faba1d018f76086
--- !u!114 &-2993611056400550530
MonoBehaviour:
m_ObjectHideFlags: 0
......
......@@ -11,14 +11,13 @@ using System.Net;
using System.Net.Http.Headers;
using System.Threading.Tasks;
public delegate void HttpResponse(string result);
public class HttpTool : MonoBehaviour
{
public bool IS_TEST = true;
public bool IS_TGYZ = false;
private string HttpLogTag = "UnityHttp";
public bool IsShowLog = false;
private static string HttpLogTag = "UnityHttp";
private static HttpTool _instacne = null;
......@@ -44,7 +43,7 @@ public class HttpTool : MonoBehaviour
{
if (_instacne == null)
{
Debug.LogError("HTTP Awake error");
Debug.unityLogger.LogError(HttpLogTag, "HTTP Awake error");
}
return _instacne;
}
......@@ -52,6 +51,7 @@ public class HttpTool : MonoBehaviour
void Awake()
{
Debug.unityLogger.logEnabled = IsShowLog;
if (IS_TEST)
{
BaseGameUrl = TEST_BASE_GAEM_URL;
......@@ -75,122 +75,120 @@ public class HttpTool : MonoBehaviour
//上报 根据后台提供的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()
{
AutomaticDecompression = DecompressionMethods.GZip
};
try
public IEnumerator GetRequestReport(string url)
{
using (UnityWebRequest webRequest = UnityWebRequest.Get(url))
{
using (var http = new HttpClient(handler))
//设置header
foreach (var v in requestHeader)
{
using (HttpContent content = new StringContent(""))
{
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "上报url" + url);
var response = http.GetAsync(url).Result;
}
};
}
catch (Exception ex)
{
Debug.unityLogger.Log("_GetEvent上报错误" + ex.Message);
webRequest.SetRequestHeader(v.Key, (string)v.Value);
}
webRequest.timeout = timeOut;
yield return webRequest.SendWebRequest();
}
//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)
{
var handler = new HttpClientHandler()
{
AutomaticDecompression = DecompressionMethods.GZip,
};
try
{
using (var http = new HttpClient(handler))
{
#if UNITY_ANDROID
AndroidJavaClass AESUtils = new AndroidJavaClass("com.unity.adcommon.unity.AESUtils");
string encryptKey = AESUtils.CallStatic<string>("encrypt", reportJson);
AndroidJavaClass AESUtils = new AndroidJavaClass("com.unity.adcommon.unity.AESUtils");
string encryptKey = AESUtils.CallStatic<string>("encrypt", reportJson);
#elif UNITY_IOS
//IOS 要做加密处理
string encryptKey = reportJson;
//IOS 要做加密处理
string encryptKey = AESEncryption.AESEncrypt(reportJson);
#endif
using (HttpContent content = new StringContent(encryptKey, Encoding.UTF8, "application/json"))
{
//content.Headers.ContentType = new MediaTypeHeaderValue("application/json;charset=UTF-8");
//foreach (var item in myDictionary)
//{
// content.Headers.Add(item.Key, item.Value);
//}
var response = http.PostAsync(BaseEventUrl + "?module=behavior", content).Result;
}
};
}
catch (Exception ex)
{
//outResStr = ex.Message;
Debug.unityLogger.Log(ZXADConfig.ADManagerTAG, "_PostEvent事件上报Error" + ex.Message);
}
//Debug.unityLogger.Log(HttpLogTag, "开始上报请求地址" + BaseEventUrl + "?module=behavior");
//Debug.unityLogger.Log(HttpLogTag, "开始上报AESUtils" + encryptKey);
//HTTPRequest request = new HTTPRequest(new System.Uri(BaseEventUrl + "?module=behavior"), HTTPMethods.Post, (req, resp) =>
//{
// //Debug.unityLogger.Log(HttpLogTag, "结束上报请求地址" + BaseEventUrl + "?module=behavior");
// //Debug.unityLogger.Log(HttpLogTag, "结束上报AESUtils" + encryptKey);
//});
//request.RawData= Encoding.UTF8.GetBytes(encryptKey);
////request.AddField("FieldName", "Field Value");
//request.Send();
StartCoroutine(PostRequestReport(encryptKey));
}
public void _GetAD<T>(string methodName, Dictionary<string, object> getParas, Action<T> success, Action<string, string> failed)
public IEnumerator PostRequestReport(string jsonString)
{
var handler = new HttpClientHandler()
{
AutomaticDecompression = DecompressionMethods.GZip
};
try
string url = BaseEventUrl + "logCollection/log/v1/userLogCollection?module=behavior"+addParams(null);
using (UnityWebRequest webRequest = UnityWebRequest.Post (url, ""))
{
using (var http = new HttpClient(handler))
if (jsonString != null && jsonString.Length > 0)
{
using (HttpContent content = new StringContent(""))
{
var response = http.GetAsync(BaseAdUrl + methodName + "?" + addParams(getParas)).Result; // postParaStr 注意拼接好
string rsult = response.Content.ReadAsStringAsync().Result;
if (response.IsSuccessStatusCode)
{
RequestResult(rsult, success, failed);
}
else
{
if (failed != null)
{
failed("0", rsult);
}
}
}
};
}
catch (Exception ex)
{
if (failed != null)
byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonString);
webRequest.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
}
foreach (var v in requestHeader)
{
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)
......@@ -214,7 +212,7 @@ public class HttpTool : MonoBehaviour
yield return webRequest.SendWebRequest();
if (webRequest.isHttpError || webRequest.isNetworkError)
{
Debug.LogError(webRequest.error + "\n" + webRequest.downloadHandler.text);
//Debug.LogError(webRequest.error + "\n" + webRequest.downloadHandler.text);
//result = webRequest.error;
if (failed != null)
{
......@@ -319,7 +317,58 @@ public class HttpTool : MonoBehaviour
//定义
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("tgtk", "1");
......@@ -376,6 +425,13 @@ public class HttpTool : MonoBehaviour
#endif
string signString = signParamsWithDict(paragrams);
paragrams.Add("sign", signString);
#endif
foreach (KeyValuePair<string, object> item in paragrams)
{
// && !string.IsNullOrEmpty(item.Value)
......@@ -442,9 +498,10 @@ public class HttpTool : MonoBehaviour
string meid = "";
private string GetDeviceIMEI()
{
#if UNITY_ANDROID
try
{
var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
var context = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
var telephoneyManager = context.Call<AndroidJavaObject>("getSystemService", "phone");
......@@ -452,14 +509,17 @@ public class HttpTool : MonoBehaviour
//imei1 = telephoneyManager.Call<string>("getImei", 1);
//meid = telephoneyManager.Call<string>("getMeid");//电信的手机 是MEID
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)
{
return "";
}
#else
return "";
#endif
}
#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:
AndroidEnableTango: 0
androidEnableBanner: 1
androidUseLowAccuracyLocation: 0
androidUseCustomKeystore: 0
androidUseCustomKeystore: 1
m_AndroidBanners:
- width: 320
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