938 lines
28 KiB
C#
938 lines
28 KiB
C#
// ***********************************************************************
|
||
// Assembly : Game
|
||
// Author : Kimch
|
||
// Created : 2021-05-02
|
||
// Description :
|
||
// Last Modified By :
|
||
// Last Modified On :
|
||
// ***********************************************************************
|
||
// <copyright file= "KPlatform.OhayooPlatform" company="Kunpo"></copyright>
|
||
// <summary></summary>
|
||
// ***********************************************************************
|
||
#if SDK_OHAYOO
|
||
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using ByteDance.Union;
|
||
using UnityEngine;
|
||
|
||
namespace G
|
||
{
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
partial class KPlatform
|
||
{
|
||
/// <summary>
|
||
/// 平台实现
|
||
/// </summary>
|
||
public class OhayooPlatform : MonoBehaviour, IPlatformWapper
|
||
{
|
||
#region 初始化
|
||
|
||
private void Start()
|
||
{
|
||
this.Init();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 游戏SDK初始化,仅Android端
|
||
/// Init for Android client ios.
|
||
/// </summary>
|
||
public void Init()
|
||
{
|
||
// 打印当前sdk版本号
|
||
Log.D("CurrentSdkVersion : " + LGSDKCore.SDK_VERSION);
|
||
#if UNITY_IOS
|
||
//在初始化之前绑定AbTest 回调
|
||
LGAppLogService.Instance.iOS_SetAbTestFinishCallBack((abTestEnabled, allConfig) =>
|
||
{
|
||
var allConfigJson = Json.Serialize(allConfig);
|
||
Log.D($"allConfigJson --- {allConfigJson}");
|
||
Log.D($"iOSAbTestFinishCallBack--- abTestEnable : {abTestEnabled} \n allConfig : {allConfig}");
|
||
Debug.Log("AbConfig:" + LGSDKCore.AppLogService.GetAbConfig("key", "defaultValue"));
|
||
});
|
||
|
||
/* 设置 push 回调 */
|
||
//LGPushService.Instance.iOS_InitWithCallback(body =>
|
||
//{
|
||
// var pushId = LGPushService.Instance.Ios_GetPushIdentifier();
|
||
// var pushStatus = LGPushService.Instance.Ios_GetSystemPushStatus();
|
||
// Log.D($"iOSPushInitSuccess---info:{body.notificationInfo} \n pushId: {pushId} \n pushStatus:{pushStatus} \n pushType:{body.pushType}");
|
||
//});
|
||
#endif
|
||
|
||
#if UNITY_ANDROID
|
||
// 注册 Android push 回调
|
||
//LGSDKPush.PushService.Android_InitPushCallback(
|
||
// delegate(NotifyClickCallbackEntity entity)
|
||
// {
|
||
// // 通知消息点击回调
|
||
// var sumMsg = "LG_Push-onNotificationClick : " + "from = " + entity.from + "--title = " + entity.title
|
||
// + "--text = " + entity.text + "--imgUrl = " + entity.imgUrl + "--uri = " + entity.openUrl.ToString()
|
||
// + " --msgId = " + entity.msgId;
|
||
// Log.D(sumMsg);
|
||
// ToastManager.Instance.ShowToast(sumMsg);
|
||
// LGSDKPush.PushService.Android_StartLaunchActivity();
|
||
// },
|
||
// delegate(PushArriveCallbackEntity entity)
|
||
// {
|
||
// // 透传消息到达监听,只有透传消息能回调到此方法
|
||
// var sumMsg = "LG_Push-PushMessageArriveCallback : " + "from = " + entity.from + "--title = " + entity.title
|
||
// + "--text = " + entity.text + "--imgUrl = " + entity.imgUrl + "--openUrl = " + entity.openUrl
|
||
// + "--msgId = " + entity.msgId;
|
||
// Log.D(sumMsg);
|
||
// ToastManager.Instance.ShowToast(sumMsg);
|
||
// });
|
||
|
||
//LGSDKDevKit.DevKitBaseService.Android_RegisterDeepLinkInnerCallBack(delegate(string message)
|
||
//{
|
||
// var tips = "收到H5消息" + message;
|
||
// Log.D(tips);
|
||
// ToastManager.Instance.ShowToast(tips);
|
||
//});
|
||
//在初始化之前绑定AbTest 回调
|
||
LGAppLogService.Instance.Android_registerAbConfigGetListener((bool changed, string abConfig) =>
|
||
{
|
||
Log.D($"abConfig --- {abConfig}");
|
||
Log.D($"AndroidAbTestFinishCallBack--- changed : {changed} \n abConfig : {abConfig}");
|
||
Debug.Log("AbConfig:" + LGSDKCore.AppLogService.GetAbConfig("key", "defaultValue"));
|
||
});
|
||
#endif
|
||
|
||
LGAbsRealName.GlobalRealNameFailCallback = delegate (int error, string errMsg)
|
||
{
|
||
// 认证失败 返回错误信息
|
||
var resultErrMsg = "RealNameVerified OnFail:" + error + ",errMsg:" + errMsg;
|
||
Debug.Log(resultErrMsg);
|
||
//ToastManager.Instance.ShowToast(resultErrMsg);
|
||
};
|
||
|
||
LGAbsRealName.GlobalRealNameSuccessCallback = delegate (bool isAdult)
|
||
{
|
||
// 认证成功 返回用户是否成年
|
||
var msg = "RealNameVerified onSuc isAdult:" + isAdult;
|
||
Debug.Log(msg);
|
||
//ToastManager.Instance.ShowToast(msg);
|
||
};
|
||
|
||
// 全局防沉迷回调
|
||
LGAbsRealName.GlobalAntiAddictionCallback = delegate (LGAntiAddictionResult result)
|
||
{
|
||
var msg = $"TriggerAntiAddiction 是否已经自动弹窗:{result.AutoPopup}" +
|
||
$"-- CanPlayTime : {result.CanPlayTime}";
|
||
//Log.D(msg);
|
||
//ToastManager.Instance.ShowToast(msg);
|
||
|
||
if (result.AutoPopup)
|
||
{
|
||
//Debug.Log("防沉迷弹窗已自动弹出,游戏可关闭应用");
|
||
ArchiveProxy.Instance.Save();
|
||
Application.Quit();
|
||
}
|
||
};
|
||
|
||
LGAbsAccount.GlobalLoginSuccessCallback = delegate (LGUser user, LGLoginInvokeMode mode)
|
||
{
|
||
Debug.Log("OHAYOO 登录成功-");
|
||
//ToastManager.Instance.ShowToast("登录成功---openID:" + user.OpenID + "---token:" + user.Token);
|
||
//LiteDataUtil.SetOpenId(user.OpenID);
|
||
Kunpo.Privacy.PrivacyProxy.LoginUser = user;
|
||
KPlatform.Instance.OnLoginSuccess(user.OpenID, user.Token, (int)user.LoginType, (int)mode);
|
||
};
|
||
|
||
LGAbsAccount.GlobalLoginFailCallback = delegate (int code, string msg, LGLoginInvokeMode mode)
|
||
{
|
||
Debug.Log("OHAYOO 登录失败---code:" + code + "---msg:" + msg + "loginMode:" + mode);
|
||
//ToastManager.Instance.ShowToast("登录失败---code:" + code + "---msg:" + msg + "loginMode:" + mode);
|
||
KPlatform.Instance.OnLoginFailure(code, msg, (int)mode);
|
||
};
|
||
|
||
LGAbsAccount.GlobalLoginBoxPopCallback = delegate ()
|
||
{
|
||
Log.D("登录弹窗展示---");
|
||
//ToastManager.Instance.ShowToast("登录弹窗展示---");
|
||
};
|
||
|
||
//回调绑定后,启动初始化方法
|
||
LGSDKCore.Init(lgInitSuccessInfo =>
|
||
{
|
||
Log.D("deviceID = " + lgInitSuccessInfo.DeviceID + "--installID = " + lgInitSuccessInfo.InstallID +
|
||
"--ssID = " + lgInitSuccessInfo.SsID + "--userUniqueID=" +
|
||
lgInitSuccessInfo.UserUniqueID);
|
||
//ToastManager.Instance.ShowToast("InitSuccess");
|
||
KPlatform.Instance.deviceId = lgInitSuccessInfo.DeviceID;
|
||
KPlatform.Instance.OnInitSuccess();
|
||
#if UNITY_IOS
|
||
RequireIDFA();
|
||
#endif
|
||
}, (errorCode, errorMessage) =>
|
||
{
|
||
var toastMsg = $"Init Fail errCode = {errorCode}, errMessage = {errorMessage}";
|
||
Log.D(toastMsg);
|
||
//ToastManager.Instance.ShowToast(toastMsg);
|
||
});
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 登录
|
||
|
||
/// <summary>
|
||
/// 正式用户调用登录接口.
|
||
/// </summary>
|
||
public void NormalLogin()
|
||
{
|
||
LGSDKAccount.AccountService.NormalLogin();
|
||
}
|
||
/// <summary>
|
||
/// 帐号切换.
|
||
/// </summary>
|
||
public void SwitchAccount()
|
||
{
|
||
LGSDKAccount.AccountService.SwitchAccount();
|
||
}
|
||
/// <summary>
|
||
/// 游客帐号绑定.
|
||
/// </summary>
|
||
public void VisitorBindAccount()
|
||
{
|
||
LGSDKAccount.AccountService.VisitorBindAccount();
|
||
}
|
||
/// <summary>
|
||
/// 是否为游客登录.
|
||
/// </summary>
|
||
/// <returns>是否为游客登录.</returns>
|
||
public bool IsVisitor()
|
||
{
|
||
return LGSDKAccount.AccountService.IsVisitor();
|
||
}
|
||
|
||
public void ClearToken()
|
||
{
|
||
#if UNITY_IOS
|
||
LGSDKAccount.AccountService.ClearToken();
|
||
#endif
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public void Logoff(System.Action<string> onSuccess, System.Action<int, string> onFail)
|
||
{
|
||
LGSDKAccount.AccountService.CloseAccount(onSuccess, onFail);
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 广告
|
||
|
||
public static class AndroidAdPositionId
|
||
{
|
||
public const string REWARD_VIDEO_HORIZONTAL_CODE = "946083313";
|
||
public const string REWARD_VIDEO_VERTICAL_CODE = "946083313";// "945930137";//"945722683";//"945651085";//已修改
|
||
}
|
||
|
||
public static class IosAdPositionId
|
||
{
|
||
public const string REWARD_VIDEO_HORIZONTAL_CODE = "946385677";//"945897453";
|
||
public const string REWARD_VIDEO_VERTICAL_CODE = "946385677";//"946371133";//"945978056";//"945897453";
|
||
}
|
||
|
||
string _reward_video_vertical_code;
|
||
public void LoadRewardVideoAd_V()
|
||
{
|
||
if (string.IsNullOrEmpty(_reward_video_vertical_code))
|
||
{
|
||
_reward_video_vertical_code = AndroidAdPositionId.REWARD_VIDEO_VERTICAL_CODE;
|
||
#if UNITY_ANDROID
|
||
var appId = Application.identifier;
|
||
switch (appId)
|
||
{
|
||
case "com.kunpo.litaibai.android.ohayoo.vapp"://vapp
|
||
_reward_video_vertical_code = "946162814";
|
||
break;
|
||
case "com.kunpo.litaibai.android.ssjj"://4399
|
||
_reward_video_vertical_code = "946510685";
|
||
break;
|
||
case "com.kunpo.litaibai.android.qqers"://7233
|
||
case "com.kunpo.litaibai.android.cczs"://cczs
|
||
_reward_video_vertical_code = "946510675";
|
||
break;
|
||
case "com.kunpo.litaibai.android.uc":
|
||
_reward_video_vertical_code = "946608295";
|
||
break;
|
||
}
|
||
#endif
|
||
}
|
||
|
||
this.LoadRewardVideoAd(
|
||
LGBaseAdRequestParams.ORIENTATION_VERTICAL,
|
||
_reward_video_vertical_code,
|
||
IosAdPositionId.REWARD_VIDEO_VERTICAL_CODE);
|
||
}
|
||
|
||
public int ShowRewardAd(string scene)
|
||
{
|
||
if (this.isLoadingAd)
|
||
{
|
||
//ToastManager.Instance.ShowToast("广告正在加载中...");
|
||
return 1;
|
||
}
|
||
|
||
if (_lgAbsRewardVideoAd == null)
|
||
{
|
||
//Log.E("请先加载广告");
|
||
//ToastManager.Instance.ShowToast("请先加载广告");
|
||
return 2;
|
||
}
|
||
if (string.IsNullOrEmpty(scene))
|
||
_lgAbsRewardVideoAd.ShowRewardAd();
|
||
else
|
||
_lgAbsRewardVideoAd.ShowRewardAd(new LGShowAdParams
|
||
{
|
||
RitScenesType = LGRitScenesType.CUSTOMIZE_SCENES,
|
||
CustomRitScenes = scene,
|
||
});
|
||
return 0;
|
||
}
|
||
|
||
private LGAbsRewardVideoAd _lgAbsRewardVideoAd;
|
||
|
||
// 是否正在加载广告
|
||
private bool isLoadingAd;
|
||
|
||
/// <summary>
|
||
/// 加载激励视频广告.
|
||
/// </summary>
|
||
/// <param name="orientation"></param>
|
||
/// <param name="androidAdID"></param>
|
||
/// <param name="iosAdId"></param>
|
||
/// <param name="isExpressAd"></param>
|
||
private void LoadRewardVideoAd(int orientation, string androidAdID, string iosAdId,
|
||
bool isExpressAd = false)
|
||
{
|
||
if (this.isLoadingAd)
|
||
{
|
||
//ToastManager.Instance.ShowToast("广告正在加载中...");
|
||
return;
|
||
}
|
||
|
||
if (this._lgAbsRewardVideoAd != null)
|
||
{
|
||
//Log.E("广告已经加载");
|
||
//ToastManager.Instance.ShowToast("广告已经加载");
|
||
return;
|
||
}
|
||
|
||
this._lgAbsRewardVideoAd = LGSDKAd.MediationAdService.CreateRewardVideoAd();
|
||
|
||
// 加载失败
|
||
this._lgAbsRewardVideoAd.OnLoadError = (code, message) =>
|
||
{
|
||
this.isLoadingAd = false;
|
||
//var lastMsg = "OnRewardVideoAdError-- code : " + code + "--message : " + message;
|
||
//this.PrintD(lastMsg);
|
||
//ToastManager.Instance.ShowToast(lastMsg);
|
||
this.ReleaseAdObject();
|
||
};
|
||
|
||
// 广告加载成功,此时调用广告的show为实时播放广告
|
||
this._lgAbsRewardVideoAd.OnRewardAdLoaded = delegate
|
||
{
|
||
this.isLoadingAd = false;
|
||
//this.PrintD("OnRewardVideoAdLoad");
|
||
//ToastManager.Instance.ShowToast("OnRewardVideoAdLoad");
|
||
|
||
// 注册广告对象的互动监听
|
||
this.RegisterRewardVideoAdInteractionListener();
|
||
};
|
||
|
||
// 广告缓存成功,此时调用广告的show为播放已经下载好的广告
|
||
this._lgAbsRewardVideoAd.OnRewardAdCached = delegate
|
||
{
|
||
this.isLoadingAd = false;
|
||
//this.PrintD("OnRewardVideoAdCached");
|
||
//ToastManager.Instance.ShowToast("OnRewardVideoAdCached");
|
||
};
|
||
|
||
|
||
var rewardVideoAdRequestParams = new LGRewardVideoAdRequestParams();
|
||
|
||
// 双端广告Id
|
||
rewardVideoAdRequestParams.android_AdId = androidAdID;
|
||
rewardVideoAdRequestParams.ios_AdId = iosAdId;
|
||
|
||
// 视频方向
|
||
rewardVideoAdRequestParams.videoPlayOrientation = orientation;
|
||
|
||
// 是否为模板广告
|
||
rewardVideoAdRequestParams.isExpressAd = isExpressAd;
|
||
rewardVideoAdRequestParams.userID = "user123"; // necessary param .用户id,必传参数
|
||
rewardVideoAdRequestParams.rewardName = "金币"; // 奖励的名称
|
||
rewardVideoAdRequestParams.rewardAmount = 5; // 奖励的数量
|
||
rewardVideoAdRequestParams.mediaExtra = "media_extra"; // 附加参数,可选
|
||
|
||
this._lgAbsRewardVideoAd.LoadRewardAd(rewardVideoAdRequestParams);
|
||
this.isLoadingAd = true;
|
||
}
|
||
|
||
// 注册激励视频广告交互监听
|
||
private void RegisterRewardVideoAdInteractionListener()
|
||
{
|
||
if (this._lgAbsRewardVideoAd == null)
|
||
{
|
||
//var lastMsg = "RegisterRewardVideoAdInteractionListener Error : _lgAbsRewardVideoAd is null";
|
||
//this.PrintD(lastMsg);
|
||
//ToastManager.Instance.ShowToast(lastMsg);
|
||
return;
|
||
}
|
||
|
||
this._lgAbsRewardVideoAd.OnAdShow_Interaction = OnRewardedAdShow;
|
||
this._lgAbsRewardVideoAd.OnAdClose_Interaction = OnRewardedAdClosed;
|
||
this._lgAbsRewardVideoAd.OnVideoError_Interaction = OnVideoError;
|
||
this._lgAbsRewardVideoAd.OnRewardAdVerify_Interaction = OnRewardVerify;
|
||
this._lgAbsRewardVideoAd.OnAdClick_Interaction = OnRewardClick;
|
||
#if UNITY_ANDROID
|
||
this._lgAbsRewardVideoAd.Android_OnSkippedVideo_Interaction = Android_OnSkippedVideo;
|
||
this._lgAbsRewardVideoAd.Android_OnVideoComplete_Interaction = Android_OnVideoComplete;
|
||
#endif
|
||
}
|
||
|
||
private void OnRewardedAdShow()
|
||
{
|
||
KPlatform.Instance.OnRewardedAdShow();
|
||
//this.PrintD("onRewardedAdShow");
|
||
//ToastManager.Instance.ShowToast("onRewardedAdShow");
|
||
}
|
||
|
||
private void OnRewardClick()
|
||
{
|
||
//this.PrintD("onRewardClick");
|
||
//ToastManager.Instance.ShowToast("onRewardClick");
|
||
KPlatform.Instance.OnRewardClick();
|
||
}
|
||
|
||
private void OnRewardedAdClosed()
|
||
{
|
||
//this.PrintD("onRewardedAdClosed");
|
||
//ToastManager.Instance.ShowToast("onRewardedAdClosed");
|
||
this.ReleaseAdObject();
|
||
KPlatform.Instance.OnRewardedAdClosed();
|
||
}
|
||
|
||
private void OnVideoError()
|
||
{
|
||
//this.PrintD("onVideoError");
|
||
//ToastManager.Instance.ShowToast("onVideoError");
|
||
KPlatform.Instance.OnVideoError();
|
||
}
|
||
|
||
private void OnRewardVerify(bool rewardVerify, float rewardAmount, string rewardName)
|
||
{
|
||
//var msg = "OnRewardVerify : rewardVerify = " + rewardVerify + "--rewardAmount = " + rewardAmount +
|
||
// "--rewardName = " + rewardName;
|
||
//this.PrintD(msg);
|
||
//ToastManager.Instance.ShowToast(msg);
|
||
KPlatform.Instance.OnRewardVerify(rewardVerify, rewardAmount, rewardName);
|
||
}
|
||
|
||
#if UNITY_ANDROID
|
||
private void Android_OnVideoComplete()
|
||
{
|
||
//this.PrintD("onVideoComplete");
|
||
//ToastManager.Instance.ShowToast("onVideoComplete");
|
||
KPlatform.Instance.OnVideoComplete();
|
||
}
|
||
|
||
private void Android_OnSkippedVideo()
|
||
{
|
||
//this.PrintD("onSkippedVideo");
|
||
//ToastManager.Instance.ShowToast("onSkippedVideo");
|
||
KPlatform.Instance.OnSkippedVideo();
|
||
}
|
||
#endif
|
||
|
||
// 释放广告对象
|
||
public void ReleaseAdObject()
|
||
{
|
||
if (this._lgAbsRewardVideoAd != null)
|
||
{
|
||
this._lgAbsRewardVideoAd.Dispose();
|
||
this._lgAbsRewardVideoAd = null;
|
||
}
|
||
}
|
||
|
||
private void PrintD(string msg)
|
||
{
|
||
//Log.D(AdFunctionScript.LG_MediationAdTAG + msg);
|
||
}
|
||
|
||
private void PrintE(string msg)
|
||
{
|
||
//Log.E(AdFunctionScript.LG_MediationAdTAG + msg);
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 兑换码
|
||
|
||
//输入的兑换码
|
||
public string Input_redeem_code { get; set; }
|
||
|
||
public void Redeem(string redeemCode)
|
||
{
|
||
Input_redeem_code = redeemCode;
|
||
ConfirmRedeemCode();
|
||
//Redeem();
|
||
}
|
||
|
||
// 查询兑换码
|
||
public void InquireRedeemCode()
|
||
{
|
||
string redeemCode = this.Input_redeem_code;
|
||
LGAbsRedemtion.OnInquireSuccess = (json) =>
|
||
{
|
||
var msg = "OnRedemptionInquireSuc-- 兑换码详情json : " + json;
|
||
Debug.Log(msg);
|
||
//ToastManager.Instance.ShowToast(msg);
|
||
|
||
// demo展示这里忽略道具展示页面,直接使用兑换码
|
||
this.ConfirmRedeemCode();
|
||
};
|
||
LGAbsRedemtion.OnInquireFail = KPlatform.Instance.OnRedeemError;
|
||
//(code, message) =>
|
||
//{
|
||
// var msg = "OnRedemptionInquireError-- code : " + code + "--message : " + message;
|
||
// Debug.Log(msg);
|
||
// //ToastManager.Instance.ShowToast(msg);
|
||
//};
|
||
Debug.Log("Redeem 被调用" + "code:" + redeemCode);
|
||
LGSDKAccount.RedemptionService.InquireRedeemCode(redeemCode);
|
||
}
|
||
|
||
/**
|
||
* 使用兑换码
|
||
* demo展示这里忽略道具展示页面,直接使用兑换码
|
||
* cp是展示道具,点击兑换,调用confirm接口,标记兑换码使用了
|
||
* 在成功的回调里面发放兑换码奖励
|
||
*/
|
||
private void ConfirmRedeemCode()
|
||
{
|
||
string redeemCode = this.Input_redeem_code;
|
||
LGAbsRedemtion.OnConfirmRedeemSuccess = KPlatform.Instance.OnRedeemSuccess;
|
||
// (result) =>
|
||
//{
|
||
// var msg = "OnRedemptionConfirmSuc-- result : " + result;
|
||
// Debug.Log(msg);
|
||
// //ToastManager.Instance.ShowToast(msg);
|
||
//};
|
||
LGAbsRedemtion.OnConfirmRedeemFail = KPlatform.Instance.OnRedeemError;
|
||
//(code, message) =>
|
||
//{
|
||
// var msg = "OnRedemptionConfirmError-- code : " + code + "--message : " + message;
|
||
// Debug.Log(msg);
|
||
// //ToastManager.Instance.ShowToast(msg);
|
||
//};
|
||
LGSDKAccount.RedemptionService.ConfirmRedeemCode(redeemCode);
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region AB Test
|
||
|
||
/// <summary>
|
||
/// 获取AB测试的配置
|
||
/// Gets the ab config.
|
||
/// </summary>
|
||
/// <returns>The ab config.</returns>
|
||
/// <param name="key">Key.</param>
|
||
/// <param name="defaultValue">Default value.</param>
|
||
/// <typeparam name="T">The 1st type parameter 类型,需是JSON兼容的数据类型.</typeparam>
|
||
public string GetAbConfig(string key, string defaultValue)
|
||
{
|
||
return LGSDKCore.AppLogService.GetAbConfig(key, defaultValue);
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 邮件
|
||
|
||
/// <summary>
|
||
/// 获取邮件.
|
||
/// </summary>
|
||
public void FetchMail()
|
||
{
|
||
LGAbsMail.OnFetchSuccess = OnMailFetchSuc;
|
||
LGAbsMail.OnFetchFail = OnMailFetchFail;
|
||
LGSDKAccount.MailService.FetchMail();
|
||
}
|
||
|
||
public void OnMailFetchSuc(string mailsJson)
|
||
{
|
||
// 打开邮件页面
|
||
var gp = new GamePacket();
|
||
gp.data = mailsJson;
|
||
gp.id = 100;
|
||
gp.error = 0;
|
||
GlobalNotifier.PostNotification(GlobalDefine.EVENT_NETWORK_PACKET, gp, "sdk");
|
||
}
|
||
|
||
public void OnMailFetchFail(int code, string msg)
|
||
{
|
||
var gp = new GamePacket();
|
||
gp.data = msg;
|
||
gp.id = 100;
|
||
gp.error = code;
|
||
GlobalNotifier.PostNotification(GlobalDefine.EVENT_NETWORK_PACKET, gp, "sdk");
|
||
//ToastManager.Instance.ShowToast("MailFetchCallBack OnFail : code = " + code + "--msg = " + msg);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 确认邮件.
|
||
/// </summary>
|
||
/// <param name="mailIds">需要确认的邮件id.</param>
|
||
public void AckMail(int[] mailIds)
|
||
{
|
||
_mailIds = mailIds;
|
||
LGAbsMail.OnAckSuccess = OnMailAckSuc;
|
||
LGAbsMail.OnAckFail = OnMailAckFail;
|
||
LGSDKAccount.MailService.AckMail(mailIds);
|
||
}
|
||
|
||
int[] _mailIds;
|
||
|
||
void OnMailAckSuc()
|
||
{
|
||
var gp = new GamePacket();
|
||
gp.data = _mailIds;
|
||
gp.id = 101;
|
||
gp.error = 0;
|
||
GlobalNotifier.PostNotification(GlobalDefine.EVENT_NETWORK_PACKET, gp, "sdk");
|
||
}
|
||
|
||
public void OnMailAckFail(int code, string msg)
|
||
{
|
||
var gp = new GamePacket();
|
||
gp.data = msg;
|
||
gp.id = 101;
|
||
gp.error = code;
|
||
GlobalNotifier.PostNotification(GlobalDefine.EVENT_NETWORK_PACKET, gp, "sdk");
|
||
|
||
var resultMsg = "领取邮件失败:code=" + code + ",msg=" + msg;
|
||
Log.E(resultMsg);
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 支付
|
||
#if ENABLE_PAY
|
||
// 输入的总金额
|
||
public string Total_amount { get; set; }
|
||
|
||
private void GoPay()
|
||
{
|
||
LGOrderInfoForPay orderInfo = null;
|
||
#if UNITY_ANDROID
|
||
orderInfo = GetAndroidOrderInfo();
|
||
#endif
|
||
#if UNITY_IOS
|
||
orderInfo = GetiOSOrderInfo();
|
||
#endif
|
||
LGAbsPay.PayResultCallback = PayResultCallback;
|
||
|
||
LGSDKPay.PayService.Pay(LGPayService.Instance.GenerateOrderInfo(orderInfo));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 生成iOS 订单信息
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private LGOrderInfoForPay GetiOSOrderInfo()
|
||
{
|
||
LGOrderInfoForPay orderInfo = new LGOrderInfoForPay();
|
||
// 订单号 必填参数
|
||
string current_time = "";// TimeUtil.GetTimeStamp();
|
||
string order_no = "订单号abc" + current_time;
|
||
Debug.Log("order_no---" + order_no);
|
||
orderInfo.order_no = order_no;
|
||
|
||
// 订单名称 必填参数
|
||
orderInfo.subject = "LightGameSDKDemo";
|
||
|
||
// 注意 这里需要传入SDK接入方自己获取的openID
|
||
//orderInfo.open_id = LiteDataUtil.GetOpenId();
|
||
//ToastManager.Instance.ShowToast("openID ==" + orderInfo.open_id);
|
||
Log.D("Open Id = " + orderInfo.open_id);
|
||
// total_amount 订单金额 必须大于0 必填参数, 单位为分
|
||
string total_amount = "4500";
|
||
orderInfo.total_amount = total_amount;
|
||
Log.D("支付金额大小为---" + total_amount);
|
||
|
||
// notyfy_url 游戏服务端异步回调地址 非空有效的公网地址 必填参数
|
||
string notify_url = "https://tt.test";
|
||
orderInfo.notify_url = notify_url;
|
||
|
||
// product_id 为商品编号非空字段
|
||
string product_id = "com.lightgame.45";
|
||
orderInfo.product_id = product_id;
|
||
|
||
// 订单详情 非必填参数 但是生成签名时候不能丢掉该字段 建议如果为空 传递空串 如下:
|
||
string body = "LightGameSDKDemo";
|
||
orderInfo.body = body;
|
||
|
||
// trade_time 订单创建时间 unix timestamp
|
||
long trade_time;
|
||
long.TryParse(current_time, out trade_time);
|
||
Log.D("trade_time---" + trade_time);
|
||
orderInfo.trade_time = trade_time;
|
||
// 订单有效期,单位为秒 >=0 && <= 3600,小于600时sdk服务端将使用600
|
||
int valid_time = 600;
|
||
orderInfo.valid_time = valid_time;
|
||
// 自定义回调信息 但是生成签名时候不能丢掉该字段 建议如果为空 传递空串 如下:
|
||
string custom_callback_info = "";
|
||
orderInfo.custom_callback_info = custom_callback_info;
|
||
|
||
// 签名类型 目前只支持MD5
|
||
string sign_type = "MD5";
|
||
orderInfo.sign_type = sign_type;
|
||
return orderInfo;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 生成 Android 订单信息
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private LGOrderInfoForPay GetAndroidOrderInfo()
|
||
{
|
||
LGOrderInfoForPay orderInfo = new LGOrderInfoForPay();
|
||
// 订单号 必填参数
|
||
string current_time = "";// TimeUtil.GetTimeStamp();
|
||
string order_no = "订单号abc" + current_time;
|
||
Debug.Log("order_no---" + order_no);
|
||
orderInfo.order_no = order_no;
|
||
|
||
// 订单名称 必填参数
|
||
orderInfo.subject = "测试商品C919";
|
||
|
||
// 注意 这里需要传入SDK接入方自己获取的openID
|
||
//orderInfo.open_id = LiteDataUtil.GetOpenId();
|
||
//ToastManager.Instance.ShowToast("openID ==" + orderInfo.open_id);
|
||
Log.D("Open Id = " + orderInfo.open_id);
|
||
// total_amount 订单金额 必须大于0 必填参数
|
||
Debug.Log("支付金额大小为---" + this.Total_amount);
|
||
string total_amount = this.Total_amount;
|
||
orderInfo.total_amount = total_amount;
|
||
|
||
// notyfy_url 游戏服务端异步回调地址 非空有效的公网地址 必填参数
|
||
string notify_url = "https://tt.test";
|
||
orderInfo.notify_url = notify_url;
|
||
// product_id 为商品编号非空字段
|
||
string product_id = "product_01";
|
||
orderInfo.product_id = product_id;
|
||
// 订单详情 非必填参数 但是生成签名时候不能丢掉该字段 建议如果为空 传递空串 如下:
|
||
string body = "";
|
||
orderInfo.body = body;
|
||
// trade_time 订单创建时间 unix timestamp
|
||
long trade_time;
|
||
long.TryParse(current_time, out trade_time);
|
||
Debug.Log("trade_time---" + trade_time);
|
||
orderInfo.trade_time = trade_time;
|
||
// 订单有效期,单位为秒 >=0 && <= 3600,小于600时sdk服务端将使用600
|
||
int valid_time = 600;
|
||
orderInfo.valid_time = valid_time;
|
||
// 自定义回调信息 但是生成签名时候不能丢掉该字段 建议如果为空 传递空串 如下:
|
||
string custom_callback_info = "";
|
||
orderInfo.custom_callback_info = custom_callback_info;
|
||
|
||
// 签名类型 目前只支持MD5
|
||
string sign_type = "MD5";
|
||
orderInfo.sign_type = sign_type;
|
||
return orderInfo;
|
||
}
|
||
|
||
// 支付回调
|
||
private void PayResultCallback(int code, string msg)
|
||
{
|
||
Debug.Log("example pay onPayResult:" + code + ",errMsg:" + msg);
|
||
//ToastManager.Instance.ShowToast("code = " + code + " || msg =" + msg);
|
||
}
|
||
|
||
// 查询是否支持支付
|
||
private void QueryPaySupport()
|
||
{
|
||
// total_amount 订单金额 必须大于0 必填参数
|
||
Debug.Log("查询支付金额大小为---" + this.Total_amount);
|
||
|
||
|
||
var total_amount = this.Total_amount;
|
||
var total = 0L;
|
||
long.TryParse(total_amount, out total);
|
||
// if (total <= 0)
|
||
// {
|
||
// ToastManager.Instance.ShowToast("订单金额 必须大于0");
|
||
// return;
|
||
// }
|
||
|
||
LGAbsPay.QueryPaySupportCallback = QueryPayCallback;
|
||
LGSDKPay.PayService.QueryPaySupport(total);
|
||
}
|
||
|
||
// 是否支持支付回调
|
||
private void QueryPayCallback(bool canPay, int code, string msg)
|
||
{
|
||
//ToastManager.Instance.ShowToast(canPay
|
||
// ? "canPay 1"
|
||
// : "Pay-code-" + code + "-message-" + msg);
|
||
//Debug.Log("example query queryResult:" + code + ",errMsg:" + msg + ", canPay:" + canPay);
|
||
}
|
||
#endif
|
||
|
||
#endregion
|
||
|
||
#region 其它
|
||
|
||
/// <summary>
|
||
/// 应用内引导评分
|
||
/// </summary>
|
||
public void InAppRating()
|
||
{
|
||
#if UNITY_IOS
|
||
LGSDKDevKit.DevKitBaseService.iOS_InAppRating();
|
||
#endif
|
||
}
|
||
|
||
/// <summary>
|
||
/// 验证敏感词.
|
||
/// </summary>
|
||
/// <param name="sensitiveWords">输入的敏感词信息.</param>
|
||
/// <param name="verifyResult">返回的敏感词结果.</param>
|
||
public void VerifySensitiveWords(string sensitiveWords, System.Action<int> verifyResult)
|
||
{
|
||
LGSDKDevKit.DevKitBaseService.VerifySensitiveWords(sensitiveWords, (result) =>
|
||
{
|
||
verifyResult?.Invoke(result == SensitiveWordsEnum.REJIECT ? 1 : 0);
|
||
});
|
||
}
|
||
|
||
/// <summary>
|
||
/// 播放品牌特效.
|
||
/// </summary>
|
||
/// <param name="portrait">游戏是否竖屏,竖屏游戏填true,横屏游戏填false.</param>
|
||
/// <param name="splashBrandEffectListener">品牌特效完成回调.</param>
|
||
public void PlaySplashBrandEffect(bool portrait, System.Action splashBrandEffectAction)
|
||
{
|
||
//LightGameSDK.PlaySplashBrandEffect(portrait, splashBrandEffectAction);
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="key"></param>
|
||
/// <param name="value"></param>
|
||
public void SetEventCommonHeader(string key, string value)
|
||
{
|
||
LGSDKCore.AppLogService.SetCommonHeader(key, value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 上报v3事件。
|
||
/// Ons the event v3.
|
||
/// </summary>
|
||
/// <param name="label">Label. 事件名,应用内需唯一 .</param>
|
||
/// <param name="paramJson">Parameter. 事件参数 json .</param>
|
||
public void ReportEvent(string label, string paramJson)
|
||
{
|
||
LGSDKCore.AppLogService.OnEventV3(label, paramJson);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取 IDFA 权限
|
||
/// </summary>
|
||
public static void RequireIDFA()
|
||
{
|
||
bool flag = false;
|
||
var osText = SystemInfo.operatingSystem;
|
||
for (int i = 0; i < osText.Length; i++)
|
||
{
|
||
if (char.IsDigit(osText[i]))
|
||
{
|
||
var osVersionText = osText.Substring(i);
|
||
if (System.Version.TryParse(osVersionText, out var osVersion))
|
||
{
|
||
if (osVersion < new System.Version(14, 5))
|
||
{
|
||
flag = true;
|
||
}
|
||
Debug.Log(osVersionText);
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
|
||
/// 获取 IDFA 权限
|
||
if (!flag)
|
||
{
|
||
#if UNITY_IOS
|
||
LGSDKAd.MediationAdService.iOS_RequireIDFA(delegate (bool hasAuthorized, string idfaString)
|
||
{
|
||
//var msg = $"是否有权限 : {hasAuthorized} \n idfaString : {idfaString}";
|
||
//ToastManager.Instance.ShowToast(msg);
|
||
});
|
||
#endif
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// openwebview
|
||
/// </summary>
|
||
/// <param name="url"></param>
|
||
public void OpenWebView(string url)
|
||
{
|
||
#if UNITY_ANDROID
|
||
LGSDKDevKit.DevKitBaseService.Android_RegisterDeepLinkInnerCallBack(delegate (string message)
|
||
{
|
||
//var tips = "收到H5消息" + message;
|
||
//Log.D(tips);
|
||
//ToastManager.Instance.ShowToast(tips);
|
||
});
|
||
|
||
LGSDKDevKit.DevKitBaseService.Android_StartBrowser(url);
|
||
#else
|
||
Application.OpenURL(url);
|
||
#endif
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public void OpenUserProtocol()
|
||
{
|
||
LGSDKDevKit.DevKitBaseService.OpenUserProtocol();
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public void OpenPrivacyProtocol()
|
||
{
|
||
LGSDKDevKit.DevKitBaseService.OpenPrivacyProtocol();
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public void OpenIdentifyProtocol()
|
||
{
|
||
LGSDKDevKit.DevKitBaseService.OpenIdentifyProtocol();
|
||
}
|
||
|
||
public string appId { get; }
|
||
|
||
#endregion
|
||
}
|
||
}
|
||
}
|
||
#endif
|
||
|