Skip to content

整理onShareAppMessage示例 #949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
30 changes: 15 additions & 15 deletions Demo/API_V2/Assets/API/APISO.asset
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ MonoBehaviour:
m_Name: APISO
m_EditorClassIdentifier:
categoryList:
- {fileID: 11400000, guid: 587fe4b03da9d44779ac921ffdb216a7, type: 2}
- {fileID: 11400000, guid: 82450cc74b3b4439da53b9f0f2298454, type: 2}
- {fileID: 11400000, guid: 24d9eba5a9b3048b59cf7e5495bb999d, type: 2}
- {fileID: 11400000, guid: 9977a581037b84833a32b508e00eb1a2, type: 2}
- {fileID: 11400000, guid: 56f316e0e10ba419bbf19bd7a68bfc4c, type: 2}
- {fileID: 11400000, guid: 6f0972f5fdc56c543b23c9873d760bf5, type: 2}
- {fileID: 11400000, guid: a461b8cd70d9e4e23ad1cc953bec31e9, type: 2}
- {fileID: 11400000, guid: 7ef06699cee7846b7823e4cc421418eb, type: 2}
- {fileID: 11400000, guid: 55de20d536f8c4689bbd80553d87fe46, type: 2}
- {fileID: 11400000, guid: f2c56d751bb7c4c398db7c1db352517d, type: 2}
- {fileID: 11400000, guid: b4a6196f623dd4435a4f3bd70af92d06, type: 2}
- {fileID: 11400000, guid: 96c20c2f2bb504877a24cb359162c323, type: 2}
- {fileID: 11400000, guid: a461b8cd70d9e4e23ad1cc953bec31e9, type: 2}
- {fileID: 11400000, guid: 6f6fdc677ed96437eb1fa0e7e272b6d8, type: 2}
- {fileID: 11400000, guid: 8c2a99491f3c0446097220cd580dfe38, type: 2}
- {fileID: 11400000, guid: 59792dcce94fc48f6ab5654a02c78c6d, type: 2}
- {fileID: 11400000, guid: b34629c67a7664a428561dd0b3621995, type: 2}
- {fileID: 11400000, guid: b363337bfb49b490e81fbfac3612f793, type: 2}
- {fileID: 11400000, guid: 9977a581037b84833a32b508e00eb1a2, type: 2}
- {fileID: 11400000, guid: 2bf0b496956fe4d89af32d301c33d9a6, type: 2}
- {fileID: 11400000, guid: 96c20c2f2bb504877a24cb359162c323, type: 2}
- {fileID: 11400000, guid: b363337bfb49b490e81fbfac3612f793, type: 2}
- {fileID: 11400000, guid: f2c56d751bb7c4c398db7c1db352517d, type: 2}
- {fileID: 11400000, guid: 55de20d536f8c4689bbd80553d87fe46, type: 2}
- {fileID: 11400000, guid: 6f0972f5fdc56c543b23c9873d760bf5, type: 2}
- {fileID: 11400000, guid: 8c2a99491f3c0446097220cd580dfe38, type: 2}
- {fileID: 11400000, guid: 56f316e0e10ba419bbf19bd7a68bfc4c, type: 2}
- {fileID: 11400000, guid: 7ef06699cee7846b7823e4cc421418eb, type: 2}
- {fileID: 11400000, guid: 587fe4b03da9d44779ac921ffdb216a7, type: 2}
- {fileID: 11400000, guid: 24d9eba5a9b3048b59cf7e5495bb999d, type: 2}
- {fileID: 11400000, guid: b34629c67a7664a428561dd0b3621995, type: 2}
nativeAbilityList:
- {fileID: 11400000, guid: 3ccd91abf96ad407d92ada7e93eda0a4, type: 2}
- {fileID: 11400000, guid: aad449a913b0c444fb827d7f3eafad70, type: 2}
- {fileID: 11400000, guid: a999a30c61ceb450ca9ec0652c439b69, type: 2}
- {fileID: 11400000, guid: 90da3e9d88868495d85959bf329b7dfd, type: 2}
- {fileID: 11400000, guid: a999a30c61ceb450ca9ec0652c439b69, type: 2}
- {fileID: 11400000, guid: 879518ab20abe40c7b42d213d2b57bdd, type: 2}
- {fileID: 11400000, guid: 3ccd91abf96ad407d92ada7e93eda0a4, type: 2}
6 changes: 3 additions & 3 deletions Demo/API_V2/Assets/API/Base/BaseSO.asset
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ MonoBehaviour:
categoryName: "\u57FA\u7840"
categorySprite: {fileID: 21300000, guid: a43db3a4b5b124728be9ff9ac754f5de, type: 3}
entryList:
- {fileID: 11400000, guid: d21307f6da1da4d7bb1322558c508822, type: 2}
- {fileID: 11400000, guid: 3996b93c3d76d47088845abcebf960fb, type: 2}
- {fileID: 11400000, guid: fc015bc2bdd084428ab1dc7cf5b87fba, type: 2}
- {fileID: 11400000, guid: e535490610e214b1cabe9378cb46ea5a, type: 2}
- {fileID: 11400000, guid: 29b8eb105fe9d400f9a79bdb140e85c9, type: 2}
- {fileID: 11400000, guid: 3996b93c3d76d47088845abcebf960fb, type: 2}
- {fileID: 11400000, guid: d21307f6da1da4d7bb1322558c508822, type: 2}
- {fileID: 11400000, guid: 9d4267fc1b8274349a253ca28e0340d7, type: 2}
- {fileID: 11400000, guid: e6944788ab3d04858bc3c6cf1f2f7273, type: 2}
- {fileID: 11400000, guid: e535490610e214b1cabe9378cb46ea5a, type: 2}
categoryOrder: 0
4 changes: 2 additions & 2 deletions Demo/API_V2/Assets/API/Facility/FacilitySO.asset
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ MonoBehaviour:
categoryName: "\u8BBE\u5907"
categorySprite: {fileID: 21300000, guid: 53dd2b1922e5142ec8a53037f362fc56, type: 3}
entryList:
- {fileID: 11400000, guid: bbbc9b983d6d34ad3bac2921509f612f, type: 2}
- {fileID: 11400000, guid: c17ae0ce755f04419b700825b20fd386, type: 2}
- {fileID: 11400000, guid: a24af43ae51914d26b0bf637c283dab2, type: 2}
- {fileID: 11400000, guid: 4eba2c9f2f2064e4081be74302ca4c33, type: 2}
- {fileID: 11400000, guid: bbbc9b983d6d34ad3bac2921509f612f, type: 2}
- {fileID: 11400000, guid: c17ae0ce755f04419b700825b20fd386, type: 2}
- {fileID: 11400000, guid: ac09abff5d8bc48bbabd08bde820b58b, type: 2}
- {fileID: 11400000, guid: 3bf339b994c544db3860ddf0a0dc8e20, type: 2}
- {fileID: 11400000, guid: e92d94924be504167a342e42e1162f21, type: 2}
Expand Down
2 changes: 1 addition & 1 deletion Demo/API_V2/Assets/API/FileSystem/FileSystemSO.asset
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ MonoBehaviour:
- {fileID: 11400000, guid: 65ab1b01a722b4542a14fcf9decca3de, type: 2}
- {fileID: 11400000, guid: 19b80cb144f0c4ea28a4ddca7a2c2f09, type: 2}
- {fileID: 11400000, guid: 0aa5d76237c844275add1612c47bddaa, type: 2}
- {fileID: 11400000, guid: 73c05fc1ffae94ec1b69a00ee261d529, type: 2}
- {fileID: 11400000, guid: 65a826f5f949544d8990e673231bb80f, type: 2}
- {fileID: 11400000, guid: 73c05fc1ffae94ec1b69a00ee261d529, type: 2}
- {fileID: 11400000, guid: 3a901e80b59ad4aafbe373ee6a8df2d8, type: 2}
- {fileID: 11400000, guid: e7ea0be62dc6543b0a8dc629489c5e7e, type: 2}
categoryOrder: 11
1 change: 1 addition & 0 deletions Demo/API_V2/Assets/API/GUI/Menu/MenuSO.asset
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ MonoBehaviour:
- buttonText: "\u83B7\u53D6\u83DC\u5355\u6309\u94AE\u5E03\u5C40\u4F4D\u7F6E\u4FE1\u606F"
- buttonText: "\u8BBE\u7F6E\u72B6\u6001\u680F\u6DF1\u8272"
initialResultList: []
entryOrder: 0
1 change: 1 addition & 0 deletions Demo/API_V2/Assets/API/Media/CameraAPI/CameraAPISO.asset
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ MonoBehaviour:
initialButtonText: "\u5F00\u59CB\u76D1\u542C\u5E27\u6570\u636E"
extraButtonList: []
initialResultList: []
entryOrder: 0
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ MonoBehaviour:
- buttonText: "\u8DF3\u8F6C"
- buttonText: "\u83B7\u5F97\u4E0B\u4E00\u5E27"
initialResultList: []
entryOrder: 0
2 changes: 1 addition & 1 deletion Demo/API_V2/Assets/API/NativeVideo/NativeVideoSO.asset
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ MonoBehaviour:
categoryName: "\u89C6\u9891"
categorySprite: {fileID: 0}
entryList:
- {fileID: 11400000, guid: 5073e277b29d95642abb3c49fe94eea0, type: 2}
- {fileID: 11400000, guid: 27654a238f98e4f7e8756e4caed418e1, type: 2}
- {fileID: 11400000, guid: 5073e277b29d95642abb3c49fe94eea0, type: 2}
- {fileID: 11400000, guid: ebd496025e81f434bb6b5b487cfbf2ed, type: 2}
categoryOrder: 0
1 change: 1 addition & 0 deletions Demo/API_V2/Assets/API/Network/Download/DownloadSO.asset
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ MonoBehaviour:
initialButtonText: "\u4E0B\u8F7D"
extraButtonList: []
initialResultList: []
entryOrder: 0
1 change: 1 addition & 0 deletions Demo/API_V2/Assets/API/Network/TCPSocket/TCPSocketSO.asset
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ MonoBehaviour:
- buttonText: "\u53D1\u9001"
- buttonText: "\u5173\u95ED"
initialResultList: []
entryOrder: 0
1 change: 1 addition & 0 deletions Demo/API_V2/Assets/API/Network/UDPSocket/UDPSocketSO.asset
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ MonoBehaviour:
- buttonText: Send
- buttonText: "\u5173\u95ED"
initialResultList: []
entryOrder: 0
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ MonoBehaviour:
- buttonText: Post
- buttonText: Get
initialResultList: []
entryOrder: 0
1 change: 1 addition & 0 deletions Demo/API_V2/Assets/API/Network/Upload/UploadSO.asset
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ MonoBehaviour:
initialButtonText: "\u4E0A\u4F20\u6587\u4EF6"
extraButtonList: []
initialResultList: []
entryOrder: 0

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

