-
Notifications
You must be signed in to change notification settings - Fork 439
/
SystemButton.cs
177 lines (156 loc) · 4.56 KB
/
SystemButton.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using WeChatWASM;
public class SystemButton : MonoBehaviour
{
private WXFeedbackButton FeedbackButton;
private WXGameClubButton GameClubButton;
private WeChatWASM.SystemInfo SystemInfo;
void Start()
{
WX.InitSDK((code) =>
{
SystemInfo = WX.GetSystemInfoSync();
CreateGameClubButton();
CreateFeedbackButton();
var result = WX.GetLaunchOptionsSync();
Debug.Log(JsonUtility.ToJson(result));
WX.GetSetting(new GetSettingOption()
{
withSubscriptions = true,
success = (res) =>
{
Dictionary<string, string> itemSettings = res.subscriptionsSetting.itemSettings;
// 是否已授权过SYS_MSG_TYPE_INTERACTIVE,授权过不在乎展示按钮
if (itemSettings.ContainsKey("SYS_MSG_TYPE_INTERACTIVE") && itemSettings["SYS_MSG_TYPE_INTERACTIVE"] == "accept")
{
GameObject requestSubscribeButton = GameObject.Find("RequestSubscribeSystemMessage");
if (requestSubscribeButton != null)
{
requestSubscribeButton.SetActive(false);
}
}
},
fail = (res) =>
{
Debug.Log("GetSetting fail" + JsonUtility.ToJson(res));
}
});
});
}
private void CreateGameClubButton()
{
var screenWidth = (int)SystemInfo.screenWidth;
GameClubButton = WX.CreateGameClubButton(new WXCreateGameClubButtonParam()
{
type = GameClubButtonType.image,
text = "游戏圈",
icon = GameClubButtonIcon.white,
style = new GameClubButtonStyle()
{
left = screenWidth - 40 - 10,
top = 200,
width = 40,
height = 40,
}
});
}
public void GameClubButtonShow()
{
GameClubButton.Show();
}
public void GameClubButtonHide()
{
GameClubButton.Hide();
}
private void GameClubButtonDestroy()
{
GameClubButton.Destroy();
}
public void OpenCustomerServiceConversation()
{
WX.OpenCustomerServiceConversation(new OpenCustomerServiceConversationOption
{
sessionFrom = "sessionFrom_test",
showMessageCard = true,
sendMessageTitle = "客服咨询",
});
}
private void CreateFeedbackButton()
{
FeedbackButton = WX.CreateFeedbackButton(new CreateOpenSettingButtonOption()
{
type = "text",
text = "打开意见反馈页面",
style = new OptionStyle()
{
left = 10,
top = 200,
width = 200,
height = 40,
lineHeight = 40,
backgroundColor = "#ff0000",
color = "#ffffff",
textAlign = "center",
fontSize = 16,
borderRadius = 4,
}
});
}
public void FeedbackButtonShow()
{
FeedbackButton.Show();
}
public void FeedbackButtonHide()
{
FeedbackButton.Hide();
}
public void FeedbackButtonOnTap()
{
FeedbackButton.OnTap((res) =>
{
Debug.Log("FeedbackButton.OnTap");
});
}
public void FeedbackButtonOffTap()
{
FeedbackButton.OffTap();
}
public void FeedbackButtonChangeText()
{
FeedbackButton.text = "跳转到意见反馈页面";
}
private void FeedbackButtonDestroy()
{
FeedbackButton.Destroy();
}
public void RequestSubscribeSystemMessage()
{
WX.RequestSubscribeSystemMessage(new RequestSubscribeSystemMessageOption()
{
msgTypeList = new string[] { "SYS_MSG_TYPE_INTERACTIVE" },
success = (res) => {
Debug.Log(res);
}
});
}
public void OpenCustomerServiceChat()
{
WX.OpenCustomerServiceChat(new OpenCustomerServiceChatOption()
{
extInfo = new ExtInfoOption()
{
url = "https://www.qq.com/"
},
corpId = "123",
});
}
private void OnDestroy()
{
GameClubButtonDestroy();
FeedbackButtonDestroy();
}
}