Skip to content

Commit 82c79c8

Browse files
committed
转发-demo
1 parent 85c9413 commit 82c79c8

File tree

12 files changed

+1269
-29
lines changed

12 files changed

+1269
-29
lines changed

Demo/API_V2/Assets/API/Share/ShareEvent.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using LitJson;
4+
using UnityEngine;
5+
using WeChatWASM;
6+
7+
public class ShareEvent : Details
8+
{
9+
10+
private bool _isListeningShareTimeline = false;
11+
12+
private readonly Action<Action<OnShareTimelineListenerResult>> _onShareTimelineCallback = (callback) => {
13+
callback(new OnShareTimelineListenerResult
14+
{
15+
imageUrl = "xxx",
16+
imagePreviewUrl = "yy",
17+
imagePreviewUrlId = "xx",
18+
imageUrlId = "xxx",
19+
path = "xx",
20+
query = "xx",
21+
title = "test",
22+
});
23+
};
24+
25+
private readonly Action<OnShareMessageToFriendListenerResult> _onShareMessageToFriend = (res) => {
26+
var result = "onShareMessageToFriend\n" + JsonMapper.ToJson(res);
27+
GameManager.Instance.detailsController.AddResult(new ResultData()
28+
{
29+
initialContentText = result
30+
});
31+
};
32+
33+
private readonly Action<Action<WXShareAppMessageParam>> _onShareAppMessageCallback = (callback) => {
34+
callback(new WXShareAppMessageParam
35+
{
36+
title = "转发标题",
37+
imageUrl = "xx",
38+
query = "key1=val1&key2=val2"
39+
});
40+
};
41+
42+
43+
private void Start()
44+
{
45+
GameManager.Instance.detailsController.BindExtraButtonAction(0, showShareMenu);
46+
GameManager.Instance.detailsController.BindExtraButtonAction(1, hideShareMenu);
47+
GameManager.Instance.detailsController.BindExtraButtonAction(2, showShareImageMenu);
48+
GameManager.Instance.detailsController.BindExtraButtonAction(3, setMessageToFriendQuery);
49+
GameManager.Instance.detailsController.BindExtraButtonAction(4, setHandoffQuery);
50+
GameManager.Instance.detailsController.BindExtraButtonAction(5, onShareTimeline);
51+
GameManager.Instance.detailsController.BindExtraButtonAction(6, onShareMessageToFriend);
52+
GameManager.Instance.detailsController.BindExtraButtonAction(7, onShareAppMessage);
53+
}
54+
55+
// 测试 API
56+
protected override void TestAPI(string[] args)
57+
{
58+
updateShareMenu();
59+
}
60+
61+
public void updateShareMenu() {
62+
var parameter = new UpdatableMessageFrontEndParameter[] {
63+
new UpdatableMessageFrontEndParameter {
64+
name = "xxx",
65+
value = "yyy"
66+
},
67+
new UpdatableMessageFrontEndParameter {
68+
name = "zz",
69+
value = "kk"
70+
}
71+
};
72+
73+
var info = new UpdatableMessageFrontEndTemplateInfo{
74+
parameterList = parameter
75+
};
76+
77+
WX.UpdateShareMenu(new UpdateShareMenuOption
78+
{
79+
isPrivateMessage = true,
80+
activityId = "xxx",
81+
templateInfo = info,
82+
success = (res) => {
83+
WX.ShowToast(new ShowToastOption
84+
{
85+
title = "设置成功"
86+
});
87+
},
88+
fail = (res) => {
89+
Debug.Log("fail" + res.errMsg);
90+
},
91+
complete = (res) => {
92+
Debug.Log("complete");
93+
}
94+
});
95+
}
96+
97+
public void showShareMenu() {
98+
WX.ShowShareMenu(new ShowShareMenuOption
99+
{
100+
withShareTicket = true,
101+
menus = new string[] {"shareAppMessage", "shareTimeline"},
102+
success = (res) => {
103+
Debug.Log("success");
104+
},
105+
fail = (res) => {
106+
Debug.Log("fail" + res.errMsg);
107+
},
108+
complete = (res) => {
109+
Debug.Log("complete");
110+
}
111+
});
112+
}
113+
114+
public void hideShareMenu() {
115+
WX.HideShareMenu(new HideShareMenuOption
116+
{
117+
menus = new string[] {"shareAppMessage", "shareTimeline"},
118+
success = (res) => {
119+
Debug.Log("success");
120+
},
121+
fail = (res) => {
122+
Debug.Log("fail" + res.errMsg);
123+
},
124+
complete = (res) => {
125+
Debug.Log("complete");
126+
}
127+
});
128+
}
129+
130+
public void showShareImageMenu() {
131+
WX.DownloadFile(new DownloadFileOption
132+
{
133+
url = "xxxxx",
134+
success = (res) => {
135+
WX.ShowShareImageMenu(new ShowShareImageMenuOption
136+
{
137+
path = res.tempFilePath,
138+
style = "default",
139+
success = (res) => {
140+
Debug.Log("success");
141+
},
142+
fail = (res) => {
143+
Debug.Log("fail" + res.errMsg);
144+
},
145+
complete = (res) => {
146+
Debug.Log("complete");
147+
}
148+
});
149+
}
150+
});
151+
}
152+
153+
public void setMessageToFriendQuery() {
154+
var isSuccess = WX.SetMessageToFriendQuery(new SetMessageToFriendQueryOption
155+
{
156+
shareMessageToFriendScene = 1,
157+
query = "abcd"
158+
});
159+
WX.ShowToast(new ShowToastOption
160+
{
161+
title = isSuccess ? "true" : "false"
162+
});
163+
}
164+
165+
public void setHandoffQuery() {
166+
var isSuccess = WX.SetHandoffQuery("xxx");
167+
WX.ShowToast(new ShowToastOption
168+
{
169+
title = isSuccess ? "true" : "false"
170+
});
171+
}
172+
173+
public void onShareTimeline() {
174+
if (!_isListeningShareTimeline) {
175+
WX.OnShareTimeline(_onShareTimelineCallback);
176+
} else {
177+
WX.OffShareTimeline(_onShareTimelineCallback);
178+
}
179+
_isListeningShareTimeline = !_isListeningShareTimeline;
180+
GameManager.Instance.detailsController.ChangeExtraButtonText(5, _isListeningShareTimeline ? "取消监听分享到朋友圈" : "开始监听分享到朋友圈");
181+
}
182+
183+
public void onShareMessageToFriend() {
184+
WX.OnShareMessageToFriend(_onShareMessageToFriend);
185+
}
186+
187+
public void onShareAppMessage() {
188+
var defaultParam = new WXShareAppMessageParam
189+
{
190+
title = "转发标题",
191+
imageUrl = "xx",
192+
query = "key1=val1&key2=val2"
193+
};
194+
WX.OnShareAppMessage(defaultParam, _onShareAppMessageCallback);
195+
}
196+
}
197+

Demo/API_V2/Assets/API/Share/ShareEvent/ShareEvent.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: fb48e4613a53bb941a20036d7c08fefb, type: 3}
13+
m_Name: ShareEventSO
14+
m_EditorClassIdentifier:
15+
entryScriptTypeName: ShareEvent
16+
entryName: "\u8F6C\u53D11"
17+
entryAPI: "\u8F6C\u53D1\u76F8\u5173api"
18+
entryDescription:
19+
optionList: []
20+
initialButtonText: "\u66F4\u65B0\u8F6C\u53D1\u5C5E\u6027"
21+
extraButtonList:
22+
- buttonText: "\u663E\u793A\u5F53\u524D\u9875\u9762\u7684\u8F6C\u53D1\u6309\u94AE"
23+
- buttonText: "\u9690\u85CF\u5F53\u524D\u9875\u9762\u7684\u8F6C\u53D1\u6309\u94AE"
24+
- buttonText: "\u6253\u5F00\u5206\u4EAB\u56FE\u7247\u5F39\u7A97"
25+
- buttonText: "\u8BBE\u7F6Esharetofriend\u5B57\u6BB5"
26+
- buttonText: "\u8BBE\u7F6E\u63A5\u529B\u53C2\u6570"
27+
- buttonText: "\u5F00\u59CB\u76D1\u542C\u5206\u4EAB\u5230\u670B\u53CB\u5708"
28+
- buttonText: "\u76D1\u542Csharetofriend"
29+
- buttonText: "\u76D1\u542C\u53F3\u4E0A\u89D2\u83DC\u5355\u7684\u8F6C\u53D1"
30+
initialResultList: []