153 changes: 153 additions & 0 deletions Demo/API_V2/Assets/API/Share/Favorites/Favorites.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
using WeChatWASM;
using System;
using UnityEngine;

public class Favorites : Details
{
private bool _isListeningAddToFavorites = false;
private Action<Action<OnAddToFavoritesListenerResult>> _onAddToFavorites;
private string localImagePath;

protected override void TestAPI(string[] args)
{
// 如果已经在监听中,只执行切换监听的操作,避免重复下载
if (_isListeningAddToFavorites)
{
onAddToFavorites();
return;
}

// 根据对应参数,执行DownloadFileImage()下载图片
if (GetOptionString(1, "") == "本地图片文件路径")
{
DownloadFileImage();
}
else
{
InitializeFavoritesCallback();
onAddToFavorites();
}
}

private void ShowLoading()
{
WX.ShowLoading(new ShowLoadingOption()
{
title = "正在下载图片...",
mask = true
});
}

private void HideLoading()
{
WX.HideLoading(new HideLoadingOption());
}

private void DownloadFileImage()
{
ShowLoading();
WX.DownloadFile(new DownloadFileOption()
{
url = "https://picsum.photos/400/400?random=1",
success = (res) =>
{
Debug.Log("WX.DownloadFile success");
if (res.statusCode == 200)
{
Debug.Log(res.tempFilePath);
var fs = WX.GetFileSystemManager();
// 将临时文件保存为本地缓存文件
localImagePath = fs.SaveFileSync(res.tempFilePath, WX.env.USER_DATA_PATH + "/favoriteImage.jpg");
Debug.Log($"本地缓存文件保存路径: {localImagePath}");
InitializeFavoritesCallback();
onAddToFavorites();
}
},
fail = (res) =>
{
Debug.Log("WX.DownloadFile fail");
},
complete = (res) =>
{
Debug.Log("WX.DownloadFile complete");
HideLoading();
}
});
}

//设置收藏回调函数
private void InitializeFavoritesCallback()
{
string title = GetOptionString(0, "");
string imageUrl = GetOptionString(1, "");
bool disableForward = !GetOptionBool(2, false);

if (imageUrl == "本地图片文件路径")
{
imageUrl = localImagePath;
}

_onAddToFavorites = (callback) =>
{
callback(
new OnAddToFavoritesListenerResult
{
title = title,
imageUrl = imageUrl,
disableForward = disableForward
}
);
Debug.Log($"收藏回调参数 - 标题: {title}, 图片URL: {imageUrl}, 禁止转发: {disableForward}");
};
}

//切换收藏监听状态
public void onAddToFavorites()
{
if (!_isListeningAddToFavorites)
{
WX.OnAddToFavorites(_onAddToFavorites);
Debug.Log("开始监听收藏");
// 添加开始监听时的提示
WX.ShowToast(new ShowToastOption()
{
title = "已开启收藏监听",
icon = "none",
duration = 1500
});
}
else
{
WX.OffAddToFavorites(_onAddToFavorites);
Debug.Log("取消监听收藏");
// 添加取消监听时的提示
WX.ShowToast(new ShowToastOption()
{
title = "已取消收藏监听",
icon = "none",
duration = 1500
});
}
_isListeningAddToFavorites = !_isListeningAddToFavorites;
GameManager.Instance.detailsController.ChangeInitialButtonText(
_isListeningAddToFavorites ? "取消监听收藏" : "开始监听收藏"
);
}

private void OnDestroy()
{
if (_isListeningAddToFavorites)
{
WX.OffAddToFavorites(_onAddToFavorites);
Debug.Log("清理收藏监听");
}

// 清理本地文件
if (!string.IsNullOrEmpty(localImagePath))
{
var fs = WX.GetFileSystemManager();
fs.UnlinkSync(localImagePath);
Debug.Log("清理本地图片成功");
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions Demo/API_V2/Assets/API/Share/Favorites/FavoritesSO.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 57c8415214254e23a63d9bfb8c6bbf62, type: 3}
m_Name: FavoritesSO
m_EditorClassIdentifier:
entryName: "\u6536\u85CF\u76D1\u542C"
entryOrder: 0
entryScriptTypeName: Favorites
entryAPI: wx.onAddToFavorites | wx.offAddToFavorites
entryDescription: "\u76D1\u542C\u7528\u6237\u70B9\u51FB\u83DC\u5355\u300C\u6536\u85CF\u300D\u6309\u94AE\u65F6\u89E6\u53D1\u7684\u4E8B\u4EF6\n\uFF08\u5B89\u53537.0.15\u8D77\u652F\u6301\uFF0CiOS
\u6682\u4E0D\u652F\u6301\uFF09\n\u6CE8\u610F\uFF1A\u7A7A\u9009\u9879\u5219\u4F7F\u7528\u9ED8\u8BA4\u503C"
optionList:
- optionName: title
availableOptions:
- "\u6536\u85CF\u6807\u9898"
-
- optionName: imageUrl
availableOptions:
- https://mmocgame.qpic.cn/wechatgame/QgsibLsZPBy1uwWJnNNPeRXjBMKm327We8xrXWxGMM4cFKUZaqy0SU8TcudBf72sE/0
- "\u672C\u5730\u56FE\u7247\u6587\u4EF6\u8DEF\u5F84"
-
- optionName: disableForward
availableOptions:
- false
- true
initialButtonText: "\u5F00\u59CB\u76D1\u542C\u6536\u85CF"
extraButtonList: []
initialResultList: []

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Demo/API_V2/Assets/API/Share/ShareAppMessage.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading