chicken_dy/Assets/HCMiniSdk/Scripts/WebGL/HCWX/HCWXShare.cs

61 lines
1.9 KiB
C#
Raw Permalink Normal View History

2024-03-07 12:12:48 +00:00
#if UNITY_WEBGL && WEBGL_WX
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using WeChatWASM;
namespace HC
{
public class HCWXShare : HCIShare
{
public HCWXShare()
{
HCAnalyticsManager.Instance.RemoteConfigListen += RemoteConfigUpdate;
OnListenShare();
}
private static void OnListenShare()
{
var shareImageUrl = HCAnalyticsManager.Instance.GetRemoteConfigStr("share_imageUrl", "");
var shareTitle = HCAnalyticsManager.Instance.GetRemoteConfigStr("share_title", "");
HCDebugger.LogDebug($"[HCWXShare] [OnListenShare] start");
WX.OnShareTimeline(action =>
{
HCDebugger.LogDebug($"[HCWXShare] [OnListenShare] action = {action}");
HCDebugger.LogDebug($"[HCWXShare] [OnListenShare] action = {action} shareImageUrl = {shareImageUrl} shareTitle = {shareTitle}");
action.Invoke(new OnShareTimelineListenerResult
{
imageUrl = shareImageUrl,
title = shareTitle
});
});
WXBase.OnShareAppMessage(new WXShareAppMessageParam
{
imageUrl = shareImageUrl,
title = shareTitle
});
}
public void Share(string title, string imgUrl, string content, Action<bool> callback, int type = 0)
{
var shareAppMessageOption = new ShareAppMessageOption
{
title = title
};
if (!string.IsNullOrEmpty(imgUrl))
{
shareAppMessageOption.imageUrl = imgUrl;
}
WX.ShareAppMessage(shareAppMessageOption);
callback?.Invoke(true);
}
private static void RemoteConfigUpdate(TrackEventPlatform platform, Dictionary<string, object> config)
{
OnListenShare();
}
}
}
#endif