com.taptap.sdk.login 4.8.4-beta.1 → 4.8.4-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Mobile/Editor/NativeDependencies.xml +3 -3
- package/Mobile/Editor/TapLoginIOSProcessor.cs +107 -49
- package/Mobile/Editor/TapLoginMobileProcessBuild.cs +20 -20
- package/Runtime/Public/TapTapLogin.cs +1 -1
- package/Standalone/Editor/TapLoginStandaloneProcessBuild.cs +21 -21
- package/Standalone/Runtime/Internal2/Http/Response/ProfileResponse.cs +23 -23
- package/Standalone/Runtime/Internal2/Http/Response/QRCodeResponse.cs +16 -16
- package/Standalone/Runtime/Internal2/Http/Response/TokenResponse.cs +28 -28
- package/Standalone/Runtime/Internal2/LoginService.cs +192 -192
- package/Standalone/Runtime/Internal2/QRCodeUtils.cs +50 -50
- package/Standalone/Runtime/Internal2/UI/ClientButtonListener.cs +20 -20
- package/Standalone/Runtime/Internal2/UI/LoginPanelController.cs +71 -71
- package/Standalone/Runtime/Internal2/UI/QRCodeController.cs +180 -180
- package/Standalone/Runtime/Internal2/UI/TitleController.cs +20 -20
- package/Standalone/Runtime/Internal2/UI/WebController.cs +128 -128
- package/package.json +9 -9
|
@@ -1,192 +1,192 @@
|
|
|
1
|
-
using System;
|
|
2
|
-
using System.Collections.Generic;
|
|
3
|
-
using System.Threading.Tasks;
|
|
4
|
-
using System.Security.Cryptography;
|
|
5
|
-
using System.Text;
|
|
6
|
-
using UnityEngine;
|
|
7
|
-
using TapSDK.Login.Internal.Http;
|
|
8
|
-
using TapSDK.Core.Standalone.Internal.Http;
|
|
9
|
-
using TapSDK.Login.Standalone.Internal.Http;
|
|
10
|
-
|
|
11
|
-
namespace TapSDK.Login.Internal
|
|
12
|
-
{
|
|
13
|
-
public static class LoginService
|
|
14
|
-
{
|
|
15
|
-
private static readonly TapHttp tapHttp = TapHttp
|
|
16
|
-
.NewBuilder("TapLogin", TapTapLogin.Version)
|
|
17
|
-
.Sign(new TapLoginSign())
|
|
18
|
-
.Build();
|
|
19
|
-
|
|
20
|
-
public static async Task<QRCodeData> GetQRCodeUrl(string clientId, string[] scopes)
|
|
21
|
-
{
|
|
22
|
-
Dictionary<string, string> data = new Dictionary<string, string> {
|
|
23
|
-
{ "client_id", clientId },
|
|
24
|
-
{ "response_type", "device_code" },
|
|
25
|
-
{ "scope", string.Join(",", scopes) },
|
|
26
|
-
{ "version", TapTapLogin.Version },
|
|
27
|
-
{ "platform", "unity" },
|
|
28
|
-
{ "info", "{\"device_id\":\"" + SystemInfo.deviceModel + "\"}" }
|
|
29
|
-
};
|
|
30
|
-
TapHttpResult<QRCodeData> result = await tapHttp.PostFormAsync<QRCodeData>(TapTapSdk.CurrentRegion.CodeUrl(), form: data);
|
|
31
|
-
if (result.IsSuccess)
|
|
32
|
-
{
|
|
33
|
-
return result.Data;
|
|
34
|
-
}
|
|
35
|
-
else
|
|
36
|
-
{
|
|
37
|
-
throw result.HttpException;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public static async Task<TokenData> Authorize(string clientId, string code)
|
|
42
|
-
{
|
|
43
|
-
Dictionary<string, string> data = new Dictionary<string, string> {
|
|
44
|
-
{ "client_id", clientId },
|
|
45
|
-
{ "grant_type", "authorization_code" },
|
|
46
|
-
{ "secret_type", "hmac-sha-1" },
|
|
47
|
-
{ "code", code },
|
|
48
|
-
{ "redirect_uri", WebLoginRequestManager.Instance.GetCurrentRequest().GetRedirectUri() },
|
|
49
|
-
{ "code_verifier", WebLoginRequestManager.Instance.GetCodeVerifier() }
|
|
50
|
-
};
|
|
51
|
-
TapHttpResult<TokenData> result = await tapHttp.PostFormAsync<TokenData>(TapTapSdk.CurrentRegion.TokenUrl(), form: data);
|
|
52
|
-
if (result.IsSuccess)
|
|
53
|
-
{
|
|
54
|
-
return result.Data;
|
|
55
|
-
}
|
|
56
|
-
else
|
|
57
|
-
{
|
|
58
|
-
throw result.HttpException;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
public static async Task<TokenData> Authorize(string clientId, string code, string codeVerify) {
|
|
63
|
-
Dictionary<string, string> data = new Dictionary<string, string> {
|
|
64
|
-
{ "client_id", clientId },
|
|
65
|
-
{ "grant_type", "authorization_code" },
|
|
66
|
-
{ "secret_type", "hmac-sha-1" },
|
|
67
|
-
{ "code", code },
|
|
68
|
-
{ "redirect_uri", "tapoauth://authorize" },
|
|
69
|
-
{ "code_verifier", codeVerify }
|
|
70
|
-
};
|
|
71
|
-
TapHttpResult<TokenData> result = await tapHttp.PostFormAsync<TokenData>(TapTapSdk.CurrentRegion.TokenUrl(), form: data);
|
|
72
|
-
if (result.IsSuccess)
|
|
73
|
-
{
|
|
74
|
-
return result.Data;
|
|
75
|
-
}
|
|
76
|
-
else
|
|
77
|
-
{
|
|
78
|
-
throw result.HttpException;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
public static async Task<TokenData> RequestScanQRCodeResult(string clientId, string deviceCode)
|
|
83
|
-
{
|
|
84
|
-
Dictionary<string, string> data = new Dictionary<string, string> {
|
|
85
|
-
{ "grant_type", "device_token" },
|
|
86
|
-
{ "client_id", clientId },
|
|
87
|
-
{ "secret_type", "hmac-sha-1" },
|
|
88
|
-
{ "code", deviceCode },
|
|
89
|
-
{ "version", "1.0" },
|
|
90
|
-
{ "platform", "unity" },
|
|
91
|
-
{ "info", "{\"device_id\":\"" + SystemInfo.deviceModel + "\"}" }
|
|
92
|
-
};
|
|
93
|
-
TapHttpResult<TokenData> result = await tapHttp.PostFormAsync<TokenData>(TapTapSdk.CurrentRegion.TokenUrl(), form: data);
|
|
94
|
-
if (result.IsSuccess)
|
|
95
|
-
{
|
|
96
|
-
return result.Data;
|
|
97
|
-
}
|
|
98
|
-
else
|
|
99
|
-
{
|
|
100
|
-
throw result.HttpException;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
public static async Task<ProfileData> GetProfile(string clientId, AccessToken token, int timestamp = 0)
|
|
105
|
-
{
|
|
106
|
-
string url = TapTapSdk.CurrentRegion.ProfileUrl(token.scopeSet.Contains(TapTapLogin.TAP_LOGIN_SCOPE_PUBLIC_PROFILE)) + clientId;
|
|
107
|
-
var uri = new Uri(url);
|
|
108
|
-
var ts = timestamp;
|
|
109
|
-
if (ts == 0)
|
|
110
|
-
{
|
|
111
|
-
var dt = DateTime.UtcNow - new DateTime(1970, 1, 1);
|
|
112
|
-
ts = (int)dt.TotalSeconds;
|
|
113
|
-
}
|
|
114
|
-
var sign = "MAC " + GetAuthorizationHeader(token.kid,
|
|
115
|
-
token.macKey,
|
|
116
|
-
token.macAlgorithm,
|
|
117
|
-
"GET",
|
|
118
|
-
uri.PathAndQuery,
|
|
119
|
-
uri.Host,
|
|
120
|
-
"443", ts);
|
|
121
|
-
Dictionary<string, string> headers = new Dictionary<string, string> {
|
|
122
|
-
{ "Authorization", sign }
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
TapHttpResult<ProfileData> result = await tapHttp.GetAsync<ProfileData>(url, headers: headers);
|
|
126
|
-
if(result.IsSuccess)
|
|
127
|
-
{
|
|
128
|
-
return result.Data;
|
|
129
|
-
}
|
|
130
|
-
else
|
|
131
|
-
{
|
|
132
|
-
throw result.HttpException;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
public static string GetAuthorizationHeader(string kid,
|
|
137
|
-
string macKey,
|
|
138
|
-
string macAlgorithm,
|
|
139
|
-
string method,
|
|
140
|
-
string uri,
|
|
141
|
-
string host,
|
|
142
|
-
string port,
|
|
143
|
-
int timestamp)
|
|
144
|
-
{
|
|
145
|
-
var nonce = new System.Random().Next().ToString();
|
|
146
|
-
|
|
147
|
-
var normalizedString = $"{timestamp}\n{nonce}\n{method}\n{uri}\n{host}\n{port}\n\n";
|
|
148
|
-
|
|
149
|
-
HashAlgorithm hashGenerator;
|
|
150
|
-
switch (macAlgorithm)
|
|
151
|
-
{
|
|
152
|
-
case "hmac-sha-256":
|
|
153
|
-
hashGenerator = new HMACSHA256(Encoding.ASCII.GetBytes(macKey));
|
|
154
|
-
break;
|
|
155
|
-
case "hmac-sha-1":
|
|
156
|
-
hashGenerator = new HMACSHA1(Encoding.ASCII.GetBytes(macKey));
|
|
157
|
-
break;
|
|
158
|
-
default:
|
|
159
|
-
throw new InvalidOperationException("Unsupported MAC algorithm");
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
var hash = Convert.ToBase64String(hashGenerator.ComputeHash(Encoding.ASCII.GetBytes(normalizedString)));
|
|
163
|
-
|
|
164
|
-
var authorizationHeader = new StringBuilder();
|
|
165
|
-
authorizationHeader.AppendFormat(@"id=""{0}"",ts=""{1}"",nonce=""{2}"",mac=""{3}""",
|
|
166
|
-
kid, timestamp, nonce, hash);
|
|
167
|
-
|
|
168
|
-
return authorizationHeader.ToString();
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
public static async Task<TokenData> RefreshToken(string clientId, string accessToken)
|
|
172
|
-
{
|
|
173
|
-
Dictionary<string, string> data = new Dictionary<string, string> {
|
|
174
|
-
{ "client_id", clientId },
|
|
175
|
-
{ "grant_type", "refresh_token" },
|
|
176
|
-
{ "token", accessToken },
|
|
177
|
-
{ "token_type_hint", "access_token" },
|
|
178
|
-
{ "platform", "unity" },
|
|
179
|
-
{ "info", "{\"device_id\":\"" + SystemInfo.deviceModel + "\"}" }
|
|
180
|
-
};
|
|
181
|
-
TapHttpResult<TokenData> result = await tapHttp.PostFormAsync<TokenData>(TapTapSdk.CurrentRegion.TokenUrl(), form: data);
|
|
182
|
-
if(result.IsSuccess)
|
|
183
|
-
{
|
|
184
|
-
return result.Data;
|
|
185
|
-
}
|
|
186
|
-
else
|
|
187
|
-
{
|
|
188
|
-
throw result.HttpException;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
using System.Threading.Tasks;
|
|
4
|
+
using System.Security.Cryptography;
|
|
5
|
+
using System.Text;
|
|
6
|
+
using UnityEngine;
|
|
7
|
+
using TapSDK.Login.Internal.Http;
|
|
8
|
+
using TapSDK.Core.Standalone.Internal.Http;
|
|
9
|
+
using TapSDK.Login.Standalone.Internal.Http;
|
|
10
|
+
|
|
11
|
+
namespace TapSDK.Login.Internal
|
|
12
|
+
{
|
|
13
|
+
public static class LoginService
|
|
14
|
+
{
|
|
15
|
+
private static readonly TapHttp tapHttp = TapHttp
|
|
16
|
+
.NewBuilder("TapLogin", TapTapLogin.Version)
|
|
17
|
+
.Sign(new TapLoginSign())
|
|
18
|
+
.Build();
|
|
19
|
+
|
|
20
|
+
public static async Task<QRCodeData> GetQRCodeUrl(string clientId, string[] scopes)
|
|
21
|
+
{
|
|
22
|
+
Dictionary<string, string> data = new Dictionary<string, string> {
|
|
23
|
+
{ "client_id", clientId },
|
|
24
|
+
{ "response_type", "device_code" },
|
|
25
|
+
{ "scope", string.Join(",", scopes) },
|
|
26
|
+
{ "version", TapTapLogin.Version },
|
|
27
|
+
{ "platform", "unity" },
|
|
28
|
+
{ "info", "{\"device_id\":\"" + SystemInfo.deviceModel + "\"}" }
|
|
29
|
+
};
|
|
30
|
+
TapHttpResult<QRCodeData> result = await tapHttp.PostFormAsync<QRCodeData>(TapTapSdk.CurrentRegion.CodeUrl(), form: data);
|
|
31
|
+
if (result.IsSuccess)
|
|
32
|
+
{
|
|
33
|
+
return result.Data;
|
|
34
|
+
}
|
|
35
|
+
else
|
|
36
|
+
{
|
|
37
|
+
throw result.HttpException;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public static async Task<TokenData> Authorize(string clientId, string code)
|
|
42
|
+
{
|
|
43
|
+
Dictionary<string, string> data = new Dictionary<string, string> {
|
|
44
|
+
{ "client_id", clientId },
|
|
45
|
+
{ "grant_type", "authorization_code" },
|
|
46
|
+
{ "secret_type", "hmac-sha-1" },
|
|
47
|
+
{ "code", code },
|
|
48
|
+
{ "redirect_uri", WebLoginRequestManager.Instance.GetCurrentRequest().GetRedirectUri() },
|
|
49
|
+
{ "code_verifier", WebLoginRequestManager.Instance.GetCodeVerifier() }
|
|
50
|
+
};
|
|
51
|
+
TapHttpResult<TokenData> result = await tapHttp.PostFormAsync<TokenData>(TapTapSdk.CurrentRegion.TokenUrl(), form: data);
|
|
52
|
+
if (result.IsSuccess)
|
|
53
|
+
{
|
|
54
|
+
return result.Data;
|
|
55
|
+
}
|
|
56
|
+
else
|
|
57
|
+
{
|
|
58
|
+
throw result.HttpException;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public static async Task<TokenData> Authorize(string clientId, string code, string codeVerify) {
|
|
63
|
+
Dictionary<string, string> data = new Dictionary<string, string> {
|
|
64
|
+
{ "client_id", clientId },
|
|
65
|
+
{ "grant_type", "authorization_code" },
|
|
66
|
+
{ "secret_type", "hmac-sha-1" },
|
|
67
|
+
{ "code", code },
|
|
68
|
+
{ "redirect_uri", "tapoauth://authorize" },
|
|
69
|
+
{ "code_verifier", codeVerify }
|
|
70
|
+
};
|
|
71
|
+
TapHttpResult<TokenData> result = await tapHttp.PostFormAsync<TokenData>(TapTapSdk.CurrentRegion.TokenUrl(), form: data);
|
|
72
|
+
if (result.IsSuccess)
|
|
73
|
+
{
|
|
74
|
+
return result.Data;
|
|
75
|
+
}
|
|
76
|
+
else
|
|
77
|
+
{
|
|
78
|
+
throw result.HttpException;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public static async Task<TokenData> RequestScanQRCodeResult(string clientId, string deviceCode)
|
|
83
|
+
{
|
|
84
|
+
Dictionary<string, string> data = new Dictionary<string, string> {
|
|
85
|
+
{ "grant_type", "device_token" },
|
|
86
|
+
{ "client_id", clientId },
|
|
87
|
+
{ "secret_type", "hmac-sha-1" },
|
|
88
|
+
{ "code", deviceCode },
|
|
89
|
+
{ "version", "1.0" },
|
|
90
|
+
{ "platform", "unity" },
|
|
91
|
+
{ "info", "{\"device_id\":\"" + SystemInfo.deviceModel + "\"}" }
|
|
92
|
+
};
|
|
93
|
+
TapHttpResult<TokenData> result = await tapHttp.PostFormAsync<TokenData>(TapTapSdk.CurrentRegion.TokenUrl(), form: data);
|
|
94
|
+
if (result.IsSuccess)
|
|
95
|
+
{
|
|
96
|
+
return result.Data;
|
|
97
|
+
}
|
|
98
|
+
else
|
|
99
|
+
{
|
|
100
|
+
throw result.HttpException;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public static async Task<ProfileData> GetProfile(string clientId, AccessToken token, int timestamp = 0)
|
|
105
|
+
{
|
|
106
|
+
string url = TapTapSdk.CurrentRegion.ProfileUrl(token.scopeSet.Contains(TapTapLogin.TAP_LOGIN_SCOPE_PUBLIC_PROFILE)) + clientId;
|
|
107
|
+
var uri = new Uri(url);
|
|
108
|
+
var ts = timestamp;
|
|
109
|
+
if (ts == 0)
|
|
110
|
+
{
|
|
111
|
+
var dt = DateTime.UtcNow - new DateTime(1970, 1, 1);
|
|
112
|
+
ts = (int)dt.TotalSeconds;
|
|
113
|
+
}
|
|
114
|
+
var sign = "MAC " + GetAuthorizationHeader(token.kid,
|
|
115
|
+
token.macKey,
|
|
116
|
+
token.macAlgorithm,
|
|
117
|
+
"GET",
|
|
118
|
+
uri.PathAndQuery,
|
|
119
|
+
uri.Host,
|
|
120
|
+
"443", ts);
|
|
121
|
+
Dictionary<string, string> headers = new Dictionary<string, string> {
|
|
122
|
+
{ "Authorization", sign }
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
TapHttpResult<ProfileData> result = await tapHttp.GetAsync<ProfileData>(url, headers: headers);
|
|
126
|
+
if(result.IsSuccess)
|
|
127
|
+
{
|
|
128
|
+
return result.Data;
|
|
129
|
+
}
|
|
130
|
+
else
|
|
131
|
+
{
|
|
132
|
+
throw result.HttpException;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
public static string GetAuthorizationHeader(string kid,
|
|
137
|
+
string macKey,
|
|
138
|
+
string macAlgorithm,
|
|
139
|
+
string method,
|
|
140
|
+
string uri,
|
|
141
|
+
string host,
|
|
142
|
+
string port,
|
|
143
|
+
int timestamp)
|
|
144
|
+
{
|
|
145
|
+
var nonce = new System.Random().Next().ToString();
|
|
146
|
+
|
|
147
|
+
var normalizedString = $"{timestamp}\n{nonce}\n{method}\n{uri}\n{host}\n{port}\n\n";
|
|
148
|
+
|
|
149
|
+
HashAlgorithm hashGenerator;
|
|
150
|
+
switch (macAlgorithm)
|
|
151
|
+
{
|
|
152
|
+
case "hmac-sha-256":
|
|
153
|
+
hashGenerator = new HMACSHA256(Encoding.ASCII.GetBytes(macKey));
|
|
154
|
+
break;
|
|
155
|
+
case "hmac-sha-1":
|
|
156
|
+
hashGenerator = new HMACSHA1(Encoding.ASCII.GetBytes(macKey));
|
|
157
|
+
break;
|
|
158
|
+
default:
|
|
159
|
+
throw new InvalidOperationException("Unsupported MAC algorithm");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
var hash = Convert.ToBase64String(hashGenerator.ComputeHash(Encoding.ASCII.GetBytes(normalizedString)));
|
|
163
|
+
|
|
164
|
+
var authorizationHeader = new StringBuilder();
|
|
165
|
+
authorizationHeader.AppendFormat(@"id=""{0}"",ts=""{1}"",nonce=""{2}"",mac=""{3}""",
|
|
166
|
+
kid, timestamp, nonce, hash);
|
|
167
|
+
|
|
168
|
+
return authorizationHeader.ToString();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
public static async Task<TokenData> RefreshToken(string clientId, string accessToken)
|
|
172
|
+
{
|
|
173
|
+
Dictionary<string, string> data = new Dictionary<string, string> {
|
|
174
|
+
{ "client_id", clientId },
|
|
175
|
+
{ "grant_type", "refresh_token" },
|
|
176
|
+
{ "token", accessToken },
|
|
177
|
+
{ "token_type_hint", "access_token" },
|
|
178
|
+
{ "platform", "unity" },
|
|
179
|
+
{ "info", "{\"device_id\":\"" + SystemInfo.deviceModel + "\"}" }
|
|
180
|
+
};
|
|
181
|
+
TapHttpResult<TokenData> result = await tapHttp.PostFormAsync<TokenData>(TapTapSdk.CurrentRegion.TokenUrl(), form: data);
|
|
182
|
+
if(result.IsSuccess)
|
|
183
|
+
{
|
|
184
|
+
return result.Data;
|
|
185
|
+
}
|
|
186
|
+
else
|
|
187
|
+
{
|
|
188
|
+
throw result.HttpException;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
using System.Collections.Generic;
|
|
2
|
-
using ZXing;
|
|
3
|
-
using ZXing.Common;
|
|
4
|
-
using ZXing.QrCode.Internal;
|
|
5
|
-
using UnityEngine;
|
|
6
|
-
|
|
7
|
-
namespace TapSDK.Login.Internal {
|
|
8
|
-
public class QRCodeUtils {
|
|
9
|
-
public static Texture2D EncodeQrImage(string content, int width, int height) {
|
|
10
|
-
var writer = new MultiFormatWriter();
|
|
11
|
-
var hints = new Dictionary<EncodeHintType, object> {
|
|
12
|
-
{ EncodeHintType.CHARACTER_SET, "UTF-8" },
|
|
13
|
-
//hints.Add(EncodeHintType.MARGIN, 0);
|
|
14
|
-
{ EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M }
|
|
15
|
-
};
|
|
16
|
-
var bitMatrix = writer.encode(content, BarcodeFormat.QR_CODE, width, height, hints);
|
|
17
|
-
bitMatrix = DeleteWhite(bitMatrix);
|
|
18
|
-
var w = bitMatrix.Width;
|
|
19
|
-
var h = bitMatrix.Height;
|
|
20
|
-
var texture = new Texture2D(w, h);
|
|
21
|
-
for (var x = 0; x < h; x++) {
|
|
22
|
-
for (var y = 0; y < w; y++) {
|
|
23
|
-
texture.SetPixel(y, x, bitMatrix[x, y] ? Color.black : Color.white);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
texture.Apply();
|
|
28
|
-
texture.filterMode = FilterMode.Point;
|
|
29
|
-
return texture;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
private static BitMatrix DeleteWhite(BitMatrix matrix) {
|
|
33
|
-
var rec = matrix.getEnclosingRectangle();
|
|
34
|
-
var resWidth = rec[2];
|
|
35
|
-
var resHeight = rec[3];
|
|
36
|
-
|
|
37
|
-
var resMatrix = new BitMatrix(resWidth, resHeight);
|
|
38
|
-
resMatrix.clear();
|
|
39
|
-
for (var i = 0; i < resWidth; i++) {
|
|
40
|
-
for (var j = 0; j < resHeight; j++){
|
|
41
|
-
if (matrix[i + rec[0], j + rec[1]]) {
|
|
42
|
-
resMatrix.flip(i, j);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return resMatrix;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
1
|
+
using System.Collections.Generic;
|
|
2
|
+
using ZXing;
|
|
3
|
+
using ZXing.Common;
|
|
4
|
+
using ZXing.QrCode.Internal;
|
|
5
|
+
using UnityEngine;
|
|
6
|
+
|
|
7
|
+
namespace TapSDK.Login.Internal {
|
|
8
|
+
public class QRCodeUtils {
|
|
9
|
+
public static Texture2D EncodeQrImage(string content, int width, int height) {
|
|
10
|
+
var writer = new MultiFormatWriter();
|
|
11
|
+
var hints = new Dictionary<EncodeHintType, object> {
|
|
12
|
+
{ EncodeHintType.CHARACTER_SET, "UTF-8" },
|
|
13
|
+
//hints.Add(EncodeHintType.MARGIN, 0);
|
|
14
|
+
{ EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M }
|
|
15
|
+
};
|
|
16
|
+
var bitMatrix = writer.encode(content, BarcodeFormat.QR_CODE, width, height, hints);
|
|
17
|
+
bitMatrix = DeleteWhite(bitMatrix);
|
|
18
|
+
var w = bitMatrix.Width;
|
|
19
|
+
var h = bitMatrix.Height;
|
|
20
|
+
var texture = new Texture2D(w, h);
|
|
21
|
+
for (var x = 0; x < h; x++) {
|
|
22
|
+
for (var y = 0; y < w; y++) {
|
|
23
|
+
texture.SetPixel(y, x, bitMatrix[x, y] ? Color.black : Color.white);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
texture.Apply();
|
|
28
|
+
texture.filterMode = FilterMode.Point;
|
|
29
|
+
return texture;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private static BitMatrix DeleteWhite(BitMatrix matrix) {
|
|
33
|
+
var rec = matrix.getEnclosingRectangle();
|
|
34
|
+
var resWidth = rec[2];
|
|
35
|
+
var resHeight = rec[3];
|
|
36
|
+
|
|
37
|
+
var resMatrix = new BitMatrix(resWidth, resHeight);
|
|
38
|
+
resMatrix.clear();
|
|
39
|
+
for (var i = 0; i < resWidth; i++) {
|
|
40
|
+
for (var j = 0; j < resHeight; j++){
|
|
41
|
+
if (matrix[i + rec[0], j + rec[1]]) {
|
|
42
|
+
resMatrix.flip(i, j);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return resMatrix;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
using System;
|
|
2
|
-
using System.Collections;
|
|
3
|
-
using System.Collections.Generic;
|
|
4
|
-
using UnityEngine;
|
|
5
|
-
using UnityEngine.EventSystems;
|
|
6
|
-
|
|
7
|
-
namespace TapSDK.Login.Internal {
|
|
8
|
-
public class ClientButtonListener : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler {
|
|
9
|
-
public Action OnMouseEnter { get; set; }
|
|
10
|
-
public Action OnMouseExit { get; set; }
|
|
11
|
-
|
|
12
|
-
public void OnPointerEnter(PointerEventData eventData) {
|
|
13
|
-
OnMouseEnter?.Invoke();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public void OnPointerExit(PointerEventData eventData) {
|
|
17
|
-
OnMouseExit?.Invoke();
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections;
|
|
3
|
+
using System.Collections.Generic;
|
|
4
|
+
using UnityEngine;
|
|
5
|
+
using UnityEngine.EventSystems;
|
|
6
|
+
|
|
7
|
+
namespace TapSDK.Login.Internal {
|
|
8
|
+
public class ClientButtonListener : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler {
|
|
9
|
+
public Action OnMouseEnter { get; set; }
|
|
10
|
+
public Action OnMouseExit { get; set; }
|
|
11
|
+
|
|
12
|
+
public void OnPointerEnter(PointerEventData eventData) {
|
|
13
|
+
OnMouseEnter?.Invoke();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public void OnPointerExit(PointerEventData eventData) {
|
|
17
|
+
OnMouseExit?.Invoke();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|