Demo/API_V2/Assets/API/Share/ShareEvent/ShareEventSO.asset.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/API_V2/Assets/API/Share/ShareEvent2.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using LitJson;
4+
using UnityEngine;
5+
using WeChatWASM;
6+
7+
public class ShareEvent2 : Details
8+
{
9+
10+
private bool _isListeningHandoff = false;
11+
private bool _isListeningCopyUrl = false;
12+
private bool _isListeningAddToFavorites = false;
13+
14+
private readonly Action<Action<OnHandoffListenerResult>> _onHandoff = (callback) => {
15+
callback(new OnHandoffListenerResult
16+
{
17+
query = "xxxx"
18+
});
19+
};
20+
21+
private readonly Action<Action<OnCopyUrlListenerResult>> _onCopyUrl = (callback) => {
22+
callback(new OnCopyUrlListenerResult
23+
{
24+
query = "xx"
25+
});
26+
};
27+
28+
private readonly Action<Action<OnAddToFavoritesListenerResult>> _onAddToFavorites = (callback) => {
29+
callback(new OnAddToFavoritesListenerResult
30+
{
31+
title = "收藏标题",
32+
imageUrl = "xx",
33+
query = "key1=val1&key2=val2",
34+
disableForward = false
35+
});
36+
};
37+
38+
private void Start()
39+
{
40+
GameManager.Instance.detailsController.BindExtraButtonAction(0, onCopyUrl);
41+
GameManager.Instance.detailsController.BindExtraButtonAction(1, onAddToFavorites);
42+
GameManager.Instance.detailsController.BindExtraButtonAction(2, getShareInfo);
43+
GameManager.Instance.detailsController.BindExtraButtonAction(3, authPrivateMessage);
44+
}
45+
46+
// 测试 API
47+
protected override void TestAPI(string[] args)
48+
{
49+
onHandoff();
50+
}
51+
52+
public void onHandoff() {
53+
if (!_isListeningHandoff) {
54+
WX.OnHandoff(_onHandoff);
55+
} else {
56+
WX.OffHandoff(_onHandoff);
57+
}
58+
_isListeningHandoff = !_isListeningHandoff;
59+
GameManager.Instance.detailsController.ChangeInitialButtonText(_isListeningHandoff ? "取消监听在电脑上打开" : "开始监听在电脑上打开");
60+
}
61+
62+
public void onCopyUrl() {
63+
if (!_isListeningCopyUrl) {
64+
WX.OnCopyUrl(_onCopyUrl);
65+
} else {
66+
WX.OffCopyUrl(_onCopyUrl);
67+
}
68+
_isListeningCopyUrl = !_isListeningCopyUrl;
69+
GameManager.Instance.detailsController.ChangeExtraButtonText(0, _isListeningCopyUrl ? "取消监听复制链接" : "开始监听复制链接");
70+
}
71+
72+
public void onAddToFavorites() {
73+
if (!_isListeningAddToFavorites) {
74+
WX.OnAddToFavorites(_onAddToFavorites);
75+
} else {
76+
WX.OffAddToFavorites(_onAddToFavorites);
77+
}
78+
_isListeningAddToFavorites = !_isListeningAddToFavorites;
79+
GameManager.Instance.detailsController.ChangeExtraButtonText(1, _isListeningAddToFavorites ? "取消监听收藏" : "开始监听收藏");
80+
}
81+
82+
public void getShareInfo() {
83+
WX.GetShareInfo(new GetShareInfoOption
84+
{
85+
shareTicket = "xxx",
86+
timeout = 2000,
87+
success = (res) => {
88+
Debug.Log("success");
89+
},
90+
fail = (res) => {
91+
Debug.Log("fail" + res.errMsg);
92+
},
93+
complete = (res) => {
94+
Debug.Log("complete");
95+
}
96+
});
97+
}
98+
99+
public void authPrivateMessage() {
100+
WX.AuthPrivateMessage(new AuthPrivateMessageOption
101+
{
102+
shareTicket = "xxxxxx",
103+
success = (res) => {
104+
Debug.Log("authPrivateMessage success" + JsonMapper.ToJson(res));
105+
// res
106+
// {
107+
// errMsg: 'authPrivateMessage:ok'
108+
// valid: true
109+
// iv: 'xxxx',
110+
// encryptedData: 'xxxxxx'
111+
// }
112+
},
113+
fail = (res) => {
114+
Debug.Log("authPrivateMessage fail" + res.errMsg);
115+
}
116+
});
117+
}
118+
}
119+

Demo/API_V2/Assets/API/Share/ShareEvent2/ShareEvent2.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